"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lodash.js" between
lodash-3.0.0.tar.gz and lodash-4.0.0.tar.gz

About: lodash is a modern JavaScript utility library delivering modularity, performance, & extras.

lodash.js  (lodash-3.0.0):lodash.js  (lodash-4.0.0)
/** /**
* @license * @license
* lodash 3.0.0 (Custom Build) <https://lodash.com/> * lodash 4.0.0 (Custom Build) <https://lodash.com/>
* Build: `lodash modern -o ./lodash.js` * Build: `lodash -d -o ./lodash.js`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE> * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporter * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporter
s & Editors s & Editors
* Available under MIT license <https://lodash.com/license> * Available under MIT license <https://lodash.com/license>
*/ */
;(function() { ;(function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */ /** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined; var undefined;
/** Used as the semantic version number. */ /** Used as the semantic version number. */
var VERSION = '3.0.0'; var VERSION = '4.0.0';
/** Used to compose bitmasks for wrapper metadata. */ /** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1, var BIND_FLAG = 1,
BIND_KEY_FLAG = 2, BIND_KEY_FLAG = 2,
CURRY_BOUND_FLAG = 4, CURRY_BOUND_FLAG = 4,
CURRY_FLAG = 8, CURRY_FLAG = 8,
CURRY_RIGHT_FLAG = 16, CURRY_RIGHT_FLAG = 16,
PARTIAL_FLAG = 32, PARTIAL_FLAG = 32,
PARTIAL_RIGHT_FLAG = 64, PARTIAL_RIGHT_FLAG = 64,
REARG_FLAG = 128, ARY_FLAG = 128,
ARY_FLAG = 256; REARG_FLAG = 256,
FLIP_FLAG = 512;
/** Used to compose bitmasks for comparison styles. */
var UNORDERED_COMPARE_FLAG = 1,
PARTIAL_COMPARE_FLAG = 2;
/** Used as default options for `_.trunc`. */ /** Used as default options for `_.truncate`. */
var DEFAULT_TRUNC_LENGTH = 30, var DEFAULT_TRUNC_LENGTH = 30,
DEFAULT_TRUNC_OMISSION = '...'; DEFAULT_TRUNC_OMISSION = '...';
/** Used to detect when a function becomes hot. */ /** Used to detect hot functions by number of calls within a span of milliseco nds. */
var HOT_COUNT = 150, var HOT_COUNT = 150,
HOT_SPAN = 16; HOT_SPAN = 16;
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;
/** Used to indicate the type of lazy iteratees. */ /** Used to indicate the type of lazy iteratees. */
var LAZY_FILTER_FLAG = 0, var LAZY_FILTER_FLAG = 1,
LAZY_MAP_FLAG = 1, LAZY_MAP_FLAG = 2,
LAZY_WHILE_FLAG = 2; LAZY_WHILE_FLAG = 3;
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function'; var FUNC_ERROR_TEXT = 'Expected a function';
/** Used to stand-in for `undefined` hash values. */
var HASH_UNDEFINED = '__lodash_hash_undefined__';
/** Used as references for various `Number` constants. */
var INFINITY = 1 / 0,
MAX_SAFE_INTEGER = 9007199254740991,
MAX_INTEGER = 1.7976931348623157e+308,
NAN = 0 / 0;
/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = 4294967295,
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
/** Used as the internal argument placeholder. */ /** Used as the internal argument placeholder. */
var PLACEHOLDER = '__lodash_placeholder__'; var PLACEHOLDER = '__lodash_placeholder__';
/** `Object#toString` result references. */ /** `Object#toString` result references. */
var argsTag = '[object Arguments]', var argsTag = '[object Arguments]',
arrayTag = '[object Array]', arrayTag = '[object Array]',
boolTag = '[object Boolean]', boolTag = '[object Boolean]',
dateTag = '[object Date]', dateTag = '[object Date]',
errorTag = '[object Error]', errorTag = '[object Error]',
funcTag = '[object Function]', funcTag = '[object Function]',
genTag = '[object GeneratorFunction]',
mapTag = '[object Map]', mapTag = '[object Map]',
numberTag = '[object Number]', numberTag = '[object Number]',
objectTag = '[object Object]', objectTag = '[object Object]',
regexpTag = '[object RegExp]', regexpTag = '[object RegExp]',
setTag = '[object Set]', setTag = '[object Set]',
stringTag = '[object String]', stringTag = '[object String]',
symbolTag = '[object Symbol]',
weakMapTag = '[object WeakMap]'; weakMapTag = '[object WeakMap]';
var arrayBufferTag = '[object ArrayBuffer]', var arrayBufferTag = '[object ArrayBuffer]',
float32Tag = '[object Float32Array]', float32Tag = '[object Float32Array]',
float64Tag = '[object Float64Array]', float64Tag = '[object Float64Array]',
int8Tag = '[object Int8Array]', int8Tag = '[object Int8Array]',
int16Tag = '[object Int16Array]', int16Tag = '[object Int16Array]',
int32Tag = '[object Int32Array]', int32Tag = '[object Int32Array]',
uint8Tag = '[object Uint8Array]', uint8Tag = '[object Uint8Array]',
uint8ClampedTag = '[object Uint8ClampedArray]', uint8ClampedTag = '[object Uint8ClampedArray]',
skipping to change at line 90 skipping to change at line 114
var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g, var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
reUnescapedHtml = /[&<>"'`]/g, reUnescapedHtml = /[&<>"'`]/g,
reHasEscapedHtml = RegExp(reEscapedHtml.source), reHasEscapedHtml = RegExp(reEscapedHtml.source),
reHasUnescapedHtml = RegExp(reUnescapedHtml.source); reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
/** Used to match template delimiters. */ /** Used to match template delimiters. */
var reEscape = /<%-([\s\S]+?)%>/g, var reEscape = /<%-([\s\S]+?)%>/g,
reEvaluate = /<%([\s\S]+?)%>/g, reEvaluate = /<%([\s\S]+?)%>/g,
reInterpolate = /<%=([\s\S]+?)%>/g; reInterpolate = /<%=([\s\S]+?)%>/g;
/** /** Used to match property names within property paths. */
* Used to match ES template delimiters. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec reIsPlainProp = /^\w*$/,
-template-literal-lexical-components) rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?
* for more details. )\2)\]/g;
*/
/** Used to match `RegExp` [syntax characters](http://ecma-international.org/e
cma-262/6.0/#sec-patterns). */
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
reHasRegExpChar = RegExp(reRegExpChar.source);
/** Used to match leading and trailing whitespace. */
var reTrim = /^\s+|\s+$/g,
reTrimStart = /^\s+/,
reTrimEnd = /\s+$/;
/** Used to match backslashes in property paths. */
var reEscapeChar = /\\(\\)?/g;
/** Used to match [ES template delimiters](http://ecma-international.org/ecma-
262/6.0/#sec-template-literal-lexical-components). */
var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
/** Used to match `RegExp` flags from their coerced string values. */ /** Used to match `RegExp` flags from their coerced string values. */
var reFlags = /\w*$/; var reFlags = /\w*$/;
/** Used to detect named functions. */
var reFuncName = /^\s*function[ \n\r\t]+\w/;
/** Used to detect hexadecimal string values. */ /** Used to detect hexadecimal string values. */
var reHexPrefix = /^0[xX]/; var reHasHexPrefix = /^0x/i;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;
/** Used to detect host constructors (Safari > 5). */ /** Used to detect host constructors (Safari > 5). */
var reHostCtor = /^\[object .+?Constructor\]$/; var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;
/** Used to detect unsigned integer values. */
var reIsUint = /^(?:0|[1-9]\d*)$/;
/** Used to match latin-1 supplementary letters (excluding mathematical operat ors). */ /** Used to match latin-1 supplementary letters (excluding mathematical operat ors). */
var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g; var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
/** Used to ensure capturing order of template delimiters. */ /** Used to ensure capturing order of template delimiters. */
var reNoMatch = /($^)/; var reNoMatch = /($^)/;
/**
* Used to match `RegExp` special characters.
* See this [article on `RegExp` characters](http://www.regular-expressions.in
fo/characters.html#special)
* for more details.
*/
var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
reHasRegExpChars = RegExp(reRegExpChars.source);
/** Used to detect functions containing a `this` reference. */
var reThis = /\bthis\b/;
/** Used to match unescaped characters in compiled string literals. */ /** Used to match unescaped characters in compiled string literals. */
var reUnescapedString = /['\n\r\u2028\u2029\\]/g; var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
/** Used to match words to create compound words. */ /** Used to compose unicode character classes. */
var reWords = (function() { var rsAstralRange = '\\ud800-\\udfff',
var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]', rsComboRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+'; rsDingbatRange = '\\u2700-\\u27bf',
rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
return RegExp(upper + '{2,}(?=' + upper + lower + ')|' + upper + '?' + lower rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
+ '|' + upper + '+|[0-9]+', 'g'); rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
}()); rsQuoteRange = '\\u2018\\u2019\\u201c\\u201d',
rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e
/** Used to detect and test for whitespace. */ \\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u
var whitespace = ( 202f\\u205f\\u3000',
// Basic whitespace characters. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
' \t\x0b\f\xa0\ufeff' + rsVarRange = '\\ufe0e\\ufe0f',
rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRang
// Line terminators. e;
'\n\r\u2028\u2029' +
/** Used to compose unicode capture groups. */
// Unicode category "Zs" space separators. var rsAstral = '[' + rsAstralRange + ']',
'\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u2 rsBreak = '[' + rsBreakRange + ']',
00a\u202f\u205f\u3000' rsCombo = '[' + rsComboRange + ']',
); rsDigits = '\\d+',
rsDingbat = '[' + rsDingbatRange + ']',
rsLower = '[' + rsLowerRange + ']',
rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange +
rsLowerRange + rsUpperRange + ']',
rsModifier = '(?:\\ud83c[\\udffb-\\udfff])',
rsNonAstral = '[^' + rsAstralRange + ']',
rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
rsUpper = '[' + rsUpperRange + ']',
rsZWJ = '\\u200d';
/** Used to compose unicode regexes. */
var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
reOptMod = rsModifier + '?',
rsOptVar = '[' + rsVarRange + ']?',
rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].
join('|') + ')' + rsOptVar + reOptMod + ')*',
rsSeq = rsOptVar + reOptMod + rsOptJoin,
rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rs
Seq,
rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSu
rrPair, rsAstral].join('|') + ')';
/** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/
Combining_Diacritical_Marks). */
var reComboMark = RegExp(rsCombo, 'g');
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-u
nicode). */
var reComplexSymbol = RegExp(rsSymbol + rsSeq, 'g');
/** Used to detect strings with [zero-width joiners or code points from the as
tral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + r
sVarRange + ']');
/** Used to match non-compound words composed of alphanumeric characters. */
var reBasicWord = /[a-zA-Z0-9]+/g;
/** Used to match complex or compound words. */
var reComplexWord = RegExp([
rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
rsUpperMisc + '+(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')'
,
rsUpper + '?' + rsLowerMisc + '+',
rsDigits + '(?:' + rsLowerMisc + '+)?',
rsEmoji
].join('|'), 'g');
/** Used to detect strings that need a more robust regexp to match words. */
var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
/** Used to assign default `context` object properties. */ /** Used to assign default `context` object properties. */
var contextProps = [ var contextProps = [
'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array', 'Array', 'Date', 'Error', 'Float32Array', 'Float64Array', 'Function',
'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'document', 'Reflect', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
'isFinite', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', '_',
'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
'window', 'WinRTError'
]; ];
/** Used to make template sourceURLs easier to identify. */ /** Used to make template sourceURLs easier to identify. */
var templateCounter = -1; var templateCounter = -1;
/** Used to identify `toStringTag` values of typed arrays. */ /** Used to identify `toStringTag` values of typed arrays. */
var typedArrayTags = {}; var typedArrayTags = {};
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
skipping to change at line 184 skipping to change at line 260
typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] =
typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false; typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
/** Used to identify `toStringTag` values supported by `_.clone`. */ /** Used to identify `toStringTag` values supported by `_.clone`. */
var cloneableTags = {}; var cloneableTags = {};
cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[argsTag] = cloneableTags[arrayTag] =
cloneableTags[arrayBufferTag] = cloneableTags[boolTag] = cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
cloneableTags[dateTag] = cloneableTags[float32Tag] = cloneableTags[dateTag] = cloneableTags[float32Tag] =
cloneableTags[float64Tag] = cloneableTags[int8Tag] = cloneableTags[float64Tag] = cloneableTags[int8Tag] =
cloneableTags[int16Tag] = cloneableTags[int32Tag] = cloneableTags[int16Tag] = cloneableTags[int32Tag] =
cloneableTags[numberTag] = cloneableTags[objectTag] = cloneableTags[mapTag] = cloneableTags[numberTag] =
cloneableTags[regexpTag] = cloneableTags[stringTag] = cloneableTags[objectTag] = cloneableTags[regexpTag] =
cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = cloneableTags[setTag] = cloneableTags[stringTag] =
cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; cloneableTags[symbolTag] = cloneableTags[uint8Tag] =
cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] =
cloneableTags[uint32Tag] = true;
cloneableTags[errorTag] = cloneableTags[funcTag] = cloneableTags[errorTag] = cloneableTags[funcTag] =
cloneableTags[mapTag] = cloneableTags[setTag] =
cloneableTags[weakMapTag] = false; cloneableTags[weakMapTag] = false;
/** Used as an internal `_.debounce` options object by `_.throttle`. */
var debounceOptions = {
'leading': false,
'maxWait': 0,
'trailing': false
};
/** Used to map latin-1 supplementary letters to basic latin letters. */ /** Used to map latin-1 supplementary letters to basic latin letters. */
var deburredLetters = { var deburredLetters = {
'\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A ', '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A ',
'\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a ', '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a ',
'\xc7': 'C', '\xe7': 'c', '\xc7': 'C', '\xe7': 'c',
'\xd0': 'D', '\xf0': 'd', '\xd0': 'D', '\xf0': 'd',
'\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
'\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
'\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
'\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
skipping to change at line 256 skipping to change at line 326
/** Used to escape characters for inclusion in compiled string literals. */ /** Used to escape characters for inclusion in compiled string literals. */
var stringEscapes = { var stringEscapes = {
'\\': '\\', '\\': '\\',
"'": "'", "'": "'",
'\n': 'n', '\n': 'n',
'\r': 'r', '\r': 'r',
'\u2028': 'u2028', '\u2028': 'u2028',
'\u2029': 'u2029' '\u2029': 'u2029'
}; };
/** Built-in method references without a dependency on `root`. */
var freeParseFloat = parseFloat,
freeParseInt = parseInt;
/** Detect free variable `exports`. */
var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType
) ? exports : null;
/** Detect free variable `module`. */
var freeModule = (objectTypes[typeof module] && module && !module.nodeType) ?
module : null;
/** Detect free variable `global` from Node.js. */
var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'ob
ject' && global);
/** Detect free variable `self`. */
var freeSelf = checkGlobal(objectTypes[typeof self] && self);
/** Detect free variable `window`. */
var freeWindow = checkGlobal(objectTypes[typeof window] && window);
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = (freeModule && freeModule.exports === freeExports) ? freeE
xports : null;
/** Detect `this` as the global object. */
var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
/** /**
* Used as a reference to the global object. * Used as a reference to the global object.
* *
* The `this` value is used if it is the global object to avoid Greasemonkey's * The `this` value is used if it's the global object to avoid Greasemonkey's
* restricted `window` object, otherwise the `window` object is used. * restricted `window` object, otherwise the `window` object is used.
*/ */
var root = (objectTypes[typeof window] && window !== (this && this.window)) ? window : this; var root = freeGlobal || ((freeWindow !== (thisGlobal && thisGlobal.window)) & & freeWindow) || freeSelf || thisGlobal || Function('return this')();
/** Detect free variable `exports`. */ /*--------------------------------------------------------------------------*/
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType
&& exports;
/** Detect free variable `module`. */ /**
var freeModule = objectTypes[typeof module] && module && !module.nodeType && m * Adds the key-value `pair` to `map`.
odule; *
* @private
* @param {Object} map The map to modify.
* @param {Array} pair The key-value pair to add.
* @returns {Object} Returns `map`.
*/
function addMapEntry(map, pair) {
map.set(pair[0], pair[1]);
return map;
}
/** Detect free variable `global` from Node.js or Browserified code and use it /**
as `root`. */ * Adds `value` to `set`.
var freeGlobal = freeExports && freeModule && typeof global == 'object' && glo *
bal; * @private
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === f * @param {Object} set The set to modify.
reeGlobal || freeGlobal.self === freeGlobal)) { * @param {*} value The value to add.
root = freeGlobal; * @returns {Object} Returns `set`.
*/
function addSetEntry(set, value) {
set.add(value);
return set;
} }
/** Detect the popular CommonJS extension `module.exports`. */ /**
var moduleExports = freeModule && freeModule.exports === freeExports && freeEx * A faster alternative to `Function#apply`, this function invokes `func`
ports; * with the `this` binding of `thisArg` and the arguments of `args`.
*
* @private
* @param {Function} func The function to invoke.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} [args] The arguments to invoke `func` with.
* @returns {*} Returns the result of `func`.
*/
function apply(func, thisArg, args) {
var length = args ? args.length : 0;
switch (length) {
case 0: return func.call(thisArg);
case 1: return func.call(thisArg, args[0]);
case 2: return func.call(thisArg, args[0], args[1]);
case 3: return func.call(thisArg, args[0], args[1], args[2]);
}
return func.apply(thisArg, args);
}
/*--------------------------------------------------------------------------*/ /**
* Creates a new array concatenating `array` with `other`.
*
* @private
* @param {Array} array The first array to concatenate.
* @param {Array} other The second array to concatenate.
* @returns {Array} Returns the new concatenated array.
*/
function arrayConcat(array, other) {
var index = -1,
length = array.length,
othIndex = -1,
othLength = other.length,
result = Array(length + othLength);
while (++index < length) {
result[index] = array[index];
}
while (++othIndex < othLength) {
result[index++] = other[othIndex];
}
return result;
}
/** /**
* The base implementation of `compareAscending` which compares values and * A specialized version of `_.forEach` for arrays without support for
* sorts them in ascending order without guaranteeing a stable sort. * iteratee shorthands.
* *
* @private * @private
* @param {*} value The value to compare to `other`. * @param {Array} array The array to iterate over.
* @param {*} other The value to compare to `value`. * @param {Function} iteratee The function invoked per iteration.
* @returns {number} Returns the sort order indicator for `value`. * @returns {Array} Returns `array`.
*/ */
function baseCompareAscending(value, other) { function arrayEach(array, iteratee) {
if (value !== other) { var index = -1,
var valIsReflexive = value === value, length = array.length;
othIsReflexive = other === other;
if (value > other || !valIsReflexive || (typeof value == 'undefined' && ot while (++index < length) {
hIsReflexive)) { if (iteratee(array[index], index, array) === false) {
return 1; break;
} }
if (value < other || !othIsReflexive || (typeof other == 'undefined' && va }
lIsReflexive)) { return array;
return -1; }
/**
* A specialized version of `_.forEachRight` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns `array`.
*/
function arrayEachRight(array, iteratee) {
var length = array.length;
while (length--) {
if (iteratee(array[length], length, array) === false) {
break;
} }
} }
return 0; return array;
}
/**
* A specialized version of `_.every` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if all elements pass the predicate check,
else `false`.
*/
function arrayEvery(array, predicate) {
var index = -1,
length = array.length;
while (++index < length) {
if (!predicate(array[index], index, array)) {
return false;
}
}
return true;
}
/**
* A specialized version of `_.filter` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
*/
function arrayFilter(array, predicate) {
var index = -1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index];
if (predicate(value, index, array)) {
result[++resIndex] = value;
}
}
return result;
}
/**
* A specialized version of `_.includes` for arrays without support for
* specifying an index to search from.
*
* @private
* @param {Array} array The array to search.
* @param {*} target The value to search for.
* @returns {boolean} Returns `true` if `target` is found, else `false`.
*/
function arrayIncludes(array, value) {
return !!array.length && baseIndexOf(array, value, 0) > -1;
}
/**
* A specialized version of `_.includesWith` for arrays without support for
* specifying an index to search from.
*
* @private
* @param {Array} array The array to search.
* @param {*} target The value to search for.
* @param {Function} comparator The comparator invoked per element.
* @returns {boolean} Returns `true` if `target` is found, else `false`.
*/
function arrayIncludesWith(array, value, comparator) {
var index = -1,
length = array.length;
while (++index < length) {
if (comparator(value, array[index])) {
return true;
}
}
return false;
}
/**
* A specialized version of `_.map` for arrays without support for iteratee
* shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
*/
function arrayMap(array, iteratee) {
var index = -1,
length = array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
}
/**
* Appends the elements of `values` to `array`.
*
* @private
* @param {Array} array The array to modify.
* @param {Array} values The values to append.
* @returns {Array} Returns `array`.
*/
function arrayPush(array, values) {
var index = -1,
length = values.length,
offset = array.length;
while (++index < length) {
array[offset + index] = values[index];
}
return array;
}
/**
* A specialized version of `_.reduce` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @param {boolean} [initFromArray] Specify using the first element of `array`
as the initial value.
* @returns {*} Returns the accumulated value.
*/
function arrayReduce(array, iteratee, accumulator, initFromArray) {
var index = -1,
length = array.length;
if (initFromArray && length) {
accumulator = array[++index];
}
while (++index < length) {
accumulator = iteratee(accumulator, array[index], index, array);
}
return accumulator;
}
/**
* A specialized version of `_.reduceRight` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @param {boolean} [initFromArray] Specify using the last element of `array`
as the initial value.
* @returns {*} Returns the accumulated value.
*/
function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
var length = array.length;
if (initFromArray && length) {
accumulator = array[--length];
}
while (length--) {
accumulator = iteratee(accumulator, array[length], length, array);
}
return accumulator;
} }
/** /**
* The base implementation of `_.indexOf` without support for binary searches. * A specialized version of `_.some` for arrays without support for iteratee
* shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate check
, else `false`.
*/
function arraySome(array, predicate) {
var index = -1,
length = array.length;
while (++index < length) {
if (predicate(array[index], index, array)) {
return true;
}
}
return false;
}
/**
* The base implementation of methods like `_.max` and `_.min` which accepts a
* `comparator` to determine the extremum value.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The iteratee invoked per iteration.
* @param {Function} comparator The comparator used to compare values.
* @returns {*} Returns the extremum value.
*/
function baseExtremum(array, iteratee, comparator) {
var index = -1,
length = array.length;
while (++index < length) {
var value = array[index],
current = iteratee(value);
if (current != null && (computed === undefined
? current === current
: comparator(current, computed)
)) {
var computed = current,
result = value;
}
}
return result;
}
/**
* The base implementation of methods like `_.find` and `_.findKey`, without
* support for iteratee shorthands, which iterates over `collection` using
* the provided `eachFunc`.
*
* @private
* @param {Array|Object} collection The collection to search.
* @param {Function} predicate The function invoked per iteration.
* @param {Function} eachFunc The function to iterate over `collection`.
* @param {boolean} [retKey] Specify returning the key of the found element in
stead of the element itself.
* @returns {*} Returns the found element or its key, else `undefined`.
*/
function baseFind(collection, predicate, eachFunc, retKey) {
var result;
eachFunc(collection, function(value, key, collection) {
if (predicate(value, key, collection)) {
result = retKey ? key : value;
return false;
}
});
return result;
}
/**
* The base implementation of `_.findIndex` and `_.findLastIndex` without
* support for iteratee shorthands.
*
* @private
* @param {Array} array The array to search.
* @param {Function} predicate The function invoked per iteration.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function baseFindIndex(array, predicate, fromRight) {
var length = array.length,
index = fromRight ? length : -1;
while ((fromRight ? index-- : ++index < length)) {
if (predicate(array[index], index, array)) {
return index;
}
}
return -1;
}
/**
* The base implementation of `_.indexOf` without `fromIndex` bounds checks.
* *
* @private * @private
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {*} value The value to search for. * @param {*} value The value to search for.
* @param {number} [fromIndex=0] The index to search from. * @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
*/ */
function baseIndexOf(array, value, fromIndex) { function baseIndexOf(array, value, fromIndex) {
if (value !== value) { if (value !== value) {
return indexOfNaN(array, fromIndex); return indexOfNaN(array, fromIndex);
} }
var index = (fromIndex || 0) - 1, var index = fromIndex - 1,
length = array.length; length = array.length;
while (++index < length) { while (++index < length) {
if (array[index] === value) { if (array[index] === value) {
return index; return index;
} }
} }
return -1; return -1;
} }
/** /**
* The base implementation of `_.sortBy` and `_.sortByAll` which uses `compare * The base implementation of `_.reduce` and `_.reduceRight`, without support
r` * for iteratee shorthands, which iterates over `collection` using the provide
* to define the sort order of `array` and replaces criteria objects with thei d
r * `eachFunc`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} accumulator The initial value.
* @param {boolean} initFromCollection Specify using the first or last element
of `collection` as the initial value.
* @param {Function} eachFunc The function to iterate over `collection`.
* @returns {*} Returns the accumulated value.
*/
function baseReduce(collection, iteratee, accumulator, initFromCollection, eac
hFunc) {
eachFunc(collection, function(value, index, collection) {
accumulator = initFromCollection
? (initFromCollection = false, value)
: iteratee(accumulator, value, index, collection);
});
return accumulator;
}
/**
* The base implementation of `_.sortBy` which uses `comparer` to define
* the sort order of `array` and replaces criteria objects with their
* corresponding values. * corresponding values.
* *
* @private * @private
* @param {Array} array The array to sort. * @param {Array} array The array to sort.
* @param {Function} comparer The function to define sort order. * @param {Function} comparer The function to define sort order.
* @returns {Array} Returns `array`. * @returns {Array} Returns `array`.
*/ */
function baseSortBy(array, comparer) { function baseSortBy(array, comparer) {
var length = array.length; var length = array.length;
array.sort(comparer); array.sort(comparer);
while (length--) { while (length--) {
array[length] = array[length].value; array[length] = array[length].value;
} }
return array; return array;
} }
/** /**
* Converts `value` to a string if it is not one. An empty string is returned * The base implementation of `_.sum` without support for iteratee shorthands.
* for `null` or `undefined` values.
* *
* @private * @private
* @param {*} value The value to process. * @param {Array} array The array to iterate over.
* @returns {string} Returns the string. * @param {Function} iteratee The function invoked per iteration.
* @returns {number} Returns the sum.
*/ */
function baseToString(value) { function baseSum(array, iteratee) {
if (typeof value == 'string') { var result,
return value; index = -1,
length = array.length;
while (++index < length) {
var current = iteratee(array[index]);
if (current !== undefined) {
result = result === undefined ? current : (result + current);
}
} }
return value == null ? '' : (value + ''); return result;
} }
/** /**
* Used by `_.max` and `_.min` as the default callback for string values. * The base implementation of `_.times` without support for iteratee shorthand
s
* or max array length checks.
* *
* @private * @private
* @param {string} string The string to inspect. * @param {number} n The number of times to invoke `iteratee`.
* @returns {number} Returns the code unit of the first character of the strin * @param {Function} iteratee The function invoked per iteration.
g. * @returns {Array} Returns the array of results.
*/
function baseTimes(n, iteratee) {
var index = -1,
result = Array(n);
while (++index < n) {
result[index] = iteratee(index);
}
return result;
}
/**
* The base implementation of `_.toPairs` and `_.toPairsIn` which creates an a
rray
* of key-value pairs for `object` corresponding to the property names of `pro
ps`.
*
* @private
* @param {Object} object The object to query.
* @param {Array} props The property names to get values for.
* @returns {Object} Returns the new array of key-value pairs.
*/ */
function charAtCallback(string) { function baseToPairs(object, props) {
return string.charCodeAt(0); return arrayMap(props, function(key) {
return [key, object[key]];
});
} }
/** /**
* Used by `_.trim` and `_.trimLeft` to get the index of the first character * The base implementation of `_.unary` without support for storing wrapper me
* of `string` that is not found in `chars`. tadata.
* *
* @private * @private
* @param {string} string The string to inspect. * @param {Function} func The function to cap arguments for.
* @param {string} chars The characters to find. * @returns {Function} Returns the new function.
* @returns {number} Returns the index of the first character not found in `ch */
ars`. function baseUnary(func) {
return function(value) {
return func(value);
};
}
/**
* The base implementation of `_.values` and `_.valuesIn` which creates an
* array of `object` property values corresponding to the property names
* of `props`.
*
* @private
* @param {Object} object The object to query.
* @param {Array} props The property names to get values for.
* @returns {Object} Returns the array of property values.
*/
function baseValues(object, props) {
return arrayMap(props, function(key) {
return object[key];
});
}
/**
* Used by `_.trim` and `_.trimStart` to get the index of the first string sym
bol
* that is not found in the character symbols.
*
* @private
* @param {Array} strSymbols The string symbols to inspect.
* @param {Array} chrSymbols The character symbols to find.
* @returns {number} Returns the index of the first unmatched string symbol.
*/ */
function charsLeftIndex(string, chars) { function charsStartIndex(strSymbols, chrSymbols) {
var index = -1, var index = -1,
length = string.length; length = strSymbols.length;
while (++index < length && chars.indexOf(string.charAt(index)) > -1) {} while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > - 1) {}
return index; return index;
} }
/** /**
* Used by `_.trim` and `_.trimRight` to get the index of the last character * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
* of `string` that is not found in `chars`. * that is not found in the character symbols.
* *
* @private * @private
* @param {string} string The string to inspect. * @param {Array} strSymbols The string symbols to inspect.
* @param {string} chars The characters to find. * @param {Array} chrSymbols The character symbols to find.
* @returns {number} Returns the index of the last character not found in `cha * @returns {number} Returns the index of the last unmatched string symbol.
rs`.
*/ */
function charsRightIndex(string, chars) { function charsEndIndex(strSymbols, chrSymbols) {
var index = string.length; var index = strSymbols.length;
while (index-- && chars.indexOf(string.charAt(index)) > -1) {} while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
return index; return index;
} }
/** /**
* Used by `_.sortBy` to compare transformed elements of a collection and stab * Checks if `value` is a global object.
le
* sort them in ascending order.
* *
* @private * @private
* @param {Object} object The object to compare to `other`. * @param {*} value The value to check.
* @param {Object} other The object to compare to `object`. * @returns {null|Object} Returns `value` if it's a global object, else `null`
* @returns {number} Returns the sort order indicator for `object`. .
*/
function checkGlobal(value) {
return (value && value.Object === Object) ? value : null;
}
/**
* Compares values to sort them in ascending order.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {number} Returns the sort order indicator for `value`.
*/ */
function compareAscending(object, other) { function compareAscending(value, other) {
return baseCompareAscending(object.criteria, other.criteria) || (object.inde if (value !== other) {
x - other.index); var valIsNull = value === null,
valIsUndef = value === undefined,
valIsReflexive = value === value;
var othIsNull = other === null,
othIsUndef = other === undefined,
othIsReflexive = other === other;
if ((value > other && !othIsNull) || !valIsReflexive ||
(valIsNull && !othIsUndef && othIsReflexive) ||
(valIsUndef && othIsReflexive)) {
return 1;
}
if ((value < other && !valIsNull) || !othIsReflexive ||
(othIsNull && !valIsUndef && valIsReflexive) ||
(othIsUndef && valIsReflexive)) {
return -1;
}
}
return 0;
} }
/** /**
* Used by `_.sortByAll` to compare multiple properties of each element * Used by `_.orderBy` to compare multiple properties of a value to another
* in a collection and stable sort them in ascending order. * and stable sort them.
*
* If `orders` is unspecified, all values are sorted in ascending order. Other
wise,
* specify an order of "desc" for descending or "asc" for ascending sort order
* of corresponding values.
* *
* @private * @private
* @param {Object} object The object to compare to `other`. * @param {Object} object The object to compare.
* @param {Object} other The object to compare to `object`. * @param {Object} other The other object to compare.
* @param {boolean[]|string[]} orders The order to sort by for each property.
* @returns {number} Returns the sort order indicator for `object`. * @returns {number} Returns the sort order indicator for `object`.
*/ */
function compareMultipleAscending(object, other) { function compareMultiple(object, other, orders) {
var index = -1, var index = -1,
objCriteria = object.criteria, objCriteria = object.criteria,
othCriteria = other.criteria, othCriteria = other.criteria,
length = objCriteria.length; length = objCriteria.length,
ordersLength = orders.length;
while (++index < length) { while (++index < length) {
var result = baseCompareAscending(objCriteria[index], othCriteria[index]); var result = compareAscending(objCriteria[index], othCriteria[index]);
if (result) { if (result) {
return result; if (index >= ordersLength) {
return result;
}
var order = orders[index];
return result * (order == 'desc' ? -1 : 1);
} }
} }
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to provide the same value fo r // that causes it, under certain circumstances, to provide the same value fo r
// `object` and `other`. See https://github.com/jashkenas/underscore/pull/12 47 // `object` and `other`. See https://github.com/jashkenas/underscore/pull/12 47
// for more details. // for more details.
// //
// This also ensures a stable sort in V8 and other engines. // This also ensures a stable sort in V8 and other engines.
// See https://code.google.com/p/v8/issues/detail?id=90 for more details. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
return object.index - other.index; return object.index - other.index;
skipping to change at line 475 skipping to change at line 1024
* *
* @private * @private
* @param {string} chr The matched character to escape. * @param {string} chr The matched character to escape.
* @returns {string} Returns the escaped character. * @returns {string} Returns the escaped character.
*/ */
function escapeHtmlChar(chr) { function escapeHtmlChar(chr) {
return htmlEscapes[chr]; return htmlEscapes[chr];
} }
/** /**
* Used by `_.template` to escape characters for inclusion in compiled * Used by `_.template` to escape characters for inclusion in compiled string
* string literals. literals.
* *
* @private * @private
* @param {string} chr The matched character to escape. * @param {string} chr The matched character to escape.
* @returns {string} Returns the escaped character. * @returns {string} Returns the escaped character.
*/ */
function escapeStringChar(chr) { function escapeStringChar(chr) {
return '\\' + stringEscapes[chr]; return '\\' + stringEscapes[chr];
} }
/** /**
* Gets the index at which the first occurrence of `NaN` is found in `array`. * Gets the index at which the first occurrence of `NaN` is found in `array`.
* If `fromRight` is provided elements of `array` are iterated from right to l eft.
* *
* @private * @private
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {number} [fromIndex] The index to search from. * @param {number} fromIndex The index to search from.
* @param {boolean} [fromRight] Specify iterating from right to left. * @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched `NaN`, else `-1`. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
*/ */
function indexOfNaN(array, fromIndex, fromRight) { function indexOfNaN(array, fromIndex, fromRight) {
var length = array.length, var length = array.length,
index = fromRight ? (fromIndex || length) : ((fromIndex || 0) - 1); index = fromIndex + (fromRight ? 0 : -1);
while ((fromRight ? index-- : ++index < length)) { while ((fromRight ? index-- : ++index < length)) {
var other = array[index]; var other = array[index];
if (other !== other) { if (other !== other) {
return index; return index;
} }
} }
return -1; return -1;
} }
/** /**
* Checks if `value` is object-like. * Checks if `value` is a host object in IE < 9.
* *
* @private * @private
* @param {*} value The value to check. * @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. * @returns {boolean} Returns `true` if `value` is a host object, else `false` .
*/ */
function isObjectLike(value) { function isHostObject(value) {
return (value && typeof value == 'object') || false; // Many host objects are `Object` objects that can coerce to strings
// despite having improperly defined `toString` methods.
var result = false;
if (value != null && typeof value.toString != 'function') {
try {
result = !!(value + '');
} catch (e) {}
}
return result;
} }
/** /**
* Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a * Checks if `value` is a valid array-like index.
* character code is whitespace.
* *
* @private * @private
* @param {number} charCode The character code to inspect. * @param {*} value The value to check.
* @returns {boolean} Returns `true` if `charCode` is whitespace, else `false` * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index
. .
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`
.
*/ */
function isSpace(charCode) { function isIndex(value, length) {
return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
32 || charCode == 160) || charCode == 5760 || charCode == 6158 || length = length == null ? MAX_SAFE_INTEGER : length;
(charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == return value > -1 && value % 1 == 0 && value < length;
8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == }
65279)));
/**
* Converts `iterator` to an array.
*
* @private
* @param {Object} iterator The iterator to convert.
* @returns {Array} Returns the converted array.
*/
function iteratorToArray(iterator) {
var data,
result = [];
while (!(data = iterator.next()).done) {
result.push(data.value);
}
return result;
}
/**
* Converts `map` to an array.
*
* @private
* @param {Object} map The map to convert.
* @returns {Array} Returns the converted array.
*/
function mapToArray(map) {
var index = -1,
result = Array(map.size);
map.forEach(function(value, key) {
result[++index] = [key, value];
});
return result;
} }
/** /**
* Replaces all `placeholder` elements in `array` with an internal placeholder * Replaces all `placeholder` elements in `array` with an internal placeholder
* and returns an array of their indexes. * and returns an array of their indexes.
* *
* @private * @private
* @param {Array} array The array to modify. * @param {Array} array The array to modify.
* @param {*} placeholder The placeholder to replace. * @param {*} placeholder The placeholder to replace.
* @returns {Array} Returns the new array of placeholder indexes. * @returns {Array} Returns the new array of placeholder indexes.
skipping to change at line 558 skipping to change at line 1148
while (++index < length) { while (++index < length) {
if (array[index] === placeholder) { if (array[index] === placeholder) {
array[index] = PLACEHOLDER; array[index] = PLACEHOLDER;
result[++resIndex] = index; result[++resIndex] = index;
} }
} }
return result; return result;
} }
/** /**
* An implementation of `_.uniq` optimized for sorted arrays without support * Converts `set` to an array.
* for callback shorthands and `this` binding.
* *
* @private * @private
* @param {Array} array The array to inspect. * @param {Object} set The set to convert.
* @param {Function} [iteratee] The function invoked per iteration. * @returns {Array} Returns the converted array.
* @returns {Array} Returns the new duplicate-value-free array.
*/ */
function sortedUniq(array, iteratee) { function setToArray(set) {
var seen, var index = -1,
index = -1, result = Array(set.size);
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index],
computed = iteratee ? iteratee(value, index, array) : value;
if (!index || seen !== computed) { set.forEach(function(value) {
seen = computed; result[++index] = value;
result[++resIndex] = value; });
}
}
return result; return result;
} }
/** /**
* Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitesp * Gets the number of symbols in `string`.
ace
* character of `string`.
* *
* @private
* @param {string} string The string to inspect. * @param {string} string The string to inspect.
* @returns {number} Returns the index of the first non-whitespace character. * @returns {number} Returns the string size.
*/ */
function trimmedLeftIndex(string) { function stringSize(string) {
var index = -1, if (!(string && reHasComplexSymbol.test(string))) {
length = string.length; return string.length;
}
while (++index < length && isSpace(string.charCodeAt(index))) {} var result = reComplexSymbol.lastIndex = 0;
return index; while (reComplexSymbol.test(string)) {
result++;
}
return result;
} }
/** /**
* Used by `_.trim` and `_.trimRight` to get the index of the last non-whitesp * Converts `string` to an array.
ace
* character of `string`.
* *
* @private * @private
* @param {string} string The string to inspect. * @param {string} string The string to convert.
* @returns {number} Returns the index of the last non-whitespace character. * @returns {Array} Returns the converted array.
*/ */
function trimmedRightIndex(string) { function stringToArray(string) {
var index = string.length; return string.match(reComplexSymbol);
while (index-- && isSpace(string.charCodeAt(index))) {}
return index;
} }
/** /**
* Used by `_.unescape` to convert HTML entities to characters. * Used by `_.unescape` to convert HTML entities to characters.
* *
* @private * @private
* @param {string} chr The matched character to unescape. * @param {string} chr The matched character to unescape.
* @returns {string} Returns the unescaped character. * @returns {string} Returns the unescaped character.
*/ */
function unescapeHtmlChar(chr) { function unescapeHtmlChar(chr) {
return htmlUnescapes[chr]; return htmlUnescapes[chr];
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/** /**
* Create a new pristine `lodash` function using the given `context` object. * Create a new pristine `lodash` function using the `context` object.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Utility * @category Util
* @param {Object} [context=root] The context object. * @param {Object} [context=root] The context object.
* @returns {Function} Returns a new `lodash` function. * @returns {Function} Returns a new `lodash` function.
* @example * @example
* *
* _.mixin({ 'add': function(a, b) { return a + b; } }); * _.mixin({ 'foo': _.constant('foo') });
* *
* var lodash = _.runInContext(); * var lodash = _.runInContext();
* lodash.mixin({ 'sub': function(a, b) { return a - b; } }); * lodash.mixin({ 'bar': lodash.constant('bar') });
* *
* _.isFunction(_.add); * _.isFunction(_.foo);
* // => true * // => true
* _.isFunction(_.sub); * _.isFunction(_.bar);
* // => false * // => false
* *
* lodash.isFunction(lodash.add); * lodash.isFunction(lodash.foo);
* // => false * // => false
* lodash.isFunction(lodash.sub); * lodash.isFunction(lodash.bar);
* // => true * // => true
* *
* // using `context` to mock `Date#getTime` use in `_.now` * // using `context` to mock `Date#getTime` use in `_.now`
* var mock = _.runInContext({ * var mock = _.runInContext({
* 'Date': function() { * 'Date': function() {
* return { 'getTime': getTimeMock }; * return { 'getTime': getTimeMock };
* } * }
* }); * });
* *
* // or creating a suped-up `defer` in Node.js * // or creating a suped-up `defer` in Node.js
* var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
*/ */
function runInContext(context) { function runInContext(context) {
// Avoid issues with some ES3 environments that attempt to use values, named context = context ? _.defaults({}, context, _.pick(root, contextProps)) : ro
// after built-in constructors like `Object`, for the creation of literals. ot;
// ES5 clears this up by stating that literals must use built-in constructor
s. /** Built-in constructor references. */
// See https://es5.github.io/#x11.1.5 for more details. var Date = context.Date,
context = context ? _.defaults(root.Object(), context, _.pick(root, contextP
rops)) : root;
/** Native constructor references. */
var Array = context.Array,
Date = context.Date,
Error = context.Error, Error = context.Error,
Function = context.Function,
Math = context.Math, Math = context.Math,
Number = context.Number,
Object = context.Object,
RegExp = context.RegExp, RegExp = context.RegExp,
String = context.String,
TypeError = context.TypeError; TypeError = context.TypeError;
/** Used for native method references. */ /** Used for built-in method references. */
var arrayProto = Array.prototype, var arrayProto = context.Array.prototype,
objectProto = Object.prototype; objectProto = context.Object.prototype;
/** Used to detect DOM support. */
var document = (document = context.window) && document.document;
/** Used to resolve the decompiled source of functions. */ /** Used to resolve the decompiled source of functions. */
var fnToString = Function.prototype.toString; var funcToString = context.Function.prototype.toString;
/** Used to the length of n-tuples for `_.unzip`. */
var getLength = baseProperty('length');
/** Used to check objects for own properties. */ /** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty; var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to generate unique IDs. */ /** Used to generate unique IDs. */
var idCounter = 0; var idCounter = 0;
/** Used to infer the `Object` constructor. */
var objectCtorString = funcToString.call(Object);
/** /**
* Used to resolve the `toStringTag` of values. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-26
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#s 2/6.0/#sec-object.prototype.tostring)
ec-object.prototype.tostring) * of values.
* for more details.
*/ */
var objToString = objectProto.toString; var objectToString = objectProto.toString;
/** Used to restore the original `_` reference in `_.noConflict`. */ /** Used to restore the original `_` reference in `_.noConflict`. */
var oldDash = context._; var oldDash = root._;
/** Used to detect if a method is native. */ /** Used to detect if a method is native. */
var reNative = RegExp('^' + var reIsNative = RegExp('^' +
escapeRegExp(objToString) funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
.replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$ .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?'
' ) + '$'
); );
/** Native method references. */ /** Built-in value references. */
var ArrayBuffer = isNative(ArrayBuffer = context.ArrayBuffer) && ArrayBuffer var _Symbol = context.Symbol,
, Reflect = context.Reflect,
bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).s Uint8Array = context.Uint8Array,
lice) && bufferSlice,
ceil = Math.ceil,
clearTimeout = context.clearTimeout, clearTimeout = context.clearTimeout,
floor = Math.floor, enumerate = Reflect ? Reflect.enumerate : undefined,
getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && get getPrototypeOf = Object.getPrototypeOf,
PrototypeOf, getOwnPropertySymbols = Object.getOwnPropertySymbols,
push = arrayProto.push, iteratorSymbol = typeof (iteratorSymbol = _Symbol && _Symbol.iterator) =
= 'symbol' ? iteratorSymbol : undefined,
propertyIsEnumerable = objectProto.propertyIsEnumerable, propertyIsEnumerable = objectProto.propertyIsEnumerable,
Set = isNative(Set = context.Set) && Set,
setTimeout = context.setTimeout, setTimeout = context.setTimeout,
splice = arrayProto.splice, splice = arrayProto.splice;
Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array,
unshift = arrayProto.unshift,
WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap;
/** Used to clone array buffers. */
var Float64Array = (function() {
// Safari 5 errors when using an array buffer to initialize a typed array
// where the array buffer's `byteLength` is not a multiple of the typed
// array's `BYTES_PER_ELEMENT`.
try {
var func = isNative(func = context.Float64Array) && func,
result = new func(new ArrayBuffer(10), 0, 1) && func;
} catch(e) {}
return result;
}());
/* Native method references for those with the same name as other `lodash` m /* Built-in method references for those with the same name as other `lodash`
ethods. */ methods. */
var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray var nativeCeil = Math.ceil,
, nativeFloor = Math.floor,
nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
nativeIsFinite = context.isFinite, nativeIsFinite = context.isFinite,
nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys, nativeJoin = arrayProto.join,
nativeKeys = Object.keys,
nativeMax = Math.max, nativeMax = Math.max,
nativeMin = Math.min, nativeMin = Math.min,
nativeNow = isNative(nativeNow = Date.now) && nativeNow,
nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nat
iveNumIsFinite,
nativeParseInt = context.parseInt, nativeParseInt = context.parseInt,
nativeRandom = Math.random; nativeRandom = Math.random,
nativeReverse = arrayProto.reverse;
/** Used as references for `-Infinity` and `Infinity`. */ /* Built-in method references that are verified to be native. */
var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY, var Map = getNative(context, 'Map'),
POSITIVE_INFINITY = Number.POSITIVE_INFINITY; Set = getNative(context, 'Set'),
WeakMap = getNative(context, 'WeakMap'),
/** Used as references for the maximum length and index of an array. */ nativeCreate = getNative(Object, 'create');
var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
/** Used as the size, in bytes, of each `Float64Array` element. */
var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMEN
T : 0;
/**
* Used as the maximum length of an array-like value.
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#s
ec-tolength)
* for more details.
*/
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
/** Used to store function metadata. */ /** Used to store function metadata. */
var metaMap = WeakMap && new WeakMap; var metaMap = WeakMap && new WeakMap;
/** Used to detect maps and sets. */
var mapCtorString = Map ? funcToString.call(Map) : '',
setCtorString = Set ? funcToString.call(Set) : '';
/** Used to convert symbols to primitives and strings. */
var symbolProto = _Symbol ? _Symbol.prototype : undefined,
symbolValueOf = _Symbol ? symbolProto.valueOf : undefined,
symbolToString = _Symbol ? symbolProto.toString : undefined;
/** Used to lookup unminified function names. */
var realNames = {};
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/** /**
* Creates a `lodash` object which wraps `value` to enable intuitive chainin * Creates a `lodash` object which wraps `value` to enable implicit method
g. * chaining. Methods that operate on and return arrays, collections, and
* Methods that operate on and return arrays, collections, and functions can * functions can be chained together. Methods that retrieve a single value o
* be chained together. Methods that return a boolean or single value will r
* automatically end the chain returning the unwrapped value. Explicit chain * may return a primitive value will automatically end the chain sequence an
ing d
* may be enabled using `_.chain`. The execution of chained methods is lazy, * return the unwrapped value. Otherwise, the value must be unwrapped with
* that is, execution is deferred until `_#value` is implicitly or explicitl * `_#value`.
y *
* called. * Explicit chaining, which must be unwrapped with `_#value` in all cases,
* may be enabled using `_.chain`.
*
* The execution of chained methods is lazy, that is, it's deferred until
* `_#value` is implicitly or explicitly called.
* *
* Lazy evaluation allows several methods to support shortcut fusion. Shortc ut * Lazy evaluation allows several methods to support shortcut fusion. Shortc ut
* fusion is an optimization that merges iteratees to avoid creating interme * fusion is an optimization to merge iteratee calls; this avoids the creati
diate on
* arrays and reduce the number of iteratee executions. * of intermediate arrays and can greatly reduce the number of iteratee exec
utions.
* Sections of a chain sequence qualify for shortcut fusion if the section i
s
* applied to an array of at least two hundred elements and any iteratees
* accept only one argument. The heuristic for whether a section qualifies
* for shortcut fusion is subject to change.
* *
* Chaining is supported in custom builds as long as the `_#value` method is * Chaining is supported in custom builds as long as the `_#value` method is
* directly or indirectly included in the build. * directly or indirectly included in the build.
* *
* In addition to lodash methods, wrappers also have the following `Array` m * In addition to lodash methods, wrappers have `Array` and `String` methods
ethods: .
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `sp *
lice`, * The wrapper `Array` methods are:
* and `unshift` * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
* *
* The wrapper functions that support shortcut fusion are: * The wrapper `String` methods are:
* `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `first`, * `replace` and `split`
* `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, `slice`,
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `where`
*
* The chainable wrapper functions are:
* `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
* `callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`,
* `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`
,
* `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`,
* `flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`,
* `forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`,
* `initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`,
* `mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`,
* `omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`,
* `pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`,
* `rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort
`,
* `sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`,
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObjec
t`,
* `transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`,
* `where`, `without`, `wrap`, `xor`, `zip`, and `zipObject`
*
* The wrapper functions that are **not** chainable by default are:
* `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `find
Key`,
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
* `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`,
* `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`,
* `isFunction`, `isMatch` , `isNative`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
* `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
* `unescape`, `uniqueId`, `value`, and `words`
* *
* The wrapper function `sample` will return a wrapped value when `n` is pro * The wrapper methods that support shortcut fusion are:
vided, * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
* otherwise an unwrapped value is returned. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice
`,
* `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
*
* The chainable wrapper methods are:
* `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`,
* `at`, `before`, `bind`, `bindAll`, `bindKey`, `chain`, `chunk`, `commit`,
* `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, `curry
`,
* `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `difference`,
* `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
* `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flip`, `flow`,
* `flowRight`, `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`,
* `forOwnRight`, `fromPairs`, `functions`, `functionsIn`, `groupBy`, `initi
al`,
* `intersection`, `intersectionBy`, `intersectionWith`, invert`, `invokeMap
`,
* `iteratee`, `keyBy`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`,
* `matches`, `matchesProperty`, `memoize`, `merge`, `mergeWith`, `method`,
* `methodOf`, `mixin`, `negate`, `nthArg`, `omit`, `omitBy`, `once`, `order
By`,
* `over`, `overArgs`, `overEvery`, `overSome`, `partial`, `partialRight`,
* `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
* `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`,
* `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`,
* `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`,
* `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`,
* `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`
,
* `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`,
* `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `without`
,
* `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, `zipObject`, and `zipWith`
*
* The wrapper methods that are **not** chainable by default are:
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
* `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
* `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
* `findLast`, `findLastIndex`, `findLastKey`, `floor`, `get`, `gt`, `gte`,
* `has`, `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`,
* `invoke`, `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`,
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
* `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`,
* `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`,
* `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`,
* `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`, `last`,
* `lastIndexOf`, `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`,
* `mean`, `min`, `minBy`, `noConflict`, `noop`, `now`, `pad`, `padEnd`,
* `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat
`,
* `result`, `round`, `runInContext`, `sample`, `shift`, `size`, `snakeCase`
,
* `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, `sortedLastInd
exBy`,
* `startCase`, `startsWith`, `subtract`, `sum`, sumBy`, `template`, `times`
,
* `toLower`, `toInteger`, `toLength`, `toNumber`, `toSafeInteger`, toString
`,
* `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqu
eId`,
* `upperCase`, `upperFirst`, `value`, and `words`
* *
* @name _ * @name _
* @constructor * @constructor
* @category Chain * @category Seq
* @param {*} value The value to wrap in a `lodash` instance. * @param {*} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns a `lodash` instance. * @returns {Object} Returns the new `lodash` wrapper instance.
* @example * @example
* *
* function square(n) {
* return n * n;
* }
*
* var wrapped = _([1, 2, 3]); * var wrapped = _([1, 2, 3]);
* *
* // returns an unwrapped value * // returns an unwrapped value
* wrapped.reduce(function(sum, n) { return sum + n; }); * wrapped.reduce(_.add);
* // => 6 * // => 6
* *
* // returns a wrapped value * // returns a wrapped value
* var squares = wrapped.map(function(n) { return n * n; }); * var squares = wrapped.map(square);
* *
* _.isArray(squares); * _.isArray(squares);
* // => false * // => false
* *
* _.isArray(squares.value()); * _.isArray(squares.value());
* // => true * // => true
*/ */
function lodash(value) { function lodash(value) {
if (isObjectLike(value) && !isArray(value)) { if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapp er)) {
if (value instanceof LodashWrapper) { if (value instanceof LodashWrapper) {
return value; return value;
} }
if (hasOwnProperty.call(value, '__wrapped__')) { if (hasOwnProperty.call(value, '__wrapped__')) {
return new LodashWrapper(value.__wrapped__, value.__chain__, arrayCopy (value.__actions__)); return wrapperClone(value);
} }
} }
return new LodashWrapper(value); return new LodashWrapper(value);
} }
/** /**
* The base constructor for creating `lodash` wrapper objects. * The function whose prototype all chaining wrappers inherit from.
* *
* @private * @private
* @param {*} value The value to wrap.
* @param {boolean} [chainAll] Enable chaining for all wrapper methods.
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped va
lue.
*/ */
function LodashWrapper(value, chainAll, actions) { function baseLodash() {
this.__actions__ = actions || []; // No operation performed.
this.__chain__ = !!chainAll;
this.__wrapped__ = value;
} }
/** /**
* An object environment feature flags. * The base constructor for creating `lodash` wrapper objects.
* *
* @static * @private
* @memberOf _ * @param {*} value The value to wrap.
* @type Object * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
*/ */
var support = lodash.support = {}; function LodashWrapper(value, chainAll) {
this.__wrapped__ = value;
(function(x) { this.__actions__ = [];
this.__chain__ = !!chainAll;
/** this.__index__ = 0;
* Detect if functions can be decompiled by `Function#toString` this.__values__ = undefined;
* (all but Firefox OS certified apps, older Opera mobile browsers, and }
* the PlayStation 3; forced `false` for Windows 8 apps).
*
* @memberOf _.support
* @type boolean
*/
support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInCon
text);
/**
* Detect if `Function#name` is supported (all but IE).
*
* @memberOf _.support
* @type boolean
*/
support.funcNames = typeof Function.name == 'string';
/**
* Detect if the DOM is supported.
*
* @memberOf _.support
* @type boolean
*/
try {
support.dom = document.createDocumentFragment().nodeType === 11;
} catch(e) {
support.dom = false;
}
/**
* Detect if `arguments` object indexes are non-enumerable.
*
* In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object
* indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat
* `arguments` object indexes as non-enumerable and fail `hasOwnProperty`
* checks for indexes that exceed their function's formal parameters with
* associated values of `0`.
*
* @memberOf _.support
* @type boolean
*/
try {
support.nonEnumArgs = !propertyIsEnumerable.call(arguments, 1);
} catch(e) {
support.nonEnumArgs = true;
}
}(0, 0));
/** /**
* By default, the template delimiters used by lodash are like those in * By default, the template delimiters used by lodash are like those in
* embedded Ruby (ERB). Change the following template settings to use * embedded Ruby (ERB). Change the following template settings to use
* alternative delimiters. * alternative delimiters.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Object * @type Object
*/ */
skipping to change at line 1020 skipping to change at line 1545
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/** /**
* Creates a lazy wrapper object which wraps `value` to enable lazy evaluati on. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluati on.
* *
* @private * @private
* @param {*} value The value to wrap. * @param {*} value The value to wrap.
*/ */
function LazyWrapper(value) { function LazyWrapper(value) {
this.actions = null; this.__wrapped__ = value;
this.dir = 1; this.__actions__ = [];
this.dropCount = 0; this.__dir__ = 1;
this.filtered = false; this.__filtered__ = false;
this.iteratees = null; this.__iteratees__ = [];
this.takeCount = POSITIVE_INFINITY; this.__takeCount__ = MAX_ARRAY_LENGTH;
this.views = null; this.__views__ = [];
this.wrapped = value;
} }
/** /**
* Creates a clone of the lazy wrapper object. * Creates a clone of the lazy wrapper object.
* *
* @private * @private
* @name clone * @name clone
* @memberOf LazyWrapper * @memberOf LazyWrapper
* @returns {Object} Returns the cloned `LazyWrapper` object. * @returns {Object} Returns the cloned `LazyWrapper` object.
*/ */
function lazyClone() { function lazyClone() {
var actions = this.actions, var result = new LazyWrapper(this.__wrapped__);
iteratees = this.iteratees, result.__actions__ = copyArray(this.__actions__);
views = this.views, result.__dir__ = this.__dir__;
result = new LazyWrapper(this.wrapped); result.__filtered__ = this.__filtered__;
result.__iteratees__ = copyArray(this.__iteratees__);
result.actions = actions ? arrayCopy(actions) : null; result.__takeCount__ = this.__takeCount__;
result.dir = this.dir; result.__views__ = copyArray(this.__views__);
result.dropCount = this.dropCount;
result.filtered = this.filtered;
result.iteratees = iteratees ? arrayCopy(iteratees) : null;
result.takeCount = this.takeCount;
result.views = views ? arrayCopy(views) : null;
return result; return result;
} }
/** /**
* Reverses the direction of lazy iteration. * Reverses the direction of lazy iteration.
* *
* @private * @private
* @name reverse * @name reverse
* @memberOf LazyWrapper * @memberOf LazyWrapper
* @returns {Object} Returns the new reversed `LazyWrapper` object. * @returns {Object} Returns the new reversed `LazyWrapper` object.
*/ */
function lazyReverse() { function lazyReverse() {
var filtered = this.filtered, if (this.__filtered__) {
result = filtered ? new LazyWrapper(this) : this.clone(); var result = new LazyWrapper(this);
result.__dir__ = -1;
result.dir = this.dir * -1; result.__filtered__ = true;
result.filtered = filtered; } else {
result = this.clone();
result.__dir__ *= -1;
}
return result; return result;
} }
/** /**
* Extracts the unwrapped value from its lazy wrapper. * Extracts the unwrapped value from its lazy wrapper.
* *
* @private * @private
* @name value * @name value
* @memberOf LazyWrapper * @memberOf LazyWrapper
* @returns {*} Returns the unwrapped value. * @returns {*} Returns the unwrapped value.
*/ */
function lazyValue() { function lazyValue() {
var array = this.wrapped.value(); var array = this.__wrapped__.value(),
if (!isArray(array)) { dir = this.__dir__,
return baseWrapperValue(array, this.actions); isArr = isArray(array),
}
var dir = this.dir,
isRight = dir < 0, isRight = dir < 0,
length = array.length, arrLength = isArr ? array.length : 0,
view = getView(0, length, this.views), view = getView(0, arrLength, this.__views__),
start = view.start, start = view.start,
end = view.end, end = view.end,
dropCount = this.dropCount, length = end - start,
takeCount = nativeMin(end - start, this.takeCount - dropCount), index = isRight ? end : (start - 1),
index = isRight ? end : start - 1, iteratees = this.__iteratees__,
iteratees = this.iteratees, iterLength = iteratees.length,
iterLength = iteratees ? iteratees.length : 0,
resIndex = 0, resIndex = 0,
result = []; takeCount = nativeMin(length, this.__takeCount__);
if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && take
Count == length)) {
return baseWrapperValue(array, this.__actions__);
}
var result = [];
outer: outer:
while (length-- && resIndex < takeCount) { while (length-- && resIndex < takeCount) {
index += dir; index += dir;
var iterIndex = -1, var iterIndex = -1,
value = array[index]; value = array[index];
while (++iterIndex < iterLength) { while (++iterIndex < iterLength) {
var data = iteratees[iterIndex], var data = iteratees[iterIndex],
iteratee = data.iteratee, iteratee = data.iteratee,
computed = iteratee(value, index, array), type = data.type,
type = data.type; computed = iteratee(value);
if (type == LAZY_MAP_FLAG) { if (type == LAZY_MAP_FLAG) {
value = computed; value = computed;
} else if (!computed) { } else if (!computed) {
if (type == LAZY_FILTER_FLAG) { if (type == LAZY_FILTER_FLAG) {
continue outer; continue outer;
} else { } else {
break outer; break outer;
} }
} }
} }
if (dropCount) { result[resIndex++] = value;
dropCount--;
} else {
result[resIndex++] = value;
}
} }
return isRight ? result.reverse() : result; return result;
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/** /**
* Creates a cache object to store key/value pairs. * Creates an hash object.
* *
* @private * @private
* @static * @returns {Object} Returns the new hash object.
* @name Cache */
* @memberOf _.memoize function Hash() {}
/**
* Removes `key` and its value from the hash.
*
* @private
* @param {Object} hash The hash to modify.
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function hashDelete(hash, key) {
return hashHas(hash, key) && delete hash[key];
}
/**
* Gets the hash value for `key`.
*
* @private
* @param {Object} hash The hash to query.
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/ */
function MapCache() { function hashGet(hash, key) {
this.__data__ = {}; if (nativeCreate) {
var result = hash[key];
return result === HASH_UNDEFINED ? undefined : result;
}
return hasOwnProperty.call(hash, key) ? hash[key] : undefined;
}
/**
* Checks if a hash value for `key` exists.
*
* @private
* @param {Object} hash The hash to query.
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `fal
se`.
*/
function hashHas(hash, key) {
return nativeCreate ? hash[key] !== undefined : hasOwnProperty.call(hash,
key);
} }
/** /**
* Removes `key` and its value from the cache. * Sets the hash `key` to `value`.
*
* @private
* @param {Object} hash The hash to modify.
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
*/
function hashSet(hash, key, value) {
hash[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value
;
}
/*------------------------------------------------------------------------*/
/**
* Creates a map cache object to store key-value pairs.
*
* @private
* @param {Array} [values] The values to cache.
*/
function MapCache(values) {
var index = -1,
length = values ? values.length : 0;
this.clear();
while (++index < length) {
var entry = values[index];
this.set(entry[0], entry[1]);
}
}
/**
* Removes all key-value entries from the map.
*
* @private
* @name clear
* @memberOf MapCache
*/
function mapClear() {
this.__data__ = { 'hash': new Hash, 'map': Map ? new Map : [], 'string': n
ew Hash };
}
/**
* Removes `key` and its value from the map.
* *
* @private * @private
* @name delete * @name delete
* @memberOf _.memoize.Cache * @memberOf MapCache
* @param {string} key The key of the value to remove. * @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed successfully, else `false`. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/ */
function mapDelete(key) { function mapDelete(key) {
return this.has(key) && delete this.__data__[key]; var data = this.__data__;
if (isKeyable(key)) {
return hashDelete(typeof key == 'string' ? data.string : data.hash, key)
;
}
return Map ? data.map['delete'](key) : assocDelete(data.map, key);
} }
/** /**
* Gets the cached value for `key`. * Gets the map value for `key`.
* *
* @private * @private
* @name get * @name get
* @memberOf _.memoize.Cache * @memberOf MapCache
* @param {string} key The key of the value to get. * @param {string} key The key of the value to get.
* @returns {*} Returns the cached value. * @returns {*} Returns the entry value.
*/ */
function mapGet(key) { function mapGet(key) {
return key == '__proto__' ? undefined : this.__data__[key]; var data = this.__data__;
if (isKeyable(key)) {
return hashGet(typeof key == 'string' ? data.string : data.hash, key);
}
return Map ? data.map.get(key) : assocGet(data.map, key);
} }
/** /**
* Checks if a cached value for `key` exists. * Checks if a map value for `key` exists.
* *
* @private * @private
* @name has * @name has
* @memberOf _.memoize.Cache * @memberOf MapCache
* @param {string} key The key of the entry to check. * @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `fal se`. * @returns {boolean} Returns `true` if an entry for `key` exists, else `fal se`.
*/ */
function mapHas(key) { function mapHas(key) {
return key != '__proto__' && hasOwnProperty.call(this.__data__, key); var data = this.__data__;
if (isKeyable(key)) {
return hashHas(typeof key == 'string' ? data.string : data.hash, key);
}
return Map ? data.map.has(key) : assocHas(data.map, key);
} }
/** /**
* Adds `value` to `key` of the cache. * Sets the map `key` to `value`.
* *
* @private * @private
* @name set * @name set
* @memberOf _.memoize.Cache * @memberOf MapCache
* @param {string} key The key of the value to cache. * @param {string} key The key of the value to set.
* @param {*} value The value to cache. * @param {*} value The value to set.
* @returns {Object} Returns the cache object. * @returns {Object} Returns the map cache object.
*/ */
function mapSet(key, value) { function mapSet(key, value) {
if (key != '__proto__') { var data = this.__data__;
this.__data__[key] = value; if (isKeyable(key)) {
hashSet(typeof key == 'string' ? data.string : data.hash, key, value);
} else if (Map) {
data.map.set(key, value);
} else {
assocSet(data.map, key, value);
} }
return this; return this;
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/** /**
* *
* Creates a cache object to store unique values. * Creates a set cache object to store unique values.
* *
* @private * @private
* @param {Array} [values] The values to cache. * @param {Array} [values] The values to cache.
*/ */
function SetCache(values) { function SetCache(values) {
var length = values ? values.length : 0; var index = -1,
length = values ? values.length : 0;
this.data = { 'hash': nativeCreate(null), 'set': new Set }; this.__data__ = new MapCache;
while (length--) { while (++index < length) {
this.push(values[length]); this.push(values[index]);
} }
} }
/** /**
* Checks if `value` is in `cache` mimicking the return signature of * Checks if `value` is in `cache`.
* `_.indexOf` by returning `0` if the value is found, else `-1`.
* *
* @private * @private
* @param {Object} cache The cache to search. * @param {Object} cache The set cache to search.
* @param {*} value The value to search for. * @param {*} value The value to search for.
* @returns {number} Returns `0` if `value` is found, else `-1`. * @returns {number} Returns `true` if `value` is found, else `false`.
*/ */
function cacheIndexOf(cache, value) { function cacheHas(cache, value) {
var data = cache.data, var map = cache.__data__;
result = (typeof value == 'string' || isObject(value)) ? data.set.has( if (isKeyable(value)) {
value) : data.hash[value]; var data = map.__data__,
hash = typeof value == 'string' ? data.string : data.hash;
return result ? 0 : -1; return hash[value] === HASH_UNDEFINED;
}
return map.has(value);
} }
/** /**
* Adds `value` to the cache. * Adds `value` to the set cache.
* *
* @private * @private
* @name push * @name push
* @memberOf SetCache * @memberOf SetCache
* @param {*} value The value to cache. * @param {*} value The value to cache.
*/ */
function cachePush(value) { function cachePush(value) {
var data = this.data; var map = this.__data__;
if (typeof value == 'string' || isObject(value)) { if (isKeyable(value)) {
data.set.add(value); var data = map.__data__,
} else { hash = typeof value == 'string' ? data.string : data.hash;
data.hash[value] = true;
hash[value] = HASH_UNDEFINED;
}
else {
map.set(value, HASH_UNDEFINED);
} }
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/** /**
* Copies the values of `source` to `array`. * Creates a stack cache object to store key-value pairs.
* *
* @private * @private
* @param {Array} source The array to copy values from. * @param {Array} [values] The values to cache.
* @param {Array} [array=[]] The array to copy values to.
* @returns {Array} Returns `array`.
*/ */
function arrayCopy(source, array) { function Stack(values) {
var index = -1, var index = -1,
length = source.length; length = values ? values.length : 0;
array || (array = Array(length)); this.clear();
while (++index < length) { while (++index < length) {
array[index] = source[index]; var entry = values[index];
this.set(entry[0], entry[1]);
} }
return array;
} }
/** /**
* A specialized version of `_.forEach` for arrays without support for callb * Removes all key-value entries from the stack.
ack
* shorthands or `this` binding.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @name clear
* @param {Function} iteratee The function invoked per iteration. * @memberOf Stack
* @returns {Array} Returns `array`.
*/ */
function arrayEach(array, iteratee) { function stackClear() {
var index = -1, this.__data__ = { 'array': [], 'map': null };
length = array.length;
while (++index < length) {
if (iteratee(array[index], index, array) === false) {
break;
}
}
return array;
} }
/** /**
* A specialized version of `_.forEachRight` for arrays without support for * Removes `key` and its value from the stack.
* callback shorthands or `this` binding.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @name delete
* @param {Function} iteratee The function invoked per iteration. * @memberOf Stack
* @returns {Array} Returns `array`. * @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/ */
function arrayEachRight(array, iteratee) { function stackDelete(key) {
var length = array.length; var data = this.__data__,
array = data.array;
while (length--) { return array ? assocDelete(array, key) : data.map['delete'](key);
if (iteratee(array[length], length, array) === false) {
break;
}
}
return array;
} }
/** /**
* A specialized version of `_.every` for arrays without support for callbac * Gets the stack value for `key`.
k
* shorthands or `this` binding.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @name get
* @param {Function} predicate The function invoked per iteration. * @memberOf Stack
* @returns {boolean} Returns `true` if all elements pass the predicate chec * @param {string} key The key of the value to get.
k, * @returns {*} Returns the entry value.
* else `false`.
*/ */
function arrayEvery(array, predicate) { function stackGet(key) {
var index = -1, var data = this.__data__,
length = array.length; array = data.array;
while (++index < length) { return array ? assocGet(array, key) : data.map.get(key);
if (!predicate(array[index], index, array)) {
return false;
}
}
return true;
} }
/** /**
* A specialized version of `_.filter` for arrays without support for callba * Checks if a stack value for `key` exists.
ck
* shorthands or `this` binding.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @name has
* @param {Function} predicate The function invoked per iteration. * @memberOf Stack
* @returns {Array} Returns the new filtered array. * @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `fal
se`.
*/ */
function arrayFilter(array, predicate) { function stackHas(key) {
var index = -1, var data = this.__data__,
length = array.length, array = data.array;
resIndex = -1,
result = [];
while (++index < length) { return array ? assocHas(array, key) : data.map.has(key);
var value = array[index];
if (predicate(value, index, array)) {
result[++resIndex] = value;
}
}
return result;
} }
/** /**
* A specialized version of `_.map` for arrays without support for callback * Sets the stack `key` to `value`.
* shorthands or `this` binding.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @name set
* @param {Function} iteratee The function invoked per iteration. * @memberOf Stack
* @returns {Array} Returns the new mapped array. * @param {string} key The key of the value to set.
*/ * @param {*} value The value to set.
function arrayMap(array, iteratee) { * @returns {Object} Returns the stack cache object.
var index = -1, */
length = array.length, function stackSet(key, value) {
result = Array(length); var data = this.__data__,
array = data.array;
while (++index < length) {
result[index] = iteratee(array[index], index, array); if (array) {
if (array.length < (LARGE_ARRAY_SIZE - 1)) {
assocSet(array, key, value);
} else {
data.array = null;
data.map = new MapCache(array);
}
} }
return result; var map = data.map;
if (map) {
map.set(key, value);
}
return this;
} }
/*------------------------------------------------------------------------*/
/** /**
* A specialized version of `_.max` for arrays without support for iteratees . * Removes `key` and its value from the associative array.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} array The array to query.
* @returns {*} Returns the maximum value. * @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/ */
function arrayMax(array) { function assocDelete(array, key) {
var index = -1, var index = assocIndexOf(array, key);
length = array.length, if (index < 0) {
result = NEGATIVE_INFINITY; return false;
while (++index < length) {
var value = array[index];
if (value > result) {
result = value;
}
} }
return result; var lastIndex = array.length - 1;
if (index == lastIndex) {
array.pop();
} else {
splice.call(array, index, 1);
}
return true;
} }
/** /**
* A specialized version of `_.min` for arrays without support for iteratees . * Gets the associative array value for `key`.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} array The array to query.
* @returns {*} Returns the minimum value. * @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/ */
function arrayMin(array) { function assocGet(array, key) {
var index = -1, var index = assocIndexOf(array, key);
length = array.length, return index < 0 ? undefined : array[index][1];
result = POSITIVE_INFINITY;
while (++index < length) {
var value = array[index];
if (value < result) {
result = value;
}
}
return result;
} }
/** /**
* A specialized version of `_.reduce` for arrays without support for callba * Checks if an associative array value for `key` exists.
ck
* shorthands or `this` binding.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} array The array to query.
* @param {Function} iteratee The function invoked per iteration. * @param {string} key The key of the entry to check.
* @param {*} [accumulator] The initial value. * @returns {boolean} Returns `true` if an entry for `key` exists, else `fal
* @param {boolean} [initFromArray] Specify using the first element of `arra se`.
y`
* as the initial value.
* @returns {*} Returns the accumulated value.
*/ */
function arrayReduce(array, iteratee, accumulator, initFromArray) { function assocHas(array, key) {
var index = -1, return assocIndexOf(array, key) > -1;
length = array.length;
if (initFromArray && length) {
accumulator = array[++index];
}
while (++index < length) {
accumulator = iteratee(accumulator, array[index], index, array);
}
return accumulator;
} }
/** /**
* A specialized version of `_.reduceRight` for arrays without support for * Gets the index at which the first occurrence of `key` is found in `array`
* callback shorthands or `this` binding. * of key-value pairs.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} array The array to search.
* @param {Function} iteratee The function invoked per iteration. * @param {*} key The key to search for.
* @param {*} [accumulator] The initial value. * @returns {number} Returns the index of the matched value, else `-1`.
* @param {boolean} [initFromArray] Specify using the last element of `array
`
* as the initial value.
* @returns {*} Returns the accumulated value.
*/ */
function arrayReduceRight(array, iteratee, accumulator, initFromArray) { function assocIndexOf(array, key) {
var length = array.length; var length = array.length;
if (initFromArray && length) {
accumulator = array[--length];
}
while (length--) { while (length--) {
accumulator = iteratee(accumulator, array[length], length, array); if (eq(array[length][0], key)) {
return length;
}
} }
return accumulator; return -1;
} }
/** /**
* A specialized version of `_.some` for arrays without support for callback * Sets the associative array `key` to `value`.
* shorthands or `this` binding.
* *
* @private * @private
* @param {Array} array The array to iterate over. * @param {Array} array The array to modify.
* @param {Function} predicate The function invoked per iteration. * @param {string} key The key of the value to set.
* @returns {boolean} Returns `true` if any element passes the predicate che * @param {*} value The value to set.
ck,
* else `false`.
*/ */
function arraySome(array, predicate) { function assocSet(array, key, value) {
var index = -1, var index = assocIndexOf(array, key);
length = array.length; if (index < 0) {
array.push([key, value]);
while (++index < length) { } else {
if (predicate(array[index], index, array)) { array[index][1] = value;
return true;
}
} }
return false;
} }
/** /*------------------------------------------------------------------------*/
* Used by `_.defaults` to customize its `_.assign` use.
*
* @private
* @param {*} objectValue The destination object property value.
* @param {*} sourceValue The source object property value.
* @returns {*} Returns the value to assign to the destination object.
*/
function assignDefaults(objectValue, sourceValue) {
return typeof objectValue == 'undefined' ? sourceValue : objectValue;
}
/** /**
* Used by `_.template` to customize its `_.assign` use. * Used by `_.defaults` to customize its `_.assignIn` use.
*
* **Note:** This method is like `assignDefaults` except that it ignores
* inherited property values when checking if a property is `undefined`.
* *
* @private * @private
* @param {*} objectValue The destination object property value. * @param {*} objValue The destination value.
* @param {*} sourceValue The source object property value. * @param {*} srcValue The source value.
* @param {string} key The key associated with the object and source values. * @param {string} key The key of the property to assign.
* @param {Object} object The destination object. * @param {Object} object The parent object of `objValue`.
* @returns {*} Returns the value to assign to the destination object. * @returns {*} Returns the value to assign.
*/ */
function assignOwnDefaults(objectValue, sourceValue, key, object) { function assignInDefaults(objValue, srcValue, key, object) {
return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, if (objValue === undefined ||
key)) (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key)))
? sourceValue {
: objectValue; return srcValue;
}
return objValue;
} }
/** /**
* The base implementation of `_.assign` without support for argument juggli * This function is like `assignValue` except that it doesn't assign `undefi
ng, ned` values.
* multiple sources, and `this` binding `customizer` functions.
* *
* @private * @private
* @param {Object} object The destination object. * @param {Object} object The object to modify.
* @param {Object} source The source object. * @param {string} key The key of the property to assign.
* @param {Function} [customizer] The function to customize assigning values * @param {*} value The value to assign.
.
* @returns {Object} Returns the destination object.
*/ */
function baseAssign(object, source, customizer) { function assignMergeValue(object, key, value) {
var props = keys(source); if ((value !== undefined && !eq(object[key], value)) ||
if (!customizer) { (typeof key == 'number' && value === undefined && !(key in object))) {
return baseCopy(source, object, props); object[key] = value;
}
var index = -1,
length = props.length
while (++index < length) {
var key = props[index],
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? result !== value : value === value) ||
(typeof value == 'undefined' && !(key in object))) {
object[key] = result;
}
} }
return object;
} }
/** /**
* The base implementation of `_.at` without support for strings and individ * Assigns `value` to `key` of `object` if the existing value is not equival
ual ent
* key arguments. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-s
amevaluezero)
* for equality comparisons.
* *
* @private * @private
* @param {Array|Object} collection The collection to iterate over. * @param {Object} object The object to modify.
* @param {number[]|string[]} [props] The property names or indexes of eleme * @param {string} key The key of the property to assign.
nts to pick. * @param {*} value The value to assign.
* @returns {Array} Returns the new array of picked elements.
*/ */
function baseAt(collection, props) { function assignValue(object, key, value) {
var index = -1, var objValue = object[key];
length = collection.length, if ((!eq(objValue, value) ||
isArr = isLength(length), (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key)
propsLength = props.length, )) ||
result = Array(propsLength); (value === undefined && !(key in object))) {
object[key] = value;
while(++index < propsLength) {
var key = props[index];
if (isArr) {
key = parseFloat(key);
result[index] = isIndex(key, length) ? collection[key] : undefined;
} else {
result[index] = collection[key];
}
} }
return result;
} }
/** /**
* Copies the properties of `source` to `object`. * The base implementation of `_.assign` without support for multiple source
s
* or `customizer` functions.
* *
* @private * @private
* @param {Object} source The object to copy properties from. * @param {Object} object The destination object.
* @param {Object} [object={}] The object to copy properties to. * @param {Object} source The source object.
* @param {Array} props The property names to copy.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
*/ */
function baseCopy(source, object, props) { function baseAssign(object, source) {
if (!props) { return object && copyObject(source, keys(source), object);
props = object;
object = {};
}
var index = -1,
length = props.length;
while (++index < length) {
var key = props[index];
object[key] = source[key];
}
return object;
} }
/** /**
* The base implementation of `_.bindAll` without support for individual * The base implementation of `_.at` without support for individual paths.
* method name arguments.
* *
* @private * @private
* @param {Object} object The object to bind and assign the bound methods to * @param {Object} object The object to iterate over.
. * @param {string[]} paths The property paths of elements to pick.
* @param {string[]} methodNames The object method names to bind. * @returns {Array} Returns the new array of picked elements.
* @returns {Object} Returns `object`.
*/ */
function baseBindAll(object, methodNames) { function baseAt(object, paths) {
var index = -1, var index = -1,
length = methodNames.length; isNil = object == null,
length = paths.length,
result = Array(length);
while (++index < length) { while (++index < length) {
var key = methodNames[index]; result[index] = isNil ? undefined : get(object, paths[index]);
object[key] = createWrapper(object[key], BIND_FLAG, object);
} }
return object; return result;
} }
/** /**
* The base implementation of `_.callback` which supports specifying the * The base implementation of `_.clamp` which doesn't coerce arguments to nu
* number of arguments to provide to `func`. mbers.
* *
* @private * @private
* @param {*} [func=_.identity] The value to convert to a callback. * @param {number} number The number to clamp.
* @param {*} [thisArg] The `this` binding of `func`. * @param {number} [lower] The lower bound.
* @param {number} [argCount] The number of arguments to provide to `func`. * @param {number} upper The upper bound.
* @returns {Function} Returns the callback. * @returns {number} Returns the clamped number.
*/ */
function baseCallback(func, thisArg, argCount) { function baseClamp(number, lower, upper) {
var type = typeof func; if (number === number) {
if (type == 'function') { if (upper !== undefined) {
return (typeof thisArg != 'undefined' && isBindable(func)) number = number <= upper ? number : upper;
? bindCallback(func, thisArg, argCount) }
: func; if (lower !== undefined) {
} number = number >= lower ? number : lower;
if (func == null) { }
return identity;
} }
// Handle "_.property" and "_.matches" style callback shorthands. return number;
return type == 'object'
? baseMatches(func, !argCount)
: baseProperty(argCount ? baseToString(func) : func);
} }
/** /**
* The base implementation of `_.clone` without support for argument jugglin * The base implementation of `_.clone` and `_.cloneDeep` which tracks
g * traversed objects.
* and `this` binding `customizer` functions.
* *
* @private * @private
* @param {*} value The value to clone. * @param {*} value The value to clone.
* @param {boolean} [isDeep] Specify a deep clone. * @param {boolean} [isDeep] Specify a deep clone.
* @param {Function} [customizer] The function to customize cloning values. * @param {Function} [customizer] The function to customize cloning.
* @param {string} [key] The key of `value`. * @param {string} [key] The key of `value`.
* @param {Object} [object] The object `value` belongs to. * @param {Object} [object] The parent object of `value`.
* @param {Array} [stackA=[]] Tracks traversed source objects. * @param {Object} [stack] Tracks traversed objects and their clone counterp
* @param {Array} [stackB=[]] Associates clones with source counterparts. arts.
* @returns {*} Returns the cloned value. * @returns {*} Returns the cloned value.
*/ */
function baseClone(value, isDeep, customizer, key, object, stackA, stackB) { function baseClone(value, isDeep, customizer, key, object, stack) {
var result; var result;
if (customizer) { if (customizer) {
result = object ? customizer(value, key, object) : customizer(value); result = object ? customizer(value, key, object, stack) : customizer(val ue);
} }
if (typeof result != 'undefined') { if (result !== undefined) {
return result; return result;
} }
if (!isObject(value)) { if (!isObject(value)) {
return value; return value;
} }
var isArr = isArray(value); var isArr = isArray(value);
if (isArr) { if (isArr) {
result = initCloneArray(value); result = initCloneArray(value);
if (!isDeep) { if (!isDeep) {
return arrayCopy(value, result); return copyArray(value, result);
} }
} else { } else {
var tag = objToString.call(value), var tag = getTag(value),
isFunc = tag == funcTag; isFunc = tag == funcTag || tag == genTag;
if (tag == objectTag || tag == argsTag || (isFunc && !object)) { if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
if (isHostObject(value)) {
return object ? value : {};
}
result = initCloneObject(isFunc ? {} : value); result = initCloneObject(isFunc ? {} : value);
if (!isDeep) { if (!isDeep) {
return baseCopy(value, result, keys(value)); return copySymbols(value, baseAssign(result, value));
} }
} else { } else {
return cloneableTags[tag] return cloneableTags[tag]
? initCloneByTag(value, tag, isDeep) ? initCloneByTag(value, tag, isDeep)
: (object ? value : {}); : (object ? value : {});
} }
} }
// Check for circular references and return corresponding clone. // Check for circular references and return its corresponding clone.
stackA || (stackA = []); stack || (stack = new Stack);
stackB || (stackB = []); var stacked = stack.get(value);
if (stacked) {
var length = stackA.length; return stacked;
while (length--) {
if (stackA[length] == value) {
return stackB[length];
}
} }
// Add the source value to the stack of traversed objects and associate it stack.set(value, result);
with its clone.
stackA.push(value);
stackB.push(result);
// Recursively populate clone (susceptible to call stack limits). // Recursively populate clone (susceptible to call stack limits).
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) { (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA , stackB); assignValue(result, key, baseClone(subValue, isDeep, customizer, key, va lue, stack));
}); });
return result; return isArr ? result : copySymbols(value, result);
}
/**
* The base implementation of `_.conforms` which doesn't clone `source`.
*
* @private
* @param {Object} source The object of property predicates to conform to.
* @returns {Function} Returns the new function.
*/
function baseConforms(source) {
var props = keys(source),
length = props.length;
return function(object) {
if (object == null) {
return !length;
}
var index = length;
while (index--) {
var key = props[index],
predicate = source[key],
value = object[key];
if ((value === undefined && !(key in Object(object))) || !predicate(va
lue)) {
return false;
}
}
return true;
};
} }
/** /**
* The base implementation of `_.create` without support for assigning * The base implementation of `_.create` without support for assigning
* properties to the created object. * properties to the created object.
* *
* @private * @private
* @param {Object} prototype The object to inherit from. * @param {Object} prototype The object to inherit from.
* @returns {Object} Returns the new object. * @returns {Object} Returns the new object.
*/ */
var baseCreate = (function() { var baseCreate = (function() {
function Object() {} function object() {}
return function(prototype) { return function(prototype) {
if (isObject(prototype)) { if (isObject(prototype)) {
Object.prototype = prototype; object.prototype = prototype;
var result = new Object; var result = new object;
Object.prototype = null; object.prototype = undefined;
} }
return result || context.Object(); return result || {};
}; };
}()); }());
/** /**
* The base implementation of `_.delay` and `_.defer` which accepts an index * The base implementation of `_.delay` and `_.defer` which accepts an array
* of where to slice the arguments to provide to `func`. * of `func` arguments.
* *
* @private * @private
* @param {Function} func The function to delay. * @param {Function} func The function to delay.
* @param {number} wait The number of milliseconds to delay invocation. * @param {number} wait The number of milliseconds to delay invocation.
* @param {Object} args The `arguments` object to slice and provide to `func `. * @param {Object} args The arguments provide to `func`.
* @returns {number} Returns the timer id. * @returns {number} Returns the timer id.
*/ */
function baseDelay(func, wait, args, fromIndex) { function baseDelay(func, wait, args) {
if (!isFunction(func)) { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
return setTimeout(function() { func.apply(undefined, baseSlice(args, fromI ndex)); }, wait); return setTimeout(function() { func.apply(undefined, args); }, wait);
} }
/** /**
* The base implementation of `_.difference` which accepts a single array * The base implementation of methods like `_.difference` without support fo
* of values to exclude. r
* excluding multiple arrays or iteratee shorthands.
* *
* @private * @private
* @param {Array} array The array to inspect. * @param {Array} array The array to inspect.
* @param {Array} values The values to exclude. * @param {Array} values The values to exclude.
* @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new array of filtered values. * @returns {Array} Returns the new array of filtered values.
*/ */
function baseDifference(array, values) { function baseDifference(array, values, iteratee, comparator) {
var length = array ? array.length : 0, var index = -1,
result = []; includes = arrayIncludes,
isCommon = true,
length = array.length,
result = [],
valuesLength = values.length;
if (!length) { if (!length) {
return result; return result;
} }
var index = -1, if (iteratee) {
indexOf = getIndexOf(), values = arrayMap(values, baseUnary(iteratee));
isCommon = indexOf == baseIndexOf, }
cache = isCommon && values.length >= 200 && createCache(values), if (comparator) {
valuesLength = values.length; includes = arrayIncludesWith;
isCommon = false;
if (cache) { }
indexOf = cacheIndexOf; else if (values.length >= LARGE_ARRAY_SIZE) {
includes = cacheHas;
isCommon = false; isCommon = false;
values = cache; values = new SetCache(values);
} }
outer: outer:
while (++index < length) { while (++index < length) {
var value = array[index]; var value = array[index],
computed = iteratee ? iteratee(value) : value;
if (isCommon && value === value) { if (isCommon && computed === computed) {
var valuesIndex = valuesLength; var valuesIndex = valuesLength;
while (valuesIndex--) { while (valuesIndex--) {
if (values[valuesIndex] === value) { if (values[valuesIndex] === computed) {
continue outer; continue outer;
} }
} }
result.push(value); result.push(value);
} }
else if (indexOf(values, value) < 0) { else if (!includes(values, computed, comparator)) {
result.push(value); result.push(value);
} }
} }
return result; return result;
} }
/** /**
* The base implementation of `_.forEach` without support for callback * The base implementation of `_.forEach` without support for iteratee short
* shorthands and `this` binding. hands.
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object|string} Returns `collection`. * @returns {Array|Object} Returns `collection`.
*/ */
function baseEach(collection, iteratee) { var baseEach = createBaseEach(baseForOwn);
var length = collection ? collection.length : 0;
if (!isLength(length)) {
return baseForOwn(collection, iteratee);
}
var index = -1,
iterable = toObject(collection);
while (++index < length) {
if (iteratee(iterable[index], index, iterable) === false) {
break;
}
}
return collection;
}
/** /**
* The base implementation of `_.forEachRight` without support for callback * The base implementation of `_.forEachRight` without support for iteratee
* shorthands and `this` binding. shorthands.
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object|string} Returns `collection`. * @returns {Array|Object} Returns `collection`.
*/ */
function baseEachRight(collection, iteratee) { var baseEachRight = createBaseEach(baseForOwnRight, true);
var length = collection ? collection.length : 0;
if (!isLength(length)) {
return baseForOwnRight(collection, iteratee);
}
var iterable = toObject(collection);
while (length--) {
if (iteratee(iterable[length], length, iterable) === false) {
break;
}
}
return collection;
}
/** /**
* The base implementation of `_.every` without support for callback * The base implementation of `_.every` without support for iteratee shortha
* shorthands or `this` binding. nds.
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration. * @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if all elements pass the predicate chec * @returns {boolean} Returns `true` if all elements pass the predicate chec
k, k, else `false`
* else `false`
*/ */
function baseEvery(collection, predicate) { function baseEvery(collection, predicate) {
var result = true; var result = true;
baseEach(collection, function(value, index, collection) { baseEach(collection, function(value, index, collection) {
result = !!predicate(value, index, collection); result = !!predicate(value, index, collection);
return result; return result;
}); });
return result; return result;
} }
/** /**
* The base implementation of `_.filter` without support for callback * The base implementation of `_.fill` without an iteratee call guard.
* shorthands or `this` binding.
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array} array The array to fill.
* @param {Function} predicate The function invoked per iteration. * @param {*} value The value to fill `array` with.
* @returns {Array} Returns the new filtered array. * @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns `array`.
*/ */
function baseFilter(collection, predicate) { function baseFill(array, value, start, end) {
var result = []; var length = array.length;
baseEach(collection, function(value, index, collection) {
if (predicate(value, index, collection)) { start = toInteger(start);
result.push(value); if (start < 0) {
} start = -start > length ? 0 : (length + start);
}); }
return result; end = (end === undefined || end > length) ? length : toInteger(end);
if (end < 0) {
end += length;
}
end = start > end ? 0 : toLength(end);
while (start < end) {
array[start++] = value;
}
return array;
} }
/** /**
* The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.fi * The base implementation of `_.filter` without support for iteratee shorth
ndLastKey`, ands.
* without support for callback shorthands and `this` binding, which iterate
s
* over `collection` using the provided `eachFunc`.
* *
* @private * @private
* @param {Array|Object|string} collection The collection to search. * @param {Array|Object} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration. * @param {Function} predicate The function invoked per iteration.
* @param {Function} eachFunc The function to iterate over `collection`. * @returns {Array} Returns the new filtered array.
* @param {boolean} [retKey] Specify returning the key of the found element
* instead of the element itself.
* @returns {*} Returns the found element or its key, else `undefined`.
*/ */
function baseFind(collection, predicate, eachFunc, retKey) { function baseFilter(collection, predicate) {
var result; var result = [];
eachFunc(collection, function(value, key, collection) { baseEach(collection, function(value, index, collection) {
if (predicate(value, key, collection)) { if (predicate(value, index, collection)) {
result = retKey ? key : value; result.push(value);
return false;
} }
}); });
return result; return result;
} }
/** /**
* The base implementation of `_.flatten` with added support for restricting * The base implementation of `_.flatten` with support for restricting flatt
* flattening and specifying the start index. ening.
* *
* @private * @private
* @param {Array} array The array to flatten. * @param {Array} array The array to flatten.
* @param {boolean} [isDeep] Specify a deep flatten. * @param {boolean} [isDeep] Specify a deep flatten.
* @param {boolean} [isStrict] Restrict flattening to arrays and `arguments` * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
objects. * @param {Array} [result=[]] The initial result value.
* @param {number} [fromIndex=0] The index to start from.
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
*/ */
function baseFlatten(array, isDeep, isStrict, fromIndex) { function baseFlatten(array, isDeep, isStrict, result) {
var index = (fromIndex || 0) - 1, result || (result = []);
length = array.length,
resIndex = -1, var index = -1,
result = []; length = array.length;
while (++index < length) { while (++index < length) {
var value = array[index]; var value = array[index];
if (isArrayLikeObject(value) &&
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || (isStrict || isArray(value) || isArguments(value))) {
isArguments(value))) {
if (isDeep) { if (isDeep) {
// Recursively flatten arrays (susceptible to call stack limits). // Recursively flatten arrays (susceptible to call stack limits).
value = baseFlatten(value, isDeep, isStrict); baseFlatten(value, isDeep, isStrict, result);
} } else {
var valIndex = -1, arrayPush(result, value);
valLength = value.length;
result.length += valLength;
while (++valIndex < valLength) {
result[++resIndex] = value[valIndex];
} }
} else if (!isStrict) { } else if (!isStrict) {
result[++resIndex] = value; result[result.length] = value;
} }
} }
return result; return result;
} }
/** /**
* The base implementation of `baseForIn` and `baseForOwn` which iterates * The base implementation of `baseForIn` and `baseForOwn` which iterates
* over `object` properties returned by `keysFunc` invoking `iteratee` for * over `object` properties returned by `keysFunc` invoking `iteratee` for
* each property. Iterator functions may exit iteration early by explicitly * each property. Iteratee functions may exit iteration early by explicitly
* returning `false`. * returning `false`.
* *
* @private * @private
* @param {Object} object The object to iterate over. * @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @param {Function} keysFunc The function to get the keys of `object`. * @param {Function} keysFunc The function to get the keys of `object`.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
*/ */
function baseFor(object, iteratee, keysFunc) { var baseFor = createBaseFor();
var index = -1,
iterable = toObject(object),
props = keysFunc(object),
length = props.length;
while (++index < length) {
var key = props[index];
if (iteratee(iterable[key], key, iterable) === false) {
break;
}
}
return object;
}
/** /**
* This function is like `baseFor` except that it iterates over properties * This function is like `baseFor` except that it iterates over properties
* in the opposite order. * in the opposite order.
* *
* @private * @private
* @param {Object} object The object to iterate over. * @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @param {Function} keysFunc The function to get the keys of `object`. * @param {Function} keysFunc The function to get the keys of `object`.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
*/ */
function baseForRight(object, iteratee, keysFunc) { var baseForRight = createBaseFor(true);
var iterable = toObject(object),
props = keysFunc(object),
length = props.length;
while (length--) {
var key = props[length];
if (iteratee(iterable[key], key, iterable) === false) {
break;
}
}
return object;
}
/** /**
* The base implementation of `_.forIn` without support for callback * The base implementation of `_.forIn` without support for iteratee shortha
* shorthands and `this` binding. nds.
* *
* @private * @private
* @param {Object} object The object to iterate over. * @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
*/ */
function baseForIn(object, iteratee) { function baseForIn(object, iteratee) {
return baseFor(object, iteratee, keysIn); return object == null ? object : baseFor(object, iteratee, keysIn);
} }
/** /**
* The base implementation of `_.forOwn` without support for callback * The base implementation of `_.forOwn` without support for iteratee shorth
* shorthands and `this` binding. ands.
* *
* @private * @private
* @param {Object} object The object to iterate over. * @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
*/ */
function baseForOwn(object, iteratee) { function baseForOwn(object, iteratee) {
return baseFor(object, iteratee, keys); return object && baseFor(object, iteratee, keys);
} }
/** /**
* The base implementation of `_.forOwnRight` without support for callback * The base implementation of `_.forOwnRight` without support for iteratee s
* shorthands and `this` binding. horthands.
* *
* @private * @private
* @param {Object} object The object to iterate over. * @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
*/ */
function baseForOwnRight(object, iteratee) { function baseForOwnRight(object, iteratee) {
return baseForRight(object, iteratee, keys); return object && baseForRight(object, iteratee, keys);
} }
/** /**
* The base implementation of `_.functions` which creates an array of * The base implementation of `_.functions` which creates an array of
* `object` function property names filtered from those provided. * `object` function property names filtered from those provided.
* *
* @private * @private
* @param {Object} object The object to inspect. * @param {Object} object The object to inspect.
* @param {Array} props The property names to filter. * @param {Array} props The property names to filter.
* @returns {Array} Returns the new array of filtered property names. * @returns {Array} Returns the new array of filtered property names.
*/ */
function baseFunctions(object, props) { function baseFunctions(object, props) {
var index = -1, return arrayFilter(props, function(key) {
length = props.length, return isFunction(object[key]);
resIndex = -1, });
}
/**
* The base implementation of `_.get` without support for default values.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @returns {*} Returns the resolved value.
*/
function baseGet(object, path) {
path = isKey(path, object) ? [path + ''] : baseToPath(path);
var index = 0,
length = path.length;
while (object != null && index < length) {
object = object[path[index++]];
}
return (index && index == length) ? object : undefined;
}
/**
* The base implementation of `_.has` without support for deep paths.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} key The key to check.
* @returns {boolean} Returns `true` if `key` exists, else `false`.
*/
function baseHas(object, key) {
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
// that are composed entirely of index properties, return `false` for
// `hasOwnProperty` checks of them.
return hasOwnProperty.call(object, key) ||
(typeof object == 'object' && key in object && getPrototypeOf(object) ==
= null);
}
/**
* The base implementation of `_.hasIn` without support for deep paths.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} key The key to check.
* @returns {boolean} Returns `true` if `key` exists, else `false`.
*/
function baseHasIn(object, key) {
return key in Object(object);
}
/**
* The base implementation of `_.inRange` which doesn't coerce arguments to
numbers.
*
* @private
* @param {number} number The number to check.
* @param {number} start The start of the range.
* @param {number} end The end of the range.
* @returns {boolean} Returns `true` if `number` is in the range, else `fals
e`.
*/
function baseInRange(number, start, end) {
return number >= nativeMin(start, end) && number < nativeMax(start, end);
}
/**
* The base implementation of methods like `_.intersection`, without support
* for iteratee shorthands, that accepts an array of arrays to inspect.
*
* @private
* @param {Array} arrays The arrays to inspect.
* @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new array of shared values.
*/
function baseIntersection(arrays, iteratee, comparator) {
var includes = comparator ? arrayIncludesWith : arrayIncludes,
othLength = arrays.length,
othIndex = othLength,
caches = Array(othLength),
result = []; result = [];
while (othIndex--) {
var array = arrays[othIndex];
if (othIndex && iteratee) {
array = arrayMap(array, baseUnary(iteratee));
}
caches[othIndex] = !comparator && (iteratee || array.length >= 120)
? new SetCache(othIndex && array)
: undefined;
}
array = arrays[0];
var index = -1,
length = array.length,
seen = caches[0];
outer:
while (++index < length) { while (++index < length) {
var key = props[index]; var value = array[index],
if (isFunction(object[key])) { computed = iteratee ? iteratee(value) : value;
result[++resIndex] = key;
if (!(seen ? cacheHas(seen, computed) : includes(result, computed, compa
rator))) {
var othIndex = othLength;
while (--othIndex) {
var cache = caches[othIndex];
if (!(cache ? cacheHas(cache, computed) : includes(arrays[othIndex],
computed, comparator))) {
continue outer;
}
}
if (seen) {
seen.push(computed);
}
result.push(value);
} }
} }
return result; return result;
} }
/** /**
* The base implementation of `_.invoke` which requires additional arguments * The base implementation of `_.invoke` without support for individual
* to be provided as an array of arguments rather than individually. * method arguments.
*
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {Object} object The object to query.
* @param {Function|string} methodName The name of the method to invoke or * @param {Array|string} path The path of the method to invoke.
* the function invoked per iteration. * @param {Array} args The arguments to invoke the method with.
* @param {Array} [args] The arguments to invoke the method with. * @returns {*} Returns the result of the invoked method.
* @returns {Array} Returns the array of results.
*/ */
function baseInvoke(collection, methodName, args) { function baseInvoke(object, path, args) {
var index = -1, if (!isKey(path, object)) {
isFunc = typeof methodName == 'function', path = baseToPath(path);
length = collection ? collection.length : 0, object = parent(object, path);
result = isLength(length) ? Array(length) : []; path = last(path);
}
baseEach(collection, function(value) { var func = object == null ? object : object[path];
var func = isFunc ? methodName : (value != null && value[methodName]); return func == null ? undefined : apply(func, object, args);
result[++index] = func ? func.apply(value, args) : undefined;
});
return result;
} }
/** /**
* The base implementation of `_.isEqual` without support for `this` binding * The base implementation of `_.isEqual` which supports partial comparisons
* `customizer` functions. * and tracks traversed objects.
* *
* @private * @private
* @param {*} value The value to compare. * @param {*} value The value to compare.
* @param {*} other The other value to compare. * @param {*} other The other value to compare.
* @param {Function} [customizer] The function to customize comparing values * @param {Function} [customizer] The function to customize comparisons.
. * @param {boolean} [bitmask] The bitmask of comparison flags.
* @param {boolean} [isWhere] Specify performing partial comparisons. * The bitmask may be composed of the following flags:
* @param {Array} [stackA] Tracks traversed `value` objects. * 1 - Unordered comparison
* @param {Array} [stackB] Tracks traversed `other` objects. * 2 - Partial comparison
* @param {Object} [stack] Tracks traversed `value` and `other` objects.
* @returns {boolean} Returns `true` if the values are equivalent, else `fal se`. * @returns {boolean} Returns `true` if the values are equivalent, else `fal se`.
*/ */
function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) { function baseIsEqual(value, other, customizer, bitmask, stack) {
// Exit early for identical values.
if (value === other) { if (value === other) {
// Treat `+0` vs. `-0` as not equal. return true;
return value !== 0 || (1 / value == 1 / other);
} }
var valType = typeof value, if (value == null || other == null || (!isObject(value) && !isObjectLike(o
othType = typeof other; ther))) {
// Exit early for unlike primitive values.
if ((valType != 'function' && valType != 'object' && othType != 'function'
&& othType != 'object') ||
value == null || other == null) {
// Return `false` unless both values are `NaN`.
return value !== value && other !== other; return value !== value && other !== other;
} }
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isWhere, sta ckA, stackB); return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, sta ck);
} }
/** /**
* A specialized version of `baseIsEqual` for arrays and objects which perfo rms * A specialized version of `baseIsEqual` for arrays and objects which perfo rms
* deep comparisons and tracks traversed objects enabling objects with circu lar * deep comparisons and tracks traversed objects enabling objects with circu lar
* references to be compared. * references to be compared.
* *
* @private * @private
* @param {Object} object The object to compare. * @param {Object} object The object to compare.
* @param {Object} other The other object to compare. * @param {Object} other The other object to compare.
* @param {Function} equalFunc The function to determine equivalents of valu es. * @param {Function} equalFunc The function to determine equivalents of valu es.
* @param {Function} [customizer] The function to customize comparing object * @param {Function} [customizer] The function to customize comparisons.
s. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqu
* @param {boolean} [isWhere] Specify performing partial comparisons. al` for more details.
* @param {Array} [stackA=[]] Tracks traversed `value` objects. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
* @param {Array} [stackB=[]] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `fa lse`. * @returns {boolean} Returns `true` if the objects are equivalent, else `fa lse`.
*/ */
function baseIsEqualDeep(object, other, equalFunc, customizer, isWhere, stac kA, stackB) { function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stac k) {
var objIsArr = isArray(object), var objIsArr = isArray(object),
othIsArr = isArray(other), othIsArr = isArray(other),
objTag = arrayTag, objTag = arrayTag,
othTag = arrayTag; othTag = arrayTag;
if (!objIsArr) { if (!objIsArr) {
objTag = objToString.call(object); objTag = getTag(object);
if (objTag == argsTag) { if (objTag == argsTag) {
objTag = objectTag; objTag = objectTag;
} else if (objTag != objectTag) { } else if (objTag != objectTag) {
objIsArr = isTypedArray(object); objIsArr = isTypedArray(object);
} }
} }
if (!othIsArr) { if (!othIsArr) {
othTag = objToString.call(other); othTag = getTag(other);
if (othTag == argsTag) { if (othTag == argsTag) {
othTag = objectTag; othTag = objectTag;
} else if (othTag != objectTag) { } else if (othTag != objectTag) {
othIsArr = isTypedArray(other); othIsArr = isTypedArray(other);
} }
} }
var objIsObj = objTag == objectTag, var objIsObj = objTag == objectTag && !isHostObject(object),
othIsObj = othTag == objectTag, othIsObj = othTag == objectTag && !isHostObject(other),
isSameTag = objTag == othTag; isSameTag = objTag == othTag;
if (isSameTag && !(objIsArr || objIsObj)) { if (isSameTag && !(objIsArr || objIsObj)) {
return equalByTag(object, other, objTag); return equalByTag(object, other, objTag, equalFunc, customizer, bitmask) ;
} }
var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); if (!isPartial) {
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'
),
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__')
;
if (valWrapped || othWrapped) { if (objIsWrapped || othIsWrapped) {
return equalFunc(valWrapped ? object.value() : object, othWrapped ? othe return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped
r.value() : other, customizer, isWhere, stackA, stackB); ? other.value() : other, customizer, bitmask, stack);
}
} }
if (!isSameTag) { if (!isSameTag) {
return false; return false;
} }
// Assume cyclic values are equal. stack || (stack = new Stack);
// For more information on detecting circular references see https://es5.g return (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, c
ithub.io/#JO. ustomizer, bitmask, stack);
stackA || (stackA = []);
stackB || (stackB = []);
var length = stackA.length;
while (length--) {
if (stackA[length] == object) {
return stackB[length] == other;
}
}
// Add `object` and `other` to the stack of traversed objects.
stackA.push(object);
stackB.push(other);
var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalF
unc, customizer, isWhere, stackA, stackB);
stackA.pop();
stackB.pop();
return result;
} }
/** /**
* The base implementation of `_.isMatch` without support for callback * The base implementation of `_.isMatch` without support for iteratee short
* shorthands or `this` binding. hands.
* *
* @private * @private
* @param {Object} source The object to inspect. * @param {Object} object The object to inspect.
* @param {Array} props The source property names to match. * @param {Object} source The object of property values to match.
* @param {Array} values The source values to match. * @param {Array} matchData The property names, values, and compare flags to
* @param {Array} strictCompareFlags Strict comparison flags for source valu match.
es. * @param {Function} [customizer] The function to customize comparisons.
* @param {Function} [customizer] The function to customize comparing object
s.
* @returns {boolean} Returns `true` if `object` is a match, else `false`. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/ */
function baseIsMatch(object, props, values, strictCompareFlags, customizer) function baseIsMatch(object, source, matchData, customizer) {
{ var index = matchData.length,
var length = props.length; length = index,
noCustomizer = !customizer;
if (object == null) { if (object == null) {
return !length; return !length;
} }
var index = -1, object = Object(object);
noCustomizer = !customizer; while (index--) {
var data = matchData[index];
while (++index < length) { if ((noCustomizer && data[2])
if ((noCustomizer && strictCompareFlags[index]) ? data[1] !== object[data[0]]
? values[index] !== object[props[index]] : !(data[0] in object)
: !hasOwnProperty.call(object, props[index])
) { ) {
return false; return false;
} }
} }
index = -1;
while (++index < length) { while (++index < length) {
var key = props[index]; data = matchData[index];
if (noCustomizer && strictCompareFlags[index]) { var key = data[0],
var result = hasOwnProperty.call(object, key); objValue = object[key],
srcValue = data[1];
if (noCustomizer && data[2]) {
if (objValue === undefined && !(key in object)) {
return false;
}
} else { } else {
var objValue = object[key], var stack = new Stack,
srcValue = values[index]; result = customizer ? customizer(objValue, srcValue, key, object,
source, stack) : undefined;
result = customizer ? customizer(objValue, srcValue, key) : undefined; if (!(result === undefined ? baseIsEqual(srcValue, objValue, customize
if (typeof result == 'undefined') { r, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) {
result = baseIsEqual(srcValue, objValue, customizer, true); return false;
} }
} }
if (!result) {
return false;
}
} }
return true; return true;
} }
/** /**
* The base implementation of `_.map` without support for callback shorthand * The base implementation of `_.iteratee`.
s
* or `this` binding.
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {*} [value=_.identity] The value to convert to an iteratee.
* @returns {Function} Returns the iteratee.
*/
function baseIteratee(value) {
var type = typeof value;
if (type == 'function') {
return value;
}
if (value == null) {
return identity;
}
if (type == 'object') {
return isArray(value)
? baseMatchesProperty(value[0], value[1])
: baseMatches(value);
}
return property(value);
}
/**
* The base implementation of `_.keys` which doesn't skip the constructor
* property of prototypes or treat sparse arrays as dense.
*
* @private
* @type Function
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function baseKeys(object) {
return nativeKeys(Object(object));
}
/**
* The base implementation of `_.keysIn` which doesn't skip the constructor
* property of prototypes or treat sparse arrays as dense.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function baseKeysIn(object) {
object = object == null ? object : Object(object);
var result = [];
for (var key in object) {
result.push(key);
}
return result;
}
// Fallback for IE < 9 with es6-shim.
if (enumerate && !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf')) {
baseKeysIn = function(object) {
return iteratorToArray(enumerate(object));
};
}
/**
* The base implementation of `_.map` without support for iteratee shorthand
s.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration. * @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array. * @returns {Array} Returns the new mapped array.
*/ */
function baseMap(collection, iteratee) { function baseMap(collection, iteratee) {
var result = []; var index = -1,
result = isArrayLike(collection) ? Array(collection.length) : [];
baseEach(collection, function(value, key, collection) { baseEach(collection, function(value, key, collection) {
result.push(iteratee(value, key, collection)); result[++index] = iteratee(value, key, collection);
}); });
return result; return result;
} }
/** /**
* The base implementation of `_.matches` which supports specifying whether * The base implementation of `_.matches` which doesn't clone `source`.
* `source` should be cloned.
* *
* @private * @private
* @param {Object} source The object of property values to match. * @param {Object} source The object of property values to match.
* @param {boolean} [isCloned] Specify cloning the source object.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new function.
*/ */
function baseMatches(source, isCloned) { function baseMatches(source) {
var props = keys(source), var matchData = getMatchData(source);
length = props.length; if (matchData.length == 1 && matchData[0][2]) {
var key = matchData[0][0],
if (length == 1) { value = matchData[0][1];
var key = props[0],
value = source[key]; return function(object) {
if (object == null) {
if (isStrictComparable(value)) { return false;
return function(object) { }
return object != null && value === object[key] && hasOwnProperty.cal return object[key] === value &&
l(object, key); (value !== undefined || (key in Object(object)));
}; };
}
}
if (isCloned) {
source = baseClone(source, true);
} }
var values = Array(length), return function(object) {
strictCompareFlags = Array(length); return object === source || baseIsMatch(object, source, matchData);
};
}
while (length--) { /**
value = source[props[length]]; * The base implementation of `_.matchesProperty` which doesn't clone `srcVa
values[length] = value; lue`.
strictCompareFlags[length] = isStrictComparable(value); *
} * @private
* @param {string} path The path of the property to get.
* @param {*} srcValue The value to match.
* @returns {Function} Returns the new function.
*/
function baseMatchesProperty(path, srcValue) {
return function(object) { return function(object) {
return baseIsMatch(object, props, values, strictCompareFlags); var objValue = get(object, path);
return (objValue === undefined && objValue === srcValue)
? hasIn(object, path)
: baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG |
PARTIAL_COMPARE_FLAG);
}; };
} }
/** /**
* The base implementation of `_.merge` without support for argument jugglin * The base implementation of `_.merge` without support for multiple sources
g, .
* multiple sources, and `this` binding `customizer` functions.
* *
* @private * @private
* @param {Object} object The destination object. * @param {Object} object The destination object.
* @param {Object} source The source object. * @param {Object} source The source object.
* @param {Function} [customizer] The function to customize merging properti * @param {Function} [customizer] The function to customize merged values.
es. * @param {Object} [stack] Tracks traversed source values and their merged c
* @param {Array} [stackA=[]] Tracks traversed source objects. ounterparts.
* @param {Array} [stackB=[]] Associates values with source counterparts. */
* @returns {Object} Returns the destination object. function baseMerge(object, source, customizer, stack) {
*/ if (object === source) {
function baseMerge(object, source, customizer, stackA, stackB) { return;
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray }
(source)); var props = (isArray(source) || isTypedArray(source)) ? undefined : keysIn
(source);
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source arrayEach(props || source, function(srcValue, key) {
) { if (props) {
if (isObjectLike(srcValue)) { key = srcValue;
stackA || (stackA = []); srcValue = source[key];
stackB || (stackB = []); }
return baseMergeDeep(object, source, key, baseMerge, customizer, stack if (isObject(srcValue)) {
A, stackB); stack || (stack = new Stack);
} baseMergeDeep(object, source, key, baseMerge, customizer, stack);
var value = object[key], }
result = customizer ? customizer(value, srcValue, key, object, sourc else {
e) : undefined, var newValue = customizer ? customizer(object[key], srcValue, (key + '
isCommon = typeof result == 'undefined'; '), object, source, stack) : undefined;
if (newValue === undefined) {
if (isCommon) { newValue = srcValue;
result = srcValue; }
} assignMergeValue(object, key, newValue);
if ((isSrcArr || typeof result != 'undefined') &&
(isCommon || (result === result ? result !== value : value === value
))) {
object[key] = result;
} }
}); });
return object;
} }
/** /**
* A specialized version of `baseMerge` for arrays and objects which perform s * A specialized version of `baseMerge` for arrays and objects which perform s
* deep merges and tracks traversed objects enabling objects with circular * deep merges and tracks traversed objects enabling objects with circular
* references to be merged. * references to be merged.
* *
* @private * @private
* @param {Object} object The destination object. * @param {Object} object The destination object.
* @param {Object} source The source object. * @param {Object} source The source object.
* @param {string} key The key of the value to merge. * @param {string} key The key of the value to merge.
* @param {Function} mergeFunc The function to merge values. * @param {Function} mergeFunc The function to merge values.
* @param {Function} [customizer] The function to customize merging properti * @param {Function} [customizer] The function to customize assigned values.
es. * @param {Object} [stack] Tracks traversed source values and their merged c
* @param {Array} [stackA=[]] Tracks traversed source objects. ounterparts.
* @param {Array} [stackB=[]] Associates values with source counterparts.
* @returns {boolean} Returns `true` if the objects are equivalent, else `fa
lse`.
*/ */
function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, s function baseMergeDeep(object, source, key, mergeFunc, customizer, stack) {
tackB) { var objValue = object[key],
var length = stackA.length, srcValue = source[key],
srcValue = source[key]; stacked = stack.get(srcValue) || stack.get(objValue);
while (length--) { if (stacked) {
if (stackA[length] == srcValue) { assignMergeValue(object, key, stacked);
object[key] = stackB[length]; return;
return;
}
} }
var value = object[key], var newValue = customizer ? customizer(objValue, srcValue, (key + ''), obj
result = customizer ? customizer(value, srcValue, key, object, source) ect, source, stack) : undefined,
: undefined, isCommon = newValue === undefined;
isCommon = typeof result == 'undefined';
if (isCommon) { if (isCommon) {
result = srcValue; newValue = srcValue;
if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcV if (isArray(srcValue) || isTypedArray(srcValue)) {
alue))) { newValue = isArray(objValue)
result = isArray(value) ? objValue
? value : ((isArrayLikeObject(objValue)) ? copyArray(objValue) : baseClone(s
: (value ? arrayCopy(value) : []); rcValue));
} }
else if (isPlainObject(srcValue) || isArguments(srcValue)) { else if (isPlainObject(srcValue) || isArguments(srcValue)) {
result = isArguments(value) newValue = isArguments(objValue)
? toPlainObject(value) ? toPlainObject(objValue)
: (isPlainObject(value) ? value : {}); : (isObject(objValue) ? objValue : baseClone(srcValue));
}
else {
isCommon = isFunction(srcValue);
} }
} }
// Add the source value to the stack of traversed objects and associate stack.set(srcValue, newValue);
// it with its merged value.
stackA.push(srcValue);
stackB.push(result);
if (isCommon) { if (isCommon) {
// Recursively merge objects and arrays (susceptible to call stack limit s). // Recursively merge objects and arrays (susceptible to call stack limit s).
object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB); mergeFunc(newValue, srcValue, customizer, stack);
} else if (result === result ? result !== value : value === value) {
object[key] = result;
} }
assignMergeValue(object, key, newValue);
}
/**
* The base implementation of `_.orderBy` without param guards.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
* @param {string[]} orders The sort orders of `iteratees`.
* @returns {Array} Returns the new sorted array.
*/
function baseOrderBy(collection, iteratees, orders) {
var index = -1,
toIteratee = getIteratee();
iteratees = arrayMap(iteratees.length ? iteratees : Array(1), function(ite
ratee) {
return toIteratee(iteratee);
});
var result = baseMap(collection, function(value, key, collection) {
var criteria = arrayMap(iteratees, function(iteratee) {
return iteratee(value);
});
return { 'criteria': criteria, 'index': ++index, 'value': value };
});
return baseSortBy(result, function(object, other) {
return compareMultiple(object, other, orders);
});
}
/**
* The base implementation of `_.pick` without support for individual
* property names.
*
* @private
* @param {Object} object The source object.
* @param {string[]} props The property names to pick.
* @returns {Object} Returns the new object.
*/
function basePick(object, props) {
object = Object(object);
return arrayReduce(props, function(result, key) {
if (key in object) {
result[key] = object[key];
}
return result;
}, {});
}
/**
* The base implementation of `_.pickBy` without support for iteratee short
hands.
*
* @private
* @param {Object} object The source object.
* @param {Function} predicate The function invoked per property.
* @returns {Object} Returns the new object.
*/
function basePickBy(object, predicate) {
var result = {};
baseForIn(object, function(value, key) {
if (predicate(value)) {
result[key] = value;
}
});
return result;
} }
/** /**
* The base implementation of `_.property` which does not coerce `key` to a string. * The base implementation of `_.property` without support for deep paths.
* *
* @private * @private
* @param {string} key The key of the property to get. * @param {string} key The key of the property to get.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new function.
*/ */
function baseProperty(key) { function baseProperty(key) {
return function(object) { return function(object) {
return object == null ? undefined : object[key]; return object == null ? undefined : object[key];
}; };
} }
/** /**
* A specialized version of `baseProperty` which supports deep paths.
*
* @private
* @param {Array|string} path The path of the property to get.
* @returns {Function} Returns the new function.
*/
function basePropertyDeep(path) {
return function(object) {
return baseGet(object, path);
};
}
/**
* The base implementation of `_.pullAll`.
*
* @private
* @param {Array} array The array to modify.
* @param {Array} values The values to remove.
* @returns {Array} Returns `array`.
*/
function basePullAll(array, values) {
return basePullAllBy(array, values);
}
/**
* The base implementation of `_.pullAllBy` without support for iteratee
* shorthands.
*
* @private
* @param {Array} array The array to modify.
* @param {Array} values The values to remove.
* @param {Function} [iteratee] The iteratee invoked per element.
* @returns {Array} Returns `array`.
*/
function basePullAllBy(array, values, iteratee) {
var index = -1,
length = values.length,
seen = array;
if (iteratee) {
seen = arrayMap(array, function(value) { return iteratee(value); });
}
while (++index < length) {
var fromIndex = 0,
value = values[index],
computed = iteratee ? iteratee(value) : value;
while ((fromIndex = baseIndexOf(seen, computed, fromIndex)) > -1) {
if (seen !== array) {
splice.call(seen, fromIndex, 1);
}
splice.call(array, fromIndex, 1);
}
}
return array;
}
/**
* The base implementation of `_.pullAt` without support for individual * The base implementation of `_.pullAt` without support for individual
* index arguments. * indexes or capturing the removed elements.
* *
* @private * @private
* @param {Array} array The array to modify. * @param {Array} array The array to modify.
* @param {number[]} indexes The indexes of elements to remove. * @param {number[]} indexes The indexes of elements to remove.
* @returns {Array} Returns the new array of removed elements. * @returns {Array} Returns `array`.
*/ */
function basePullAt(array, indexes) { function basePullAt(array, indexes) {
var length = indexes.length, var length = array ? indexes.length : 0,
result = baseAt(array, indexes); lastIndex = length - 1;
indexes.sort(baseCompareAscending);
while (length--) { while (length--) {
var index = parseFloat(indexes[length]); var index = indexes[length];
if (index != previous && isIndex(index)) { if (lastIndex == length || index != previous) {
var previous = index; var previous = index;
splice.call(array, index, 1); if (isIndex(index)) {
splice.call(array, index, 1);
}
else if (!isKey(index, array)) {
var path = baseToPath(index),
object = parent(array, path);
if (object != null) {
delete object[last(path)];
}
}
else {
delete array[index];
}
} }
} }
return result; return array;
} }
/** /**
* The base implementation of `_.random` without support for argument juggli * The base implementation of `_.random` without support for returning
ng * floating-point numbers.
* and returning floating-point numbers.
* *
* @private * @private
* @param {number} min The minimum possible value. * @param {number} lower The lower bound.
* @param {number} max The maximum possible value. * @param {number} upper The upper bound.
* @returns {number} Returns the random number. * @returns {number} Returns the random number.
*/ */
function baseRandom(min, max) { function baseRandom(lower, upper) {
return min + floor(nativeRandom() * (max - min + 1)); return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
} }
/** /**
* The base implementation of `_.reduce` and `_.reduceRight` without support * The base implementation of `_.range` and `_.rangeRight` which doesn't
* for callback shorthands or `this` binding, which iterates over `collectio * coerce arguments to numbers.
n`
* using the provided `eachFunc`.
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {number} start The start of the range.
* @param {Function} iteratee The function invoked per iteration. * @param {number} end The end of the range.
* @param {*} accumulator The initial value. * @param {number} step The value to increment or decrement by.
* @param {boolean} initFromCollection Specify using the first or last eleme * @param {boolean} [fromRight] Specify iterating from right to left.
nt * @returns {Array} Returns the new array of numbers.
* of `collection` as the initial value.
* @param {Function} eachFunc The function to iterate over `collection`.
* @returns {*} Returns the accumulated value.
*/ */
function baseReduce(collection, iteratee, accumulator, initFromCollection, e function baseRange(start, end, step, fromRight) {
achFunc) { var index = -1,
eachFunc(collection, function(value, index, collection) { length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
accumulator = initFromCollection result = Array(length);
? (initFromCollection = false, value)
: iteratee(accumulator, value, index, collection) while (length--) {
}); result[fromRight ? length : ++index] = start;
return accumulator; start += step;
}
return result;
}
/**
* The base implementation of `_.set`.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to set.
* @param {*} value The value to set.
* @param {Function} [customizer] The function to customize path creation.
* @returns {Object} Returns `object`.
*/
function baseSet(object, path, value, customizer) {
path = isKey(path, object) ? [path + ''] : baseToPath(path);
var index = -1,
length = path.length,
lastIndex = length - 1,
nested = object;
while (nested != null && ++index < length) {
var key = path[index];
if (isObject(nested)) {
var newValue = value;
if (index != lastIndex) {
var objValue = nested[key];
newValue = customizer ? customizer(objValue, key, nested) : undefine
d;
if (newValue === undefined) {
newValue = objValue == null ? (isIndex(path[index + 1]) ? [] : {})
: objValue;
}
}
assignValue(nested, key, newValue);
}
nested = nested[key];
}
return object;
} }
/** /**
* The base implementation of `setData` without support for hot loop detecti on. * The base implementation of `setData` without support for hot loop detecti on.
* *
* @private * @private
* @param {Function} func The function to associate metadata with. * @param {Function} func The function to associate metadata with.
* @param {*} data The metadata. * @param {*} data The metadata.
* @returns {Function} Returns `func`. * @returns {Function} Returns `func`.
*/ */
skipping to change at line 2491 skipping to change at line 3297
* @private * @private
* @param {Array} array The array to slice. * @param {Array} array The array to slice.
* @param {number} [start=0] The start position. * @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position. * @param {number} [end=array.length] The end position.
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
*/ */
function baseSlice(array, start, end) { function baseSlice(array, start, end) {
var index = -1, var index = -1,
length = array.length; length = array.length;
start = start == null ? 0 : (+start || 0);
if (start < 0) { if (start < 0) {
start = -start > length ? 0 : (length + start); start = -start > length ? 0 : (length + start);
} }
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0); end = end > length ? length : end;
if (end < 0) { if (end < 0) {
end += length; end += length;
} }
length = start > end ? 0 : (end - start); length = start > end ? 0 : ((end - start) >>> 0);
start >>>= 0;
var result = Array(length); var result = Array(length);
while (++index < length) { while (++index < length) {
result[index] = array[index + start]; result[index] = array[index + start];
} }
return result; return result;
} }
/** /**
* The base implementation of `_.some` without support for callback shorthan * The base implementation of `_.some` without support for iteratee shorthan
ds ds.
* or `this` binding.
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration. * @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate che * @returns {boolean} Returns `true` if any element passes the predicate che
ck, ck, else `false`.
* else `false`.
*/ */
function baseSome(collection, predicate) { function baseSome(collection, predicate) {
var result; var result;
baseEach(collection, function(value, index, collection) { baseEach(collection, function(value, index, collection) {
result = predicate(value, index, collection); result = predicate(value, index, collection);
return !result; return !result;
}); });
return !!result; return !!result;
} }
/** /**
* The base implementation of `_.uniq` without support for callback shorthan * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
ds * performs a binary search of `array` to determine the index at which `valu
* and `this` binding. e`
* should be inserted into `array` in order to maintain its sort order.
*
* @private
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @param {boolean} [retHighest] Specify returning the highest qualified ind
ex.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
*/
function baseSortedIndex(array, value, retHighest) {
var low = 0,
high = array ? array.length : low;
if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_
LENGTH) {
while (low < high) {
var mid = (low + high) >>> 1,
computed = array[mid];
if ((retHighest ? (computed <= value) : (computed < value)) && compute
d !== null) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
return baseSortedIndexBy(array, value, identity, retHighest);
}
/**
* The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
* which invokes `iteratee` for `value` and each element of `array` to compu
te
* their sort ranking. The iteratee is invoked with one argument; (value).
*
* @private
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @param {Function} iteratee The iteratee invoked per element.
* @param {boolean} [retHighest] Specify returning the highest qualified ind
ex.
* @returns {number} Returns the index at which `value` should be inserted i
nto `array`.
*/
function baseSortedIndexBy(array, value, iteratee, retHighest) {
value = iteratee(value);
var low = 0,
high = array ? array.length : 0,
valIsNaN = value !== value,
valIsNull = value === null,
valIsUndef = value === undefined;
while (low < high) {
var mid = nativeFloor((low + high) / 2),
computed = iteratee(array[mid]),
isDef = computed !== undefined,
isReflexive = computed === computed;
if (valIsNaN) {
var setLow = isReflexive || retHighest;
} else if (valIsNull) {
setLow = isReflexive && isDef && (retHighest || computed != null);
} else if (valIsUndef) {
setLow = isReflexive && (retHighest || isDef);
} else if (computed == null) {
setLow = false;
} else {
setLow = retHighest ? (computed <= value) : (computed < value);
}
if (setLow) {
low = mid + 1;
} else {
high = mid;
}
}
return nativeMin(high, MAX_ARRAY_INDEX);
}
/**
* The base implementation of `_.sortedUniq`.
*
* @private
* @param {Array} array The array to inspect.
* @returns {Array} Returns the new duplicate free array.
*/
function baseSortedUniq(array) {
return baseSortedUniqBy(array);
}
/**
* The base implementation of `_.sortedUniqBy` without support for iteratee
* shorthands.
*
* @private
* @param {Array} array The array to inspect.
* @param {Function} [iteratee] The iteratee invoked per element.
* @returns {Array} Returns the new duplicate free array.
*/
function baseSortedUniqBy(array, iteratee) {
var index = 0,
length = array.length,
value = array[0],
computed = iteratee ? iteratee(value) : value,
seen = computed,
resIndex = 0,
result = [value];
while (++index < length) {
value = array[index],
computed = iteratee ? iteratee(value) : value;
if (!eq(computed, seen)) {
seen = computed;
result[++resIndex] = value;
}
}
return result;
}
/**
* The base implementation of `_.toPath` which only converts `value` to a
* path if it's not one.
*
* @private
* @param {*} value The value to process.
* @returns {Array} Returns the property path array.
*/
function baseToPath(value) {
return isArray(value) ? value : stringToPath(value);
}
/**
* The base implementation of `_.uniqBy` without support for iteratee shorth
ands.
* *
* @private * @private
* @param {Array} array The array to inspect. * @param {Array} array The array to inspect.
* @param {Function} [iteratee] The function invoked per iteration. * @param {Function} [iteratee] The iteratee invoked per element.
* @returns {Array} Returns the new duplicate-value-free array. * @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new duplicate free array.
*/ */
function baseUniq(array, iteratee) { function baseUniq(array, iteratee, comparator) {
var index = -1, var index = -1,
indexOf = getIndexOf(), includes = arrayIncludes,
length = array.length, length = array.length,
isCommon = indexOf == baseIndexOf, isCommon = true,
isLarge = isCommon && length >= 200, result = [],
seen = isLarge && createCache(), seen = result;
result = [];
if (seen) { if (comparator) {
indexOf = cacheIndexOf;
isCommon = false; isCommon = false;
} else { includes = arrayIncludesWith;
isLarge = false; }
else if (length >= LARGE_ARRAY_SIZE) {
var set = iteratee ? null : createSet(array);
if (set) {
return setToArray(set);
}
isCommon = false;
includes = cacheHas;
seen = new SetCache;
}
else {
seen = iteratee ? [] : result; seen = iteratee ? [] : result;
} }
outer: outer:
while (++index < length) { while (++index < length) {
var value = array[index], var value = array[index],
computed = iteratee ? iteratee(value, index, array) : value; computed = iteratee ? iteratee(value) : value;
if (isCommon && value === value) { if (isCommon && computed === computed) {
var seenIndex = seen.length; var seenIndex = seen.length;
while (seenIndex--) { while (seenIndex--) {
if (seen[seenIndex] === computed) { if (seen[seenIndex] === computed) {
continue outer; continue outer;
} }
} }
if (iteratee) { if (iteratee) {
seen.push(computed); seen.push(computed);
} }
result.push(value); result.push(value);
} }
else if (indexOf(seen, computed) < 0) { else if (!includes(seen, computed, comparator)) {
if (iteratee || isLarge) { if (seen !== result) {
seen.push(computed); seen.push(computed);
} }
result.push(value); result.push(value);
} }
} }
return result; return result;
} }
/** /**
* The base implementation of `_.values` and `_.valuesIn` which creates an * The base implementation of `_.unset`.
* array of `object` property values corresponding to the property names
* returned by `keysFunc`.
* *
* @private * @private
* @param {Object} object The object to query. * @param {Object} object The object to modify.
* @param {Array} props The property names to get values for. * @param {Array|string} path The path of the property to unset.
* @returns {Object} Returns the array of property values. * @returns {boolean} Returns `true` if the property is deleted, else `false
`.
*/ */
function baseValues(object, props) { function baseUnset(object, path) {
var index = -1, path = isKey(path, object) ? [path + ''] : baseToPath(path);
length = props.length, object = parent(object, path);
result = Array(length); var key = last(path);
return (object != null && has(object, key)) ? delete object[key] : true;
}
while (++index < length) { /**
result[index] = object[props[index]]; * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
} * without support for iteratee shorthands.
return result; *
* @private
* @param {Array} array The array to query.
* @param {Function} predicate The function invoked per iteration.
* @param {boolean} [isDrop] Specify dropping elements instead of taking the
m.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Array} Returns the slice of `array`.
*/
function baseWhile(array, predicate, isDrop, fromRight) {
var length = array.length,
index = fromRight ? length : -1;
while ((fromRight ? index-- : ++index < length) &&
predicate(array[index], index, array)) {}
return isDrop
? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : len
gth))
: baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : in
dex));
} }
/** /**
* The base implementation of `wrapperValue` which returns the result of * The base implementation of `wrapperValue` which returns the result of
* performing a sequence of actions on the unwrapped `value`, where each * performing a sequence of actions on the unwrapped `value`, where each
* successive action is supplied the return value of the previous. * successive action is supplied the return value of the previous.
* *
* @private * @private
* @param {*} value The unwrapped value. * @param {*} value The unwrapped value.
* @param {Array} actions Actions to peform to resolve the unwrapped value. * @param {Array} actions Actions to perform to resolve the unwrapped value.
* @returns {*} Returns the resolved unwrapped value. * @returns {*} Returns the resolved value.
*/ */
function baseWrapperValue(value, actions) { function baseWrapperValue(value, actions) {
var result = value; var result = value;
if (result instanceof LazyWrapper) { if (result instanceof LazyWrapper) {
result = result.value(); result = result.value();
} }
return arrayReduce(actions, function(result, action) {
return action.func.apply(action.thisArg, arrayPush([result], action.args
));
}, result);
}
/**
* The base implementation of methods like `_.xor`, without support for
* iteratee shorthands, that accepts an array of arrays to inspect.
*
* @private
* @param {Array} arrays The arrays to inspect.
* @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new array of values.
*/
function baseXor(arrays, iteratee, comparator) {
var index = -1, var index = -1,
length = actions.length; length = arrays.length;
while (++index < length) { while (++index < length) {
var args = [result], var result = result
action = actions[index]; ? arrayPush(
baseDifference(result, arrays[index], iteratee, comparator),
push.apply(args, action.args); baseDifference(arrays[index], result, iteratee, comparator)
result = action.func.apply(action.thisArg, args); )
: arrays[index];
} }
return result; return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
} }
/** /**
* Performs a binary search of `array` to determine the index at which `valu * Creates a clone of `buffer`.
e`
* should be inserted into `array` in order to maintain its sort order.
* *
* @private * @private
* @param {Array} array The sorted array to inspect. * @param {ArrayBuffer} buffer The array buffer to clone.
* @param {*} value The value to evaluate. * @returns {ArrayBuffer} Returns the cloned array buffer.
* @param {boolean} [retHighest] Specify returning the highest, instead
* of the lowest, index at which a value should be inserted into `array`.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
*/ */
function binaryIndex(array, value, retHighest) { function cloneBuffer(buffer) {
var low = 0, var Ctor = buffer.constructor,
high = array ? array.length : low; result = new Ctor(buffer.byteLength),
view = new Uint8Array(result);
if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_
LENGTH) {
while (low < high) {
var mid = (low + high) >>> 1,
computed = array[mid];
if (retHighest ? (computed <= value) : (computed < value)) { view.set(new Uint8Array(buffer));
low = mid + 1; return result;
} else {
high = mid;
}
}
return high;
}
return binaryIndexBy(array, value, identity, retHighest);
} }
/** /**
* This function is like `binaryIndex` except that it invokes `iteratee` for * Creates a clone of `map`.
* `value` and each element of `array` to compute their sort ranking. The
* iteratee is invoked with one argument; (value).
* *
* @private * @private
* @param {Array} array The sorted array to inspect. * @param {Object} map The map to clone.
* @param {*} value The value to evaluate. * @returns {Object} Returns the cloned map.
* @param {Function} iteratee The function invoked per iteration.
* @param {boolean} [retHighest] Specify returning the highest, instead
* of the lowest, index at which a value should be inserted into `array`.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
*/ */
function binaryIndexBy(array, value, iteratee, retHighest) { function cloneMap(map) {
value = iteratee(value); var Ctor = map.constructor;
return arrayReduce(mapToArray(map), addMapEntry, new Ctor);
var low = 0, }
high = array ? array.length : 0,
valIsNaN = value !== value,
valIsUndef = typeof value == 'undefined';
while (low < high) { /**
var mid = floor((low + high) / 2), * Creates a clone of `regexp`.
computed = iteratee(array[mid]), *
isReflexive = computed === computed; * @private
* @param {Object} regexp The regexp to clone.
* @returns {Object} Returns the cloned regexp.
*/
function cloneRegExp(regexp) {
var Ctor = regexp.constructor,
result = new Ctor(regexp.source, reFlags.exec(regexp));
if (valIsNaN) { result.lastIndex = regexp.lastIndex;
var setLow = isReflexive || retHighest; return result;
} else if (valIsUndef) {
setLow = isReflexive && (retHighest || typeof computed != 'undefined')
;
} else {
setLow = retHighest ? (computed <= value) : (computed < value);
}
if (setLow) {
low = mid + 1;
} else {
high = mid;
}
}
return nativeMin(high, MAX_ARRAY_INDEX);
} }
/** /**
* A specialized version of `baseCallback` which only supports `this` bindin * Creates a clone of `set`.
g
* and specifying the number of arguments to provide to `func`.
* *
* @private * @private
* @param {Function} func The function to bind. * @param {Object} set The set to clone.
* @param {*} thisArg The `this` binding of `func`. * @returns {Object} Returns the cloned set.
* @param {number} [argCount] The number of arguments to provide to `func`.
* @returns {Function} Returns the callback.
*/ */
function bindCallback(func, thisArg, argCount) { function cloneSet(set) {
if (typeof func != 'function') { var Ctor = set.constructor;
return identity; return arrayReduce(setToArray(set), addSetEntry, new Ctor);
}
if (typeof thisArg == 'undefined') {
return func;
}
switch (argCount) {
case 1: return function(value) {
return func.call(thisArg, value);
};
case 3: return function(value, index, collection) {
return func.call(thisArg, value, index, collection);
};
case 4: return function(accumulator, value, index, collection) {
return func.call(thisArg, accumulator, value, index, collection);
};
case 5: return function(value, other, key, object, source) {
return func.call(thisArg, value, other, key, object, source);
};
}
return function() {
return func.apply(thisArg, arguments);
};
} }
/** /**
* Creates a clone of the given array buffer. * Creates a clone of the `symbol` object.
* *
* @private * @private
* @param {ArrayBuffer} buffer The array buffer to clone. * @param {Object} symbol The symbol object to clone.
* @returns {ArrayBuffer} Returns the cloned array buffer. * @returns {Object} Returns the cloned symbol object.
*/ */
function bufferClone(buffer) { function cloneSymbol(symbol) {
return bufferSlice.call(buffer, 0); return _Symbol ? Object(symbolValueOf.call(symbol)) : {};
} }
if (!bufferSlice) {
// PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array`. /**
bufferClone = !(ArrayBuffer && Uint8Array) ? constant(null) : function(buf * Creates a clone of `typedArray`.
fer) { *
var byteLength = buffer.byteLength, * @private
floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_EL * @param {Object} typedArray The typed array to clone.
EMENT) : 0, * @param {boolean} [isDeep] Specify a deep clone.
offset = floatLength * FLOAT64_BYTES_PER_ELEMENT, * @returns {Object} Returns the cloned typed array.
result = new ArrayBuffer(byteLength); */
function cloneTypedArray(typedArray, isDeep) {
if (floatLength) { var buffer = typedArray.buffer,
var view = new Float64Array(result, 0, floatLength); Ctor = typedArray.constructor;
view.set(new Float64Array(buffer, 0, floatLength));
} return new Ctor(isDeep ? cloneBuffer(buffer) : buffer, typedArray.byteOffs
if (byteLength != offset) { et, typedArray.length);
view = new Uint8Array(result, offset);
view.set(new Uint8Array(buffer, offset));
}
return result;
};
} }
/** /**
* Creates an array that is the composition of partially applied arguments, * Creates an array that is the composition of partially applied arguments,
* placeholders, and provided arguments into a single array of arguments. * placeholders, and provided arguments into a single array of arguments.
* *
* @private * @private
* @param {Array|Object} args The provided arguments. * @param {Array|Object} args The provided arguments.
* @param {Array} partials The arguments to prepend to those provided. * @param {Array} partials The arguments to prepend to those provided.
* @param {Array} holders The `partials` placeholder indexes. * @param {Array} holders The `partials` placeholder indexes.
* @returns {Array} Returns the new array of composed arguments. * @returns {Array} Returns the new array of composed arguments.
*/ */
function composeArgs(args, partials, holders) { function composeArgs(args, partials, holders) {
var holdersLength = holders.length, var holdersLength = holders.length,
argsIndex = -1, argsIndex = -1,
argsLength = nativeMax(args.length - holdersLength, 0), argsLength = nativeMax(args.length - holdersLength, 0),
leftIndex = -1, leftIndex = -1,
leftLength = partials.length, leftLength = partials.length,
result = Array(argsLength + leftLength); result = Array(leftLength + argsLength);
while (++leftIndex < leftLength) { while (++leftIndex < leftLength) {
result[leftIndex] = partials[leftIndex]; result[leftIndex] = partials[leftIndex];
} }
while (++argsIndex < holdersLength) { while (++argsIndex < holdersLength) {
result[holders[argsIndex]] = args[argsIndex]; result[holders[argsIndex]] = args[argsIndex];
} }
while (argsLength--) { while (argsLength--) {
result[leftIndex++] = args[argsIndex++]; result[leftIndex++] = args[argsIndex++];
} }
skipping to change at line 2822 skipping to change at line 3740
holdersLength = holders.length, holdersLength = holders.length,
argsIndex = -1, argsIndex = -1,
argsLength = nativeMax(args.length - holdersLength, 0), argsLength = nativeMax(args.length - holdersLength, 0),
rightIndex = -1, rightIndex = -1,
rightLength = partials.length, rightLength = partials.length,
result = Array(argsLength + rightLength); result = Array(argsLength + rightLength);
while (++argsIndex < argsLength) { while (++argsIndex < argsLength) {
result[argsIndex] = args[argsIndex]; result[argsIndex] = args[argsIndex];
} }
var pad = argsIndex; var offset = argsIndex;
while (++rightIndex < rightLength) { while (++rightIndex < rightLength) {
result[pad + rightIndex] = partials[rightIndex]; result[offset + rightIndex] = partials[rightIndex];
} }
while (++holdersIndex < holdersLength) { while (++holdersIndex < holdersLength) {
result[pad + holders[holdersIndex]] = args[argsIndex++]; result[offset + holders[holdersIndex]] = args[argsIndex++];
} }
return result; return result;
} }
/** /**
* Creates a function that aggregates a collection, creating an accumulator * Copies the values of `source` to `array`.
* object composed from the results of running each element in the collectio *
n * @private
* through an iteratee. The `setter` sets the keys and values of the accumul * @param {Array} source The array to copy values from.
ator * @param {Array} [array=[]] The array to copy values to.
* object. If `initializer` is provided initializes the accumulator object. * @returns {Array} Returns `array`.
*/
function copyArray(source, array) {
var index = -1,
length = source.length;
array || (array = Array(length));
while (++index < length) {
array[index] = source[index];
}
return array;
}
/**
* Copies properties of `source` to `object`.
*
* @private
* @param {Object} source The object to copy properties from.
* @param {Array} props The property names to copy.
* @param {Object} [object={}] The object to copy properties to.
* @returns {Object} Returns `object`.
*/
function copyObject(source, props, object) {
return copyObjectWith(source, props, object);
}
/**
* This function is like `copyObject` except that it accepts a function to
* customize copied values.
*
* @private
* @param {Object} source The object to copy properties from.
* @param {Array} props The property names to copy.
* @param {Object} [object={}] The object to copy properties to.
* @param {Function} [customizer] The function to customize copied values.
* @returns {Object} Returns `object`.
*/
function copyObjectWith(source, props, object, customizer) {
object || (object = {});
var index = -1,
length = props.length;
while (++index < length) {
var key = props[index],
newValue = customizer ? customizer(object[key], source[key], key, ob
ject, source) : source[key];
assignValue(object, key, newValue);
}
return object;
}
/**
* Copies own symbol properties of `source` to `object`.
*
* @private
* @param {Object} source The object to copy symbols from.
* @param {Object} [object={}] The object to copy symbols to.
* @returns {Object} Returns `object`.
*/
function copySymbols(source, object) {
return copyObject(source, getSymbols(source), object);
}
/**
* Creates a function like `_.groupBy`.
* *
* @private * @private
* @param {Function} setter The function to set keys and values of the accum ulator object. * @param {Function} setter The function to set keys and values of the accum ulator object.
* @param {Function} [initializer] The function to initialize the accumulato r object. * @param {Function} [initializer] The function to initialize the accumulato r object.
* @returns {Function} Returns the new aggregator function. * @returns {Function} Returns the new aggregator function.
*/ */
function createAggregator(setter, initializer) { function createAggregator(setter, initializer) {
return function(collection, iteratee, thisArg) { return function(collection, iteratee) {
var result = initializer ? initializer() : {}; var result = initializer ? initializer() : {};
iteratee = getCallback(iteratee, thisArg, 3); iteratee = getIteratee(iteratee);
if (isArray(collection)) { if (isArray(collection)) {
var index = -1, var index = -1,
length = collection.length; length = collection.length;
while (++index < length) { while (++index < length) {
var value = collection[index]; var value = collection[index];
setter(result, value, iteratee(value, index, collection), collection ); setter(result, value, iteratee(value), collection);
} }
} else { } else {
baseEach(collection, function(value, key, collection) { baseEach(collection, function(value, key, collection) {
setter(result, value, iteratee(value, key, collection), collection); setter(result, value, iteratee(value), collection);
}); });
} }
return result; return result;
}; };
} }
/** /**
* Creates a function that assigns properties of source object(s) to a given * Creates a function like `_.assign`.
* destination object.
* *
* @private * @private
* @param {Function} assigner The function to assign values. * @param {Function} assigner The function to assign values.
* @returns {Function} Returns the new assigner function. * @returns {Function} Returns the new assigner function.
*/ */
function createAssigner(assigner) { function createAssigner(assigner) {
return function() { return rest(function(object, sources) {
var length = arguments.length, var index = -1,
object = arguments[0]; length = sources.length,
customizer = length > 1 ? sources[length - 1] : undefined,
if (length < 2 || object == null) { guard = length > 2 ? sources[2] : undefined;
return object;
} customizer = typeof customizer == 'function' ? (length--, customizer) :
if (length > 3 && isIterateeCall(arguments[1], arguments[2], arguments[3 undefined;
])) { if (guard && isIterateeCall(sources[0], sources[1], guard)) {
length = 2; customizer = length < 3 ? undefined : customizer;
} length = 1;
// Juggle arguments.
if (length > 3 && typeof arguments[length - 2] == 'function') {
var customizer = bindCallback(arguments[--length - 1], arguments[lengt
h--], 5);
} else if (length > 2 && typeof arguments[length - 1] == 'function') {
customizer = arguments[--length];
} }
var index = 0; object = Object(object);
while (++index < length) { while (++index < length) {
var source = arguments[index]; var source = sources[index];
if (source) { if (source) {
assigner(object, source, customizer); assigner(object, source, customizer);
} }
} }
return object; return object;
});
}
/**
* Creates a `baseEach` or `baseEachRight` function.
*
* @private
* @param {Function} eachFunc The function to iterate over a collection.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new base function.
*/
function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) {
if (collection == null) {
return collection;
}
if (!isArrayLike(collection)) {
return eachFunc(collection, iteratee);
}
var length = collection.length,
index = fromRight ? length : -1,
iterable = Object(collection);
while ((fromRight ? index-- : ++index < length)) {
if (iteratee(iterable[index], index, iterable) === false) {
break;
}
}
return collection;
};
}
/**
* Creates a base function for methods like `_.forIn`.
*
* @private
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new base function.
*/
function createBaseFor(fromRight) {
return function(object, iteratee, keysFunc) {
var index = -1,
iterable = Object(object),
props = keysFunc(object),
length = props.length;
while (length--) {
var key = props[fromRight ? length : ++index];
if (iteratee(iterable[key], key, iterable) === false) {
break;
}
}
return object;
}; };
} }
/** /**
* Creates a function that wraps `func` and invokes it with the `this` * Creates a function that wraps `func` to invoke it with the optional `this `
* binding of `thisArg`. * binding of `thisArg`.
* *
* @private * @private
* @param {Function} func The function to bind. * @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
for more details.
* @param {*} [thisArg] The `this` binding of `func`. * @param {*} [thisArg] The `this` binding of `func`.
* @returns {Function} Returns the new bound function. * @returns {Function} Returns the new wrapped function.
*/ */
function createBindWrapper(func, thisArg) { function createBaseWrapper(func, bitmask, thisArg) {
var Ctor = createCtorWrapper(func); var isBind = bitmask & BIND_FLAG,
Ctor = createCtorWrapper(func);
function wrapper() { function wrapper() {
return (this instanceof wrapper ? Ctor : func).apply(thisArg, arguments) var fn = (this && this !== root && this instanceof wrapper) ? Ctor : fun
; c;
return fn.apply(isBind ? thisArg : this, arguments);
} }
return wrapper; return wrapper;
} }
/** /**
* Creates a `Set` cache object to optimize linear searches of large arrays. * Creates a function like `_.lowerFirst`.
* *
* @private * @private
* @param {Array} [values] The values to cache. * @param {string} methodName The name of the `String` case method to use.
* @returns {null|Object} Returns the new cache object if `Set` is supported * @returns {Function} Returns the new function.
, else `null`.
*/ */
var createCache = !(nativeCreate && Set) ? constant(null) : function(values) function createCaseFirst(methodName) {
{ return function(string) {
return new SetCache(values); string = toString(string);
};
var strSymbols = reHasComplexSymbol.test(string) ? stringToArray(string)
: undefined,
chr = strSymbols ? strSymbols[0] : string.charAt(0),
trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(
1);
return chr[methodName]() + trailing;
};
}
/** /**
* Creates a function that produces compound words out of the words in a * Creates a function like `_.camelCase`.
* given string.
* *
* @private * @private
* @param {Function} callback The function to combine each word. * @param {Function} callback The function to combine each word.
* @returns {Function} Returns the new compounder function. * @returns {Function} Returns the new compounder function.
*/ */
function createCompounder(callback) { function createCompounder(callback) {
return function(string) { return function(string) {
var index = -1, return arrayReduce(words(deburr(string)), callback, '');
array = words(deburr(string)),
length = array.length,
result = '';
while (++index < length) {
result = callback(result, array[index], index);
}
return result;
}; };
} }
/** /**
* Creates a function that produces an instance of `Ctor` regardless of * Creates a function that produces an instance of `Ctor` regardless of
* whether it was invoked as part of a `new` expression or by `call` or `app ly`. * whether it was invoked as part of a `new` expression or by `call` or `app ly`.
* *
* @private * @private
* @param {Function} Ctor The constructor to wrap. * @param {Function} Ctor The constructor to wrap.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createCtorWrapper(Ctor) { function createCtorWrapper(Ctor) {
return function() { return function() {
// Use a `switch` statement to work with class constructors.
// See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-functi
on-objects-call-thisargument-argumentslist
// for more details.
var args = arguments;
switch (args.length) {
case 0: return new Ctor;
case 1: return new Ctor(args[0]);
case 2: return new Ctor(args[0], args[1]);
case 3: return new Ctor(args[0], args[1], args[2]);
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], a
rgs[5]);
case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], a
rgs[5], args[6]);
}
var thisBinding = baseCreate(Ctor.prototype), var thisBinding = baseCreate(Ctor.prototype),
result = Ctor.apply(thisBinding, arguments); result = Ctor.apply(thisBinding, args);
// Mimic the constructor's `return` behavior. // Mimic the constructor's `return` behavior.
// See https://es5.github.io/#x13.2.2 for more details. // See https://es5.github.io/#x13.2.2 for more details.
return isObject(result) ? result : thisBinding; return isObject(result) ? result : thisBinding;
}; };
} }
/** /**
* Creates a function that gets the extremum value of a collection. * Creates a function that wraps `func` to enable currying.
*
* @private
* @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
for more details.
* @param {number} arity The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createCurryWrapper(func, bitmask, arity) {
var Ctor = createCtorWrapper(func);
function wrapper() {
var length = arguments.length,
index = length,
args = Array(length),
fn = (this && this !== root && this instanceof wrapper) ? Ctor : fun
c,
placeholder = wrapper.placeholder;
while (index--) {
args[index] = arguments[index];
}
var holders = (length < 3 && args[0] !== placeholder && args[length - 1]
!== placeholder)
? []
: replaceHolders(args, placeholder);
length -= holders.length;
return length < arity
? createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder
, undefined, args, holders, undefined, undefined, arity - length)
: apply(fn, this, args);
}
return wrapper;
}
/**
* Creates a `_.flow` or `_.flowRight` function.
* *
* @private * @private
* @param {Function} arrayFunc The function to get the extremum value from a * @param {boolean} [fromRight] Specify iterating from right to left.
n array. * @returns {Function} Returns the new flow function.
* @param {boolean} [isMin] Specify returning the minimum, instead of the ma */
ximum, function createFlow(fromRight) {
* extremum value. return rest(function(funcs) {
* @returns {Function} Returns the new extremum function. funcs = baseFlatten(funcs);
*/
function createExtremum(arrayFunc, isMin) { var length = funcs.length,
return function(collection, iteratee, thisArg) { index = length,
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { prereq = LodashWrapper.prototype.thru;
iteratee = null;
} if (fromRight) {
var func = getCallback(), funcs.reverse();
noIteratee = iteratee == null; }
while (index--) {
if (!(func === baseCallback && noIteratee)) { var func = funcs[index];
noIteratee = false; if (typeof func != 'function') {
iteratee = func(iteratee, thisArg, 3); throw new TypeError(FUNC_ERROR_TEXT);
} }
if (noIteratee) { if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
var isArr = isArray(collection); var wrapper = new LodashWrapper([], true);
if (!isArr && isString(collection)) { }
iteratee = charAtCallback; }
index = wrapper ? index : length;
while (++index < length) {
func = funcs[index];
var funcName = getFuncName(func),
data = funcName == 'wrapper' ? getData(func) : undefined;
if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG |
PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
} else { } else {
return arrayFunc(isArr ? collection : toIterable(collection)); wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName] () : wrapper.thru(func);
} }
} }
return extremumBy(collection, iteratee, isMin); return function() {
}; var args = arguments,
value = args[0];
if (wrapper && args.length == 1 && isArray(value) && value.length >= L
ARGE_ARRAY_SIZE) {
return wrapper.plant(value).value();
}
var index = 0,
result = length ? funcs[index].apply(this, args) : value;
while (++index < length) {
result = funcs[index].call(this, result);
}
return result;
};
});
} }
/** /**
* Creates a function that wraps `func` and invokes it with optional `this` * Creates a function that wraps `func` to invoke it with optional `this`
* binding of, partial application, and currying. * binding of `thisArg`, partial application, and currying.
* *
* @private * @private
* @param {Function|string} func The function or method name to reference. * @param {Function|string} func The function or method name to wrap.
* @param {number} bitmask The bitmask of flags. See `createWrapper` for mor * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
e details. for more details.
* @param {*} [thisArg] The `this` binding of `func`. * @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to prepend to those provided to t he new function. * @param {Array} [partials] The arguments to prepend to those provided to t he new function.
* @param {Array} [holders] The `partials` placeholder indexes. * @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [partialsRight] The arguments to append to those provided to the new function. * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
* @param {Array} [holdersRight] The `partialsRight` placeholder indexes. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function. * @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`. * @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`. * @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createHybridWrapper(func, bitmask, thisArg, partials, holders, part ialsRight, holdersRight, argPos, ary, arity) { function createHybridWrapper(func, bitmask, thisArg, partials, holders, part ialsRight, holdersRight, argPos, ary, arity) {
var isAry = bitmask & ARY_FLAG, var isAry = bitmask & ARY_FLAG,
isBind = bitmask & BIND_FLAG, isBind = bitmask & BIND_FLAG,
isBindKey = bitmask & BIND_KEY_FLAG, isBindKey = bitmask & BIND_KEY_FLAG,
isCurry = bitmask & CURRY_FLAG, isCurry = bitmask & CURRY_FLAG,
isCurryBound = bitmask & CURRY_BOUND_FLAG, isCurryRight = bitmask & CURRY_RIGHT_FLAG,
isCurryRight = bitmask & CURRY_RIGHT_FLAG; isFlip = bitmask & FLIP_FLAG,
Ctor = isBindKey ? undefined : createCtorWrapper(func);
var Ctor = !isBindKey && createCtorWrapper(func),
key = func;
function wrapper() { function wrapper() {
// Avoid `arguments` object use disqualifying optimizations by
// converting it to an array before providing it to other functions.
var length = arguments.length, var length = arguments.length,
index = length, index = length,
args = Array(length); args = Array(length);
while (index--) { while (index--) {
args[index] = arguments[index]; args[index] = arguments[index];
} }
if (partials) { if (partials) {
args = composeArgs(args, partials, holders); args = composeArgs(args, partials, holders);
} }
if (partialsRight) { if (partialsRight) {
args = composeArgsRight(args, partialsRight, holdersRight); args = composeArgsRight(args, partialsRight, holdersRight);
} }
if (isCurry || isCurryRight) { if (isCurry || isCurryRight) {
var placeholder = wrapper.placeholder, var placeholder = wrapper.placeholder,
argsHolders = replaceHolders(args, placeholder); argsHolders = replaceHolders(args, placeholder);
length -= argsHolders.length; length -= argsHolders.length;
if (length < arity) { if (length < arity) {
var newArgPos = argPos ? arrayCopy(argPos) : null, return createRecurryWrapper(func, bitmask, createHybridWrapper, plac
newArity = nativeMax(arity - length, 0), eholder, thisArg, args, argsHolders, argPos, ary, arity - length);
newsHolders = isCurry ? argsHolders : null,
newHoldersRight = isCurry ? null : argsHolders,
newPartials = isCurry ? args : null,
newPartialsRight = isCurry ? null : args;
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
if (!isCurryBound) {
bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
}
var result = createHybridWrapper(func, bitmask, thisArg, newPartials
, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity);
result.placeholder = placeholder;
return result;
} }
} }
var thisBinding = isBind ? thisArg : this; var thisBinding = isBind ? thisArg : this,
if (isBindKey) { fn = isBindKey ? thisBinding[func] : func;
func = thisBinding[key];
}
if (argPos) { if (argPos) {
args = reorder(args, argPos); args = reorder(args, argPos);
} else if (isFlip && args.length > 1) {
args.reverse();
} }
if (isAry && ary < args.length) { if (isAry && ary < args.length) {
args.length = ary; args.length = ary;
} }
return (this instanceof wrapper ? (Ctor || createCtorWrapper(func)) : fu if (this && this !== root && this instanceof wrapper) {
nc).apply(thisBinding, args); fn = Ctor || createCtorWrapper(fn);
}
return fn.apply(thisBinding, args);
} }
return wrapper; return wrapper;
} }
/** /**
* Creates the pad required for `string` based on the given padding length. * Creates a function like `_.over`.
* The `chars` string may be truncated if the number of padding characters *
* exceeds the padding length. * @private
* @param {Function} arrayFunc The function to iterate over iteratees.
* @returns {Function} Returns the new invoker function.
*/
function createOver(arrayFunc) {
return rest(function(iteratees) {
iteratees = arrayMap(baseFlatten(iteratees), getIteratee());
return rest(function(args) {
var thisArg = this;
return arrayFunc(iteratees, function(iteratee) {
return apply(iteratee, thisArg, args);
});
});
});
}
/**
* Creates the padding for `string` based on `length`. The `chars` string
* is truncated if the number of characters exceeds `length`.
* *
* @private * @private
* @param {string} string The string to create padding for. * @param {string} string The string to create padding for.
* @param {number} [length=0] The padding length. * @param {number} [length=0] The padding length.
* @param {string} [chars=' '] The string used as padding. * @param {string} [chars=' '] The string used as padding.
* @returns {string} Returns the pad for `string`. * @returns {string} Returns the padding for `string`.
*/ */
function createPad(string, length, chars) { function createPadding(string, length, chars) {
var strLength = string.length; length = toInteger(length);
length = +length;
if (strLength >= length || !nativeIsFinite(length)) { var strLength = stringSize(string);
if (!length || strLength >= length) {
return ''; return '';
} }
var padLength = length - strLength; var padLength = length - strLength;
chars = chars == null ? ' ' : baseToString(chars); chars = chars === undefined ? ' ' : (chars + '');
return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
var result = repeat(chars, nativeCeil(padLength / stringSize(chars)));
return reHasComplexSymbol.test(chars)
? stringToArray(result).slice(0, padLength).join('')
: result.slice(0, padLength);
} }
/** /**
* Creates a function that wraps `func` and invokes it with the optional `th is` * Creates a function that wraps `func` to invoke it with the optional `this `
* binding of `thisArg` and the `partials` prepended to those provided to * binding of `thisArg` and the `partials` prepended to those provided to
* the wrapper. * the wrapper.
* *
* @private * @private
* @param {Function} func The function to partially apply arguments to. * @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask of flags. See `createWrapper` for mor * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
e details. for more details.
* @param {*} thisArg The `this` binding of `func`. * @param {*} thisArg The `this` binding of `func`.
* @param {Array} partials The arguments to prepend to those provided to the new function. * @param {Array} partials The arguments to prepend to those provided to the new function.
* @returns {Function} Returns the new bound function. * @returns {Function} Returns the new wrapped function.
*/ */
function createPartialWrapper(func, bitmask, thisArg, partials) { function createPartialWrapper(func, bitmask, thisArg, partials) {
var isBind = bitmask & BIND_FLAG, var isBind = bitmask & BIND_FLAG,
Ctor = createCtorWrapper(func); Ctor = createCtorWrapper(func);
function wrapper() { function wrapper() {
// Avoid `arguments` object use disqualifying optimizations by
// converting it to an array before providing it `func`.
var argsIndex = -1, var argsIndex = -1,
argsLength = arguments.length, argsLength = arguments.length,
leftIndex = -1, leftIndex = -1,
leftLength = partials.length, leftLength = partials.length,
args = Array(argsLength + leftLength); args = Array(leftLength + argsLength),
fn = (this && this !== root && this instanceof wrapper) ? Ctor : fun
c;
while (++leftIndex < leftLength) { while (++leftIndex < leftLength) {
args[leftIndex] = partials[leftIndex]; args[leftIndex] = partials[leftIndex];
} }
while (argsLength--) { while (argsLength--) {
args[leftIndex++] = arguments[++argsIndex]; args[leftIndex++] = arguments[++argsIndex];
} }
return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args); return apply(fn, isBind ? thisArg : this, args);
} }
return wrapper; return wrapper;
} }
/** /**
* Creates a `_.range` or `_.rangeRight` function.
*
* @private
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new range function.
*/
function createRange(fromRight) {
return function(start, end, step) {
if (step && typeof step != 'number' && isIterateeCall(start, end, step))
{
end = step = undefined;
}
// Ensure the sign of `-0` is preserved.
start = toNumber(start);
start = start === start ? start : 0;
if (end === undefined) {
end = start;
start = 0;
} else {
end = toNumber(end) || 0;
}
step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) ||
0);
return baseRange(start, end, step, fromRight);
};
}
/**
* Creates a function that wraps `func` to continue currying.
*
* @private
* @param {Function} func The function to wrap.
* @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
for more details.
* @param {Function} wrapFunc The function to create the `func` wrapper.
* @param {*} placeholder The placeholder to replace.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to prepend to those provided to t
he new function.
* @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createRecurryWrapper(func, bitmask, wrapFunc, placeholder, thisArg,
partials, holders, argPos, ary, arity) {
var isCurry = bitmask & CURRY_FLAG,
newArgPos = argPos ? copyArray(argPos) : undefined,
newsHolders = isCurry ? holders : undefined,
newHoldersRight = isCurry ? undefined : holders,
newPartials = isCurry ? partials : undefined,
newPartialsRight = isCurry ? undefined : partials;
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
if (!(bitmask & CURRY_BOUND_FLAG)) {
bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
}
var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartia
lsRight, newHoldersRight, newArgPos, ary, arity],
result = wrapFunc.apply(undefined, newData);
if (isLaziable(func)) {
setData(result, newData);
}
result.placeholder = placeholder;
return result;
}
/**
* Creates a function like `_.round`.
*
* @private
* @param {string} methodName The name of the `Math` method to use when roun
ding.
* @returns {Function} Returns the new round function.
*/
function createRound(methodName) {
var func = Math[methodName];
return function(number, precision) {
number = toNumber(number);
precision = toInteger(precision);
if (precision) {
// Shift with exponential notation to avoid floating-point issues.
// See [MDN](https://mdn.io/round#Examples) for more details.
var pair = (toString(number) + 'e').split('e'),
value = func(pair[0] + 'e' + (+pair[1] + precision));
pair = (toString(value) + 'e').split('e');
return +(pair[0] + 'e' + (+pair[1] - precision));
}
return func(number);
};
}
/**
* Creates a set of `values`.
*
* @private
* @param {Array} values The values to add to the set.
* @returns {Object} Returns the new set.
*/
var createSet = !(Set && new Set([1, 2]).size === 2) ? noop : function(value
s) {
return new Set(values);
};
/**
* Creates a function that either curries or invokes `func` with optional * Creates a function that either curries or invokes `func` with optional
* `this` binding and partially applied arguments. * `this` binding and partially applied arguments.
* *
* @private * @private
* @param {Function|string} func The function or method name to reference. * @param {Function|string} func The function or method name to wrap.
* @param {number} bitmask The bitmask of flags. * @param {number} bitmask The bitmask of wrapper flags.
* The bitmask may be composed of the following flags: * The bitmask may be composed of the following flags:
* 1 - `_.bind` * 1 - `_.bind`
* 2 - `_.bindKey` * 2 - `_.bindKey`
* 4 - `_.curry` or `_.curryRight` of a bound function * 4 - `_.curry` or `_.curryRight` of a bound function
* 8 - `_.curry` * 8 - `_.curry`
* 16 - `_.curryRight` * 16 - `_.curryRight`
* 32 - `_.partial` * 32 - `_.partial`
* 64 - `_.partialRight` * 64 - `_.partialRight`
* 128 - `_.rearg` * 128 - `_.rearg`
* 256 - `_.ary` * 256 - `_.ary`
* @param {*} [thisArg] The `this` binding of `func`. * @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to be partially applied. * @param {Array} [partials] The arguments to be partially applied.
* @param {Array} [holders] The `partials` placeholder indexes. * @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function. * @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`. * @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`. * @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function. * @returns {Function} Returns the new wrapped function.
*/ */
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ar y, arity) { function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ar y, arity) {
var isBindKey = bitmask & BIND_KEY_FLAG; var isBindKey = bitmask & BIND_KEY_FLAG;
if (!isBindKey && !isFunction(func)) { if (!isBindKey && typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
var length = partials ? partials.length : 0; var length = partials ? partials.length : 0;
if (!length) { if (!length) {
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG); bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
partials = holders = null; partials = holders = undefined;
} }
length -= (holders ? holders.length : 0); ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
arity = arity === undefined ? arity : toInteger(arity);
length -= holders ? holders.length : 0;
if (bitmask & PARTIAL_RIGHT_FLAG) { if (bitmask & PARTIAL_RIGHT_FLAG) {
var partialsRight = partials, var partialsRight = partials,
holdersRight = holders; holdersRight = holders;
partials = holders = null; partials = holders = undefined;
} }
var data = !isBindKey && getData(func), var data = isBindKey ? undefined : getData(func),
newData = [func, bitmask, thisArg, partials, holders, partialsRight, h oldersRight, argPos, ary, arity]; newData = [func, bitmask, thisArg, partials, holders, partialsRight, h oldersRight, argPos, ary, arity];
if (data && data !== true) { if (data) {
mergeData(newData, data); mergeData(newData, data);
bitmask = newData[1];
arity = newData[9];
} }
newData[9] = arity == null func = newData[0];
bitmask = newData[1];
thisArg = newData[2];
partials = newData[3];
holders = newData[4];
arity = newData[9] = newData[9] == null
? (isBindKey ? 0 : func.length) ? (isBindKey ? 0 : func.length)
: (nativeMax(arity - length, 0) || 0); : nativeMax(newData[9] - length, 0);
if (bitmask == BIND_FLAG) { if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
var result = createBindWrapper(newData[0], newData[2]); bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLA }
G)) && !newData[4].length) { if (!bitmask || bitmask == BIND_FLAG) {
result = createPartialWrapper.apply(null, newData); var result = createBaseWrapper(func, bitmask, thisArg);
} else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
result = createCurryWrapper(func, bitmask, arity);
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLA
G)) && !holders.length) {
result = createPartialWrapper(func, bitmask, thisArg, partials);
} else { } else {
result = createHybridWrapper.apply(null, newData); result = createHybridWrapper.apply(undefined, newData);
} }
var setter = data ? baseSetData : setData; var setter = data ? baseSetData : setData;
return setter(result, newData); return setter(result, newData);
} }
/** /**
* A specialized version of `baseIsEqualDeep` for arrays with support for * A specialized version of `baseIsEqualDeep` for arrays with support for
* partial deep comparisons. * partial deep comparisons.
* *
* @private * @private
* @param {Array} array The array to compare. * @param {Array} array The array to compare.
* @param {Array} other The other array to compare. * @param {Array} other The other array to compare.
* @param {Function} equalFunc The function to determine equivalents of valu es. * @param {Function} equalFunc The function to determine equivalents of valu es.
* @param {Function} [customizer] The function to customize comparing arrays * @param {Function} [customizer] The function to customize comparisons.
. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqu
* @param {boolean} [isWhere] Specify performing partial comparisons. al` for more details.
* @param {Array} [stackA] Tracks traversed `value` objects. * @param {Object} [stack] Tracks traversed `array` and `other` objects.
* @param {Array} [stackB] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the arrays are equivalent, else `fal se`. * @returns {boolean} Returns `true` if the arrays are equivalent, else `fal se`.
*/ */
function equalArrays(array, other, equalFunc, customizer, isWhere, stackA, s tackB) { function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
var index = -1, var index = -1,
isPartial = bitmask & PARTIAL_COMPARE_FLAG,
isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
arrLength = array.length, arrLength = array.length,
othLength = other.length, othLength = other.length;
result = true;
if (arrLength != othLength && !(isWhere && othLength > arrLength)) { if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
return false; return false;
} }
// Deep compare the contents, ignoring non-numeric properties. // Assume cyclic values are equal.
while (result && ++index < arrLength) { var stacked = stack.get(array);
if (stacked) {
return stacked == other;
}
var result = true;
stack.set(array, other);
// Ignore non-index properties.
while (++index < arrLength) {
var arrValue = array[index], var arrValue = array[index],
othValue = other[index]; othValue = other[index];
result = undefined;
if (customizer) { if (customizer) {
result = isWhere var compared = isPartial
? customizer(othValue, arrValue, index) ? customizer(othValue, arrValue, index, other, array, stack)
: customizer(arrValue, othValue, index); : customizer(arrValue, othValue, index, array, other, stack);
} }
if (typeof result == 'undefined') { if (compared !== undefined) {
// Recursively compare arrays (susceptible to call stack limits). if (compared) {
if (isWhere) { continue;
var othIndex = othLength; }
while (othIndex--) { result = false;
othValue = other[othIndex]; break;
result = (arrValue && arrValue === othValue) || equalFunc(arrValue }
, othValue, customizer, isWhere, stackA, stackB); // Recursively compare arrays (susceptible to call stack limits).
if (result) { if (isUnordered) {
break; if (!arraySome(other, function(othValue) {
} return arrValue === othValue || equalFunc(arrValue, othValue, cu
} stomizer, bitmask, stack);
} else { })) {
result = (arrValue && arrValue === othValue) || equalFunc(arrValue, result = false;
othValue, customizer, isWhere, stackA, stackB); break;
} }
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, cust
omizer, bitmask, stack))) {
result = false;
break;
} }
} }
return !!result; stack['delete'](array);
return result;
} }
/** /**
* A specialized version of `baseIsEqualDeep` for comparing objects of * A specialized version of `baseIsEqualDeep` for comparing objects of
* the same `toStringTag`. * the same `toStringTag`.
* *
* **Note:** This function only supports comparing values with tags of * **Note:** This function only supports comparing values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
* *
* @private * @private
* @param {Object} value The object to compare. * @param {Object} object The object to compare.
* @param {Object} other The other object to compare. * @param {Object} other The other object to compare.
* @param {string} tag The `toStringTag` of the objects to compare. * @param {string} tag The `toStringTag` of the objects to compare.
* @param {Function} equalFunc The function to determine equivalents of valu
es.
* @param {Function} [customizer] The function to customize comparisons.
* @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqu
al` for more details.
* @returns {boolean} Returns `true` if the objects are equivalent, else `fa lse`. * @returns {boolean} Returns `true` if the objects are equivalent, else `fa lse`.
*/ */
function equalByTag(object, other, tag) { function equalByTag(object, other, tag, equalFunc, customizer, bitmask) {
switch (tag) { switch (tag) {
case arrayBufferTag:
if ((object.byteLength != other.byteLength) ||
!equalFunc(new Uint8Array(object), new Uint8Array(other))) {
return false;
}
return true;
case boolTag: case boolTag:
case dateTag: case dateTag:
// Coerce dates and booleans to numbers, dates to milliseconds and boo leans // Coerce dates and booleans to numbers, dates to milliseconds and boo leans
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
return +object == +other; return +object == +other;
case errorTag: case errorTag:
return object.name == other.name && object.message == other.message; return object.name == other.name && object.message == other.message;
case numberTag: case numberTag:
// Treat `NaN` vs. `NaN` as equal. // Treat `NaN` vs. `NaN` as equal.
return (object != +object) return (object != +object) ? other != +other : object == +other;
? other != +other
// But, treat `-0` vs. `+0` as not equal.
: (object == 0 ? ((1 / object) == (1 / other)) : object == +other);
case regexpTag: case regexpTag:
case stringTag: case stringTag:
// Coerce regexes to strings and treat strings primitives and string // Coerce regexes to strings and treat strings primitives and string
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more de tails. // objects as equal. See https://es5.github.io/#x15.10.6.4 for more de tails.
return object == baseToString(other); return object == (other + '');
case mapTag:
var convert = mapToArray;
case setTag:
var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
convert || (convert = setToArray);
// Recursively compare objects (susceptible to call stack limits).
return (isPartial || object.size == other.size) &&
equalFunc(convert(object), convert(other), customizer, bitmask | UNO
RDERED_COMPARE_FLAG);
case symbolTag:
return !!_Symbol && (symbolValueOf.call(object) == symbolValueOf.call(
other));
} }
return false; return false;
} }
/** /**
* A specialized version of `baseIsEqualDeep` for objects with support for * A specialized version of `baseIsEqualDeep` for objects with support for
* partial deep comparisons. * partial deep comparisons.
* *
* @private * @private
* @param {Object} object The object to compare. * @param {Object} object The object to compare.
* @param {Object} other The other object to compare. * @param {Object} other The other object to compare.
* @param {Function} equalFunc The function to determine equivalents of valu es. * @param {Function} equalFunc The function to determine equivalents of valu es.
* @param {Function} [customizer] The function to customize comparing values * @param {Function} [customizer] The function to customize comparisons.
. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqu
* @param {boolean} [isWhere] Specify performing partial comparisons. al` for more details.
* @param {Array} [stackA] Tracks traversed `value` objects. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
* @param {Array} [stackB] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `fa lse`. * @returns {boolean} Returns `true` if the objects are equivalent, else `fa lse`.
*/ */
function equalObjects(object, other, equalFunc, customizer, isWhere, stackA, function equalObjects(object, other, equalFunc, customizer, bitmask, stack)
stackB) { {
var objProps = keys(object), var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
isUnordered = bitmask & UNORDERED_COMPARE_FLAG,
objProps = keys(object),
objLength = objProps.length, objLength = objProps.length,
othProps = keys(other), othProps = keys(other),
othLength = othProps.length; othLength = othProps.length;
if (objLength != othLength && !isWhere) { if (objLength != othLength && !isPartial) {
return false; return false;
} }
var hasCtor, var index = objLength;
index = -1; while (index--) {
var key = objProps[index];
if (!(isPartial ? key in other : baseHas(other, key)) ||
!(isUnordered || key == othProps[index])) {
return false;
}
}
// Assume cyclic values are equal.
var stacked = stack.get(object);
if (stacked) {
return stacked == other;
}
var result = true;
stack.set(object, other);
var skipCtor = isPartial;
while (++index < objLength) { while (++index < objLength) {
var key = objProps[index], key = objProps[index];
result = hasOwnProperty.call(other, key); var objValue = object[key],
othValue = other[key];
if (result) { if (customizer) {
var objValue = object[key], var compared = isPartial
othValue = other[key]; ? customizer(othValue, objValue, key, other, object, stack)
: customizer(objValue, othValue, key, object, other, stack);
result = undefined; }
if (customizer) { // Recursively compare objects (susceptible to call stack limits).
result = isWhere if (!(compared === undefined
? customizer(othValue, objValue, key) ? (objValue === othValue || equalFunc(objValue, othValue, customiz
: customizer(objValue, othValue, key); er, bitmask, stack))
} : compared
if (typeof result == 'undefined') { )) {
// Recursively compare objects (susceptible to call stack limits). result = false;
result = (objValue && objValue === othValue) || equalFunc(objValue, break;
othValue, customizer, isWhere, stackA, stackB);
}
}
if (!result) {
return false;
} }
hasCtor || (hasCtor = key == 'constructor'); skipCtor || (skipCtor = key == 'constructor');
} }
if (!hasCtor) { if (result && !skipCtor) {
var objCtor = object.constructor, var objCtor = object.constructor,
othCtor = other.constructor; othCtor = other.constructor;
// Non `Object` object instances with different constructors are not equ al. // Non `Object` object instances with different constructors are not equ al.
if (objCtor != othCtor && ('constructor' in object && 'constructor' in o if (objCtor != othCtor &&
ther) && ('constructor' in object && 'constructor' in other) &&
!(typeof objCtor == 'function' && objCtor instanceof objCtor && type !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
of othCtor == 'function' && othCtor instanceof othCtor)) { typeof othCtor == 'function' && othCtor instanceof othCtor)) {
return false; result = false;
} }
} }
return true; stack['delete'](object);
return result;
} }
/** /**
* Gets the extremum value of `collection` invoking `iteratee` for each valu * Gets metadata for `func`.
e
* in `collection` to generate the criterion by which the value is ranked.
* The `iteratee` is invoked with three arguments; (value, index, collection
).
* *
* @private * @private
* @param {Array|Object|string} collection The collection to iterate over. * @param {Function} func The function to query.
* @param {Function} iteratee The function invoked per iteration. * @returns {*} Returns the metadata for `func`.
* @param {boolean} [isMin] Specify returning the minimum, instead of the */
* maximum, extremum value. var getData = !metaMap ? noop : function(func) {
* @returns {*} Returns the extremum value. return metaMap.get(func);
*/ };
function extremumBy(collection, iteratee, isMin) {
var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY,
computed = exValue,
result = computed;
baseEach(collection, function(value, index, collection) { /**
var current = iteratee(value, index, collection); * Gets the name of `func`.
if ((isMin ? current < computed : current > computed) || (current === ex *
Value && current === result)) { * @private
computed = current; * @param {Function} func The function to query.
result = value; * @returns {string} Returns the function name.
*/
function getFuncName(func) {
var result = (func.name + ''),
array = realNames[result],
length = array ? array.length : 0;
while (length--) {
var data = array[length],
otherFunc = data.func;
if (otherFunc == null || otherFunc == func) {
return data.name;
} }
}); }
return result; return result;
} }
/** /**
* Gets the appropriate "callback" function. If the `_.callback` method is * Gets the appropriate "iteratee" function. If the `_.iteratee` method is
* customized this function returns the custom method, otherwise it returns * customized this function returns the custom method, otherwise it returns
* the `baseCallback` function. If arguments are provided the chosen functio * `baseIteratee`. If arguments are provided the chosen function is invoked
n * with them and its result is returned.
* is invoked with them and its result is returned.
* *
* @private * @private
* @param {*} [value] The value to convert to an iteratee.
* @param {number} [arity] The arity of the created iteratee.
* @returns {Function} Returns the chosen function or its result. * @returns {Function} Returns the chosen function or its result.
*/ */
function getCallback(func, thisArg, argCount) { function getIteratee() {
var result = lodash.callback || callback; var result = lodash.iteratee || iteratee;
result = result === callback ? baseCallback : result; result = result === iteratee ? baseIteratee : result;
return argCount ? result(func, thisArg, argCount) : result; return arguments.length ? result(arguments[0], arguments[1]) : result;
} }
/** /**
* Gets metadata for `func`. * Gets the "length" property value of `object`.
*
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.
org/show_bug.cgi?id=142792)
* that affects Safari on at least iOS 8.1-8.3 ARM64.
* *
* @private * @private
* @param {Function} func The function to query. * @param {Object} object The object to query.
* @returns {*} Returns the metadata for `func`. * @returns {*} Returns the "length" value.
*/ */
var getData = !metaMap ? noop : function(func) { var getLength = baseProperty('length');
return metaMap.get(func);
/**
* Gets the property names, values, and compare flags of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the match data of `object`.
*/
function getMatchData(object) {
var result = toPairs(object),
length = result.length;
while (length--) {
result[length][2] = isStrictComparable(result[length][1]);
}
return result;
}
/**
* Gets the native function at `key` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the method to get.
* @returns {*} Returns the function if it's native, else `undefined`.
*/
function getNative(object, key) {
var value = object == null ? undefined : object[key];
return isNative(value) ? value : undefined;
}
/**
* Creates an array of the own symbol properties of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of symbols.
*/
var getSymbols = getOwnPropertySymbols || function() {
return [];
}; };
/** /**
* Gets the appropriate "indexOf" function. If the `_.indexOf` method is * Gets the `toStringTag` of `value`.
* customized this function returns the custom method, otherwise it returns
* the `baseIndexOf` function. If arguments are provided the chosen function
* is invoked with them and its result is returned.
* *
* @private * @private
* @returns {Function|number} Returns the chosen function or its result. * @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/ */
function getIndexOf(collection, target, fromIndex) { function getTag(value) {
var result = lodash.indexOf || indexOf; return objectToString.call(value);
result = result === indexOf ? baseIndexOf : result; }
return collection ? result(collection, target, fromIndex) : result;
// Fallback for IE 11 providing `toStringTag` values for maps and sets.
if ((Map && getTag(new Map) != mapTag) || (Set && getTag(new Set) != setTag)
) {
getTag = function(value) {
var result = objectToString.call(value),
Ctor = result == objectTag ? value.constructor : null,
ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : '
';
if (ctorString) {
if (ctorString == mapCtorString) {
return mapTag;
}
if (ctorString == setCtorString) {
return setTag;
}
}
return result;
};
} }
/** /**
* Gets the view, applying any `transforms` to the `start` and `end` positio ns. * Gets the view, applying any `transforms` to the `start` and `end` positio ns.
* *
* @private * @private
* @param {number} start The start of the view. * @param {number} start The start of the view.
* @param {number} end The end of the view. * @param {number} end The end of the view.
* @param {Array} [transforms] The transformations to apply to the view. * @param {Array} transforms The transformations to apply to the view.
* @returns {Object} Returns an object containing the `start` and `end` * @returns {Object} Returns an object containing the `start` and `end`
* positions of the view. * positions of the view.
*/ */
function getView(start, end, transforms) { function getView(start, end, transforms) {
var index = -1, var index = -1,
length = transforms ? transforms.length : 0; length = transforms.length;
while (++index < length) { while (++index < length) {
var data = transforms[index], var data = transforms[index],
size = data.size; size = data.size;
switch (data.type) { switch (data.type) {
case 'drop': start += size; break; case 'drop': start += size; break;
case 'dropRight': end -= size; break; case 'dropRight': end -= size; break;
case 'take': end = nativeMin(end, start + size); break; case 'take': end = nativeMin(end, start + size); break;
case 'takeRight': start = nativeMax(start, end - size); break; case 'takeRight': start = nativeMax(start, end - size); break;
} }
} }
return { 'start': start, 'end': end }; return { 'start': start, 'end': end };
} }
/** /**
* Checks if `path` exists on `object`.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} path The path to check.
* @param {Function} hasFunc The function to check properties.
* @returns {boolean} Returns `true` if `path` exists, else `false`.
*/
function hasPath(object, path, hasFunc) {
if (object == null) {
return false;
}
var result = hasFunc(object, path);
if (!result && !isKey(path)) {
path = baseToPath(path);
object = parent(object, path);
if (object != null) {
path = last(path);
result = hasFunc(object, path);
}
}
return result || (isLength(object && object.length) && isIndex(path, objec
t.length) &&
(isArray(object) || isString(object) || isArguments(object)));
}
/**
* Initializes an array clone. * Initializes an array clone.
* *
* @private * @private
* @param {Array} array The array to clone. * @param {Array} array The array to clone.
* @returns {Array} Returns the initialized clone. * @returns {Array} Returns the initialized clone.
*/ */
function initCloneArray(array) { function initCloneArray(array) {
var length = array.length, var length = array.length,
result = new array.constructor(length); result = array.constructor(length);
// Add array properties assigned by `RegExp#exec`. // Add properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'i ndex')) { if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'i ndex')) {
result.index = array.index; result.index = array.index;
result.input = array.input; result.input = array.input;
} }
return result; return result;
} }
/** /**
* Initializes an object clone. * Initializes an object clone.
* *
* @private * @private
* @param {Object} object The object to clone. * @param {Object} object The object to clone.
* @returns {Object} Returns the initialized clone. * @returns {Object} Returns the initialized clone.
*/ */
function initCloneObject(object) { function initCloneObject(object) {
var Ctor = object.constructor; var Ctor = object.constructor;
if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) { return baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
Ctor = Object;
}
return new Ctor;
} }
/** /**
* Initializes an object clone based on its `toStringTag`. * Initializes an object clone based on its `toStringTag`.
* *
* **Note:** This function only supports cloning values with tags of * **Note:** This function only supports cloning values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
* *
*
* @private * @private
* @param {Object} object The object to clone. * @param {Object} object The object to clone.
* @param {string} tag The `toStringTag` of the object to clone. * @param {string} tag The `toStringTag` of the object to clone.
* @param {boolean} [isDeep] Specify a deep clone. * @param {boolean} [isDeep] Specify a deep clone.
* @returns {Object} Returns the initialized clone. * @returns {Object} Returns the initialized clone.
*/ */
function initCloneByTag(object, tag, isDeep) { function initCloneByTag(object, tag, isDeep) {
var Ctor = object.constructor; var Ctor = object.constructor;
switch (tag) { switch (tag) {
case arrayBufferTag: case arrayBufferTag:
return bufferClone(object); return cloneBuffer(object);
case boolTag: case boolTag:
case dateTag: case dateTag:
return new Ctor(+object); return new Ctor(+object);
case float32Tag: case float64Tag: case float32Tag: case float64Tag:
case int8Tag: case int16Tag: case int32Tag: case int8Tag: case int16Tag: case int32Tag:
case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
var buffer = object.buffer; return cloneTypedArray(object, isDeep);
return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffs
et, object.length); case mapTag:
return cloneMap(object);
case numberTag: case numberTag:
case stringTag: case stringTag:
return new Ctor(object); return new Ctor(object);
case regexpTag: case regexpTag:
var result = new Ctor(object.source, reFlags.exec(object)); return cloneRegExp(object);
result.lastIndex = object.lastIndex;
}
return result;
}
/** case setTag:
* Checks if `func` is eligible for `this` binding. return cloneSet(object);
*
* @private
* @param {Function} func The function to check.
* @returns {boolean} Returns `true` if `func` is eligible, else `false`.
*/
function isBindable(func) {
var support = lodash.support,
result = !(support.funcNames ? func.name : support.funcDecomp);
if (!result) { case symbolTag:
var source = fnToString.call(func); return cloneSymbol(object);
if (!support.funcNames) {
result = !reFuncName.test(source);
}
if (!result) {
// Check if `func` references the `this` keyword and store the result.
result = reThis.test(source) || isNative(func);
baseSetData(func, result);
}
} }
return result;
} }
/** /**
* Checks if `value` is a valid array-like index. * Creates an array of index keys for `object` values of arrays,
* `arguments` objects, and strings, otherwise `null` is returned.
* *
* @private * @private
* @param {*} value The value to check. * @param {Object} object The object to query.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid ind * @returns {Array|null} Returns index keys, else `null`.
ex.
* @returns {boolean} Returns `true` if `value` is a valid index, else `fals
e`.
*/ */
function isIndex(value, length) { function indexKeys(object) {
value = +value; var length = object ? object.length : undefined;
length = length == null ? MAX_SAFE_INTEGER : length; return (isLength(length) && (isArray(object) || isString(object) || isArgu
return value > -1 && value % 1 == 0 && value < length; ments(object)))
? baseTimes(length, String)
: null;
} }
/** /**
* Checks if the provided arguments are from an iteratee call. * Checks if the provided arguments are from an iteratee call.
* *
* @private * @private
* @param {*} value The potential iteratee value argument. * @param {*} value The potential iteratee value argument.
* @param {*} index The potential iteratee index or key argument. * @param {*} index The potential iteratee index or key argument.
* @param {*} object The potential iteratee object argument. * @param {*} object The potential iteratee object argument.
* @returns {boolean} Returns `true` if the arguments are from an iteratee c all, else `false`. * @returns {boolean} Returns `true` if the arguments are from an iteratee c all, else `false`.
*/ */
function isIterateeCall(value, index, object) { function isIterateeCall(value, index, object) {
if (!isObject(object)) { if (!isObject(object)) {
return false; return false;
} }
var type = typeof index; var type = typeof index;
if (type == 'number') { if (type == 'number'
var length = object.length, ? (isArrayLike(object) && isIndex(index, object.length))
prereq = isLength(length) && isIndex(index, length); : (type == 'string' && index in object)) {
} else { return eq(object[index], value);
prereq = type == 'string' && index in value;
} }
return prereq && object[index] === value; return false;
} }
/** /**
* Checks if `value` is a valid array-like length. * Checks if `value` is a property name and not a property path.
* *
* @private * @private
* @param {*} value The value to check. * @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `fal * @param {Object} [object] The object to query keys on.
se`. * @returns {boolean} Returns `true` if `value` is a property name, else `fa
lse`.
*/ */
function isLength(value) { function isKey(value, object) {
return typeof value == 'number' && value > -1 && value % 1 == 0 && value < if (typeof value == 'number') {
= MAX_SAFE_INTEGER; return true;
}
return !isArray(value) &&
(reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
(object != null && value in Object(object)));
}
/**
* Checks if `value` is suitable for use as unique object key.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
*/
function isKeyable(value) {
var type = typeof value;
return type == 'number' || type == 'boolean' ||
(type == 'string' && value !== '__proto__') || value == null;
}
/**
* Checks if `func` has a lazy counterpart.
*
* @private
* @param {Function} func The function to check.
* @returns {boolean} Returns `true` if `func` has a lazy counterpart, else
`false`.
*/
function isLaziable(func) {
var funcName = getFuncName(func),
other = lodash[funcName];
if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
return false;
}
if (func === other) {
return true;
}
var data = getData(other);
return !!data && func === data[0];
}
/**
* Checks if `value` is likely a prototype object.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`
.
*/
function isPrototype(value) {
var Ctor = value && value.constructor,
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
return value === proto;
} }
/** /**
* Checks if `value` is suitable for strict equality comparisons, i.e. `===` . * Checks if `value` is suitable for strict equality comparisons, i.e. `===` .
* *
* @private * @private
* @param {*} value The value to check. * @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` if suitable for strict * @returns {boolean} Returns `true` if `value` if suitable for strict
* equality comparisons, else `false`. * equality comparisons, else `false`.
*/ */
function isStrictComparable(value) { function isStrictComparable(value) {
return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(val ue)); return value === value && !isObject(value);
} }
/** /**
* Merges the function metadata of `source` into `data`. * Merges the function metadata of `source` into `data`.
* *
* Merging metadata reduces the number of wrappers required to invoke a func tion. * Merging metadata reduces the number of wrappers used to invoke a function .
* This is possible because methods like `_.bind`, `_.curry`, and `_.partial ` * This is possible because methods like `_.bind`, `_.curry`, and `_.partial `
* may be applied regardless of execution order. Methods like `_.ary` and `_ .rearg` * may be applied regardless of execution order. Methods like `_.ary` and `_ .rearg`
* augment function arguments, making the order in which they are executed i mportant, * modify function arguments, making the order in which they are executed im portant,
* preventing the merging of metadata. However, we make an exception for a s afe * preventing the merging of metadata. However, we make an exception for a s afe
* common case where curried functions have `_.ary` and or `_.rearg` applied . * combined case where curried functions have `_.ary` and or `_.rearg` appli ed.
* *
* @private * @private
* @param {Array} data The destination metadata. * @param {Array} data The destination metadata.
* @param {Array} source The source metadata. * @param {Array} source The source metadata.
* @returns {Array} Returns `data`. * @returns {Array} Returns `data`.
*/ */
function mergeData(data, source) { function mergeData(data, source) {
var bitmask = data[1], var bitmask = data[1],
srcBitmask = source[1], srcBitmask = source[1],
newBitmask = bitmask | srcBitmask; newBitmask = bitmask | srcBitmask,
isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
var arityFlags = ARY_FLAG | REARG_FLAG,
bindFlags = BIND_FLAG | BIND_KEY_FLAG,
comboFlags = arityFlags | bindFlags | CURRY_BOUND_FLAG | CURRY_RIGHT_F
LAG;
var isAry = bitmask & ARY_FLAG && !(srcBitmask & ARY_FLAG),
isRearg = bitmask & REARG_FLAG && !(srcBitmask & REARG_FLAG),
argPos = (isRearg ? data : source)[7],
ary = (isAry ? data : source)[8];
var isCommon = !(bitmask >= REARG_FLAG && srcBitmask > bindFlags) && var isCombo =
!(bitmask > bindFlags && srcBitmask >= REARG_FLAG); (srcBitmask == ARY_FLAG && (bitmask == CURRY_FLAG)) ||
(srcBitmask == ARY_FLAG && (bitmask == REARG_FLAG) && (data[7].length <=
var isCombo = (newBitmask >= arityFlags && newBitmask <= comboFlags) && source[8])) ||
(bitmask < REARG_FLAG || ((isRearg || isAry) && argPos.length <= ary)); (srcBitmask == (ARY_FLAG | REARG_FLAG) && (source[7].length <= source[8]
) && (bitmask == CURRY_FLAG));
// Exit early if metadata can't be merged. // Exit early if metadata can't be merged.
if (!(isCommon || isCombo)) { if (!(isCommon || isCombo)) {
return data; return data;
} }
// Use source `thisArg` if available. // Use source `thisArg` if available.
if (srcBitmask & BIND_FLAG) { if (srcBitmask & BIND_FLAG) {
data[2] = source[2]; data[2] = source[2];
// Set when currying a bound function. // Set when currying a bound function.
newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG; newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
} }
// Compose partial arguments. // Compose partial arguments.
var value = source[3]; var value = source[3];
if (value) { if (value) {
var partials = data[3]; var partials = data[3];
data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy data[3] = partials ? composeArgs(partials, value, source[4]) : copyArray
(value); (value);
data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(so data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : copyArray(so
urce[4]); urce[4]);
} }
// Compose partial right arguments. // Compose partial right arguments.
value = source[5]; value = source[5];
if (value) { if (value) {
partials = data[5]; partials = data[5];
data[5] = partials ? composeArgsRight(partials, value, source[6]) : arra data[5] = partials ? composeArgsRight(partials, value, source[6]) : copy
yCopy(value); Array(value);
data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(so data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : copyArray(so
urce[6]); urce[6]);
} }
// Use source `argPos` if available. // Use source `argPos` if available.
value = source[7]; value = source[7];
if (value) { if (value) {
data[7] = arrayCopy(value); data[7] = copyArray(value);
} }
// Use source `ary` if it's smaller. // Use source `ary` if it's smaller.
if (srcBitmask & ARY_FLAG) { if (srcBitmask & ARY_FLAG) {
data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]); data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
} }
// Use source `arity` if one is not provided. // Use source `arity` if one is not provided.
if (data[9] == null) { if (data[9] == null) {
data[9] = source[9]; data[9] = source[9];
} }
// Use source `func` and merge bitmasks. // Use source `func` and merge bitmasks.
data[0] = source[0]; data[0] = source[0];
data[1] = newBitmask; data[1] = newBitmask;
return data; return data;
} }
/** /**
* A specialized version of `_.pick` that picks `object` properties specifie * Used by `_.defaultsDeep` to customize its `_.merge` use.
d
* by the `props` array.
* *
* @private * @private
* @param {Object} object The source object. * @param {*} objValue The destination value.
* @param {string[]} props The property names to pick. * @param {*} srcValue The source value.
* @returns {Object} Returns the new object. * @param {string} key The key of the property to merge.
* @param {Object} object The parent object of `objValue`.
* @param {Object} source The parent object of `srcValue`.
* @param {Object} [stack] Tracks traversed source values and their merged c
ounterparts.
* @returns {*} Returns the value to assign.
*/ */
function pickByArray(object, props) { function mergeDefaults(objValue, srcValue, key, object, source, stack) {
object = toObject(object); if (isObject(objValue) && isObject(srcValue)) {
stack.set(srcValue, objValue);
var index = -1, baseMerge(objValue, srcValue, mergeDefaults, stack);
length = props.length,
result = {};
while (++index < length) {
var key = props[index];
if (key in object) {
result[key] = object[key];
}
} }
return result; return objValue === undefined ? baseClone(srcValue) : objValue;
} }
/** /**
* A specialized version of `_.pick` that picks `object` properties `predica * Gets the parent value at `path` of `object`.
te`
* returns truthy for.
* *
* @private * @private
* @param {Object} object The source object. * @param {Object} object The object to query.
* @param {Function} predicate The function invoked per iteration. * @param {Array} path The path to get the parent value of.
* @returns {Object} Returns the new object. * @returns {*} Returns the parent value.
*/ */
function pickByCallback(object, predicate) { function parent(object, path) {
var result = {}; return path.length == 1 ? object : get(object, baseSlice(path, 0, -1));
baseForIn(object, function(value, key, object) {
if (predicate(value, key, object)) {
result[key] = value;
}
});
return result;
} }
/** /**
* Reorder `array` according to the specified indexes where the element at * Reorder `array` according to the specified indexes where the element at
* the first index is assigned as the first element, the element at * the first index is assigned as the first element, the element at
* the second index is assigned as the second element, and so on. * the second index is assigned as the second element, and so on.
* *
* @private * @private
* @param {Array} array The array to reorder. * @param {Array} array The array to reorder.
* @param {Array} indexes The arranged array indexes. * @param {Array} indexes The arranged array indexes.
* @returns {Array} Returns `array`. * @returns {Array} Returns `array`.
*/ */
function reorder(array, indexes) { function reorder(array, indexes) {
var arrLength = array.length, var arrLength = array.length,
length = nativeMin(indexes.length, arrLength), length = nativeMin(indexes.length, arrLength),
oldArray = arrayCopy(array); oldArray = copyArray(array);
while (length--) { while (length--) {
var index = indexes[length]; var index = indexes[length];
array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined; array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
} }
return array; return array;
} }
/** /**
* Sets metadata for `func`. * Sets metadata for `func`.
skipping to change at line 3801 skipping to change at line 5175
return key; return key;
} }
} else { } else {
count = 0; count = 0;
} }
return baseSetData(key, value); return baseSetData(key, value);
}; };
}()); }());
/** /**
* A fallback implementation of `_.isPlainObject` which checks if `value` * Converts `string` to a property path array.
* is an object created by the `Object` constructor or has a `[[Prototype]]`
* of `null`.
* *
* @private * @private
* @param {*} value The value to check. * @param {string} string The string to convert.
* @returns {boolean} Returns `true` if `value` is a plain object, else `fal * @returns {Array} Returns the property path array.
se`.
*/ */
function shimIsPlainObject(value) { function stringToPath(string) {
var Ctor, var result = [];
support = lodash.support; toString(string).replace(rePropName, function(match, number, quote, string
) {
// Exit early for non `Object` objects. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || matc
if (!(isObjectLike(value) && objToString.call(value) == objectTag) || h));
(!hasOwnProperty.call(value, 'constructor') &&
(Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor insta
nceof Ctor)))) {
return false;
}
// IE < 9 iterates inherited properties before own properties. If the firs
t
// iterated property is an object's own property then there are no inherit
ed
// enumerable properties.
var result;
// In most environments an object's own properties are iterated before
// its inherited properties. If the last iterated property is an object's
// own property then there are no inherited enumerable properties.
baseForIn(value, function(subValue, key) {
result = key;
}); });
return typeof result == 'undefined' || hasOwnProperty.call(value, result); return result;
} }
/** /**
* A fallback implementation of `Object.keys` which creates an array of the * Converts `value` to an array-like object if it's not one.
* own enumerable property names of `object`.
* *
* @private * @private
* @param {Object} object The object to inspect. * @param {*} value The value to process.
* @returns {Array} Returns the array of property names. * @returns {Array} Returns the array-like object.
*/ */
function shimKeys(object) { function toArrayLikeObject(value) {
var props = keysIn(object), return isArrayLikeObject(value) ? value : [];
propsLength = props.length,
length = propsLength && object.length,
support = lodash.support;
var allowIndexes = length && isLength(length) &&
(isArray(object) || (support.nonEnumArgs && isArguments(object)));
var index = -1,
result = [];
while (++index < propsLength) {
var key = props[index];
if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object
, key)) {
result.push(key);
}
}
return result;
} }
/** /**
* Converts `value` to an array-like object if it is not one. * Converts `value` to a function if it's not one.
* *
* @private * @private
* @param {*} value The value to process. * @param {*} value The value to process.
* @returns {Array|Object} Returns the array-like object. * @returns {Function} Returns the function.
*/ */
function toIterable(value) { function toFunction(value) {
if (value == null) { return typeof value == 'function' ? value : identity;
return [];
}
if (!isLength(value.length)) {
return values(value);
}
return isObject(value) ? value : Object(value);
} }
/** /**
* Converts `value` to an object if it is not one. * Creates a clone of `wrapper`.
* *
* @private * @private
* @param {*} value The value to process. * @param {Object} wrapper The wrapper to clone.
* @returns {Object} Returns the object. * @returns {Object} Returns the cloned wrapper.
*/ */
function toObject(value) { function wrapperClone(wrapper) {
return isObject(value) ? value : Object(value); if (wrapper instanceof LazyWrapper) {
return wrapper.clone();
}
var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
result.__actions__ = copyArray(wrapper.__actions__);
result.__index__ = wrapper.__index__;
result.__values__ = wrapper.__values__;
return result;
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
/** /**
* Creates an array of elements split into groups the length of `size`. * Creates an array of elements split into groups the length of `size`.
* If `collection` can't be split evenly, the final chunk will be the remain ing * If `array` can't be split evenly, the final chunk will be the remaining
* elements. * elements.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
* @param {Array} array The array to process. * @param {Array} array The array to process.
* @param {numer} [size=1] The length of each chunk. * @param {number} [size=0] The length of each chunk.
* @param- {Object} [guard] Enables use as a callback for functions like `_.
map`.
* @returns {Array} Returns the new array containing chunks. * @returns {Array} Returns the new array containing chunks.
* @example * @example
* *
* _.chunk(['a', 'b', 'c', 'd'], 2); * _.chunk(['a', 'b', 'c', 'd'], 2);
* // => [['a', 'b'], ['c', 'd']] * // => [['a', 'b'], ['c', 'd']]
* *
* _.chunk(['a', 'b', 'c', 'd'], 3); * _.chunk(['a', 'b', 'c', 'd'], 3);
* // => [['a', 'b', 'c'], ['d']] * // => [['a', 'b', 'c'], ['d']]
*/ */
function chunk(array, size, guard) { function chunk(array, size) {
if (guard ? isIterateeCall(array, size, guard) : size == null) { size = nativeMax(toInteger(size), 0);
size = 1;
} else { var length = array ? array.length : 0;
size = nativeMax(+size || 1, 1); if (!length || size < 1) {
return [];
} }
var index = 0, var index = 0,
length = array ? array.length : 0,
resIndex = -1, resIndex = -1,
result = Array(ceil(length / size)); result = Array(nativeCeil(length / size));
while (index < length) { while (index < length) {
result[++resIndex] = baseSlice(array, index, (index += size)); result[++resIndex] = baseSlice(array, index, (index += size));
} }
return result; return result;
} }
/** /**
* Creates an array with all falsey values removed. The values `false`, `nul l`, * Creates an array with all falsey values removed. The values `false`, `nul l`,
* `0`, `""`, `undefined`, and `NaN` are falsey. * `0`, `""`, `undefined`, and `NaN` are falsey.
skipping to change at line 3958 skipping to change at line 5297
while (++index < length) { while (++index < length) {
var value = array[index]; var value = array[index];
if (value) { if (value) {
result[++resIndex] = value; result[++resIndex] = value;
} }
} }
return result; return result;
} }
/** /**
* Creates an array excluding all values of the provided arrays using * Creates a new array concatenating `array` with any additional arrays
* `SameValueZero` for equality comparisons. * and/or values.
* *
* **Note:** `SameValueZero` comparisons are like strict equality comparison * @static
s, * @memberOf _
* e.g. `===`, except that `NaN` matches `NaN`. See the * @category Array
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samev * @param {Array} array The array to concatenate.
aluezero) * @param {...*} [values] The values to concatenate.
* for more details. * @returns {Array} Returns the new concatenated array.
* @example
*
* var array = [1];
* var other = _.concat(array, 2, [3], [[4]]);
*
* console.log(other);
* // => [1, 2, 3, [4]]
*
* console.log(array);
* // => [1]
*/
var concat = rest(function(array, values) {
values = baseFlatten(values);
return arrayConcat(isArray(array) ? array : [Object(array)], values);
});
/**
* Creates an array of unique `array` values not included in the other
* provided arrays using [`SameValueZero`](http://ecma-international.org/ecm
a-262/6.0/#sec-samevaluezero)
* for equality comparisons.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
* @param {Array} array The array to inspect. * @param {Array} array The array to inspect.
* @param {...Array} [values] The arrays of values to exclude. * @param {...Array} [values] The values to exclude.
* @returns {Array} Returns the new array of filtered values. * @returns {Array} Returns the new array of filtered values.
* @example * @example
* *
* _.difference([1, 2, 3], [5, 2, 10]); * _.difference([3, 2, 1], [4, 2]);
* // => [1, 3] * // => [3, 1]
*/ */
function difference() { var difference = rest(function(array, values) {
var index = -1, return isArrayLikeObject(array)
length = arguments.length; ? baseDifference(array, baseFlatten(values, false, true))
: [];
});
while (++index < length) { /**
var value = arguments[index]; * This method is like `_.difference` except that it accepts `iteratee` whic
if (isArray(value) || isArguments(value)) { h
break; * is invoked for each element of `array` and `values` to generate the crite
} rion
} * by which uniqueness is computed. The iteratee is invoked with one argumen
return baseDifference(value, baseFlatten(arguments, false, true, ++index)) t: (value).
; *
} * @static
* @memberOf _
* @category Array
* @param {Array} array The array to inspect.
* @param {...Array} [values] The values to exclude.
* @param {Function|Object|string} [iteratee=_.identity] The iteratee invoke
d per element.
* @returns {Array} Returns the new array of filtered values.
* @example
*
* _.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
* // => [3.1, 1.3]
*
* // using the `_.property` iteratee shorthand
* _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
* // => [{ 'x': 2 }]
*/
var differenceBy = rest(function(array, values) {
var iteratee = last(values);
if (isArrayLikeObject(iteratee)) {
iteratee = undefined;
}
return isArrayLikeObject(array)
? baseDifference(array, baseFlatten(values, false, true), getIteratee(it
eratee))
: [];
});
/**
* This method is like `_.difference` except that it accepts `comparator`
* which is invoked to compare elements of `array` to `values`. The comparat
or
* is invoked with two arguments: (arrVal, othVal).
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to inspect.
* @param {...Array} [values] The values to exclude.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new array of filtered values.
* @example
*
* var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
*
* _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
* // => [{ 'x': 2, 'y': 1 }]
*/
var differenceWith = rest(function(array, values) {
var comparator = last(values);
if (isArrayLikeObject(comparator)) {
comparator = undefined;
}
return isArrayLikeObject(array)
? baseDifference(array, baseFlatten(values, false, true), undefined, com
parator)
: [];
});
/** /**
* Creates a slice of `array` with `n` elements dropped from the beginning. * Creates a slice of `array` with `n` elements dropped from the beginning.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop. * @param {number} [n=1] The number of elements to drop.
* @param- {Object} [guard] Enables use as a callback for functions like `_. map`. * @param- {Object} [guard] Enables use as an iteratee for functions like `_ .map`.
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
* *
* _.drop([1, 2, 3]); * _.drop([1, 2, 3]);
* // => [2, 3] * // => [2, 3]
* *
* _.drop([1, 2, 3], 2); * _.drop([1, 2, 3], 2);
* // => [3] * // => [3]
* *
* _.drop([1, 2, 3], 5); * _.drop([1, 2, 3], 5);
* // => [] * // => []
* *
* _.drop([1, 2, 3], 0); * _.drop([1, 2, 3], 0);
* // => [1, 2, 3] * // => [1, 2, 3]
*/ */
function drop(array, n, guard) { function drop(array, n, guard) {
var length = array ? array.length : 0; var length = array ? array.length : 0;
if (!length) { if (!length) {
return []; return [];
} }
if (guard ? isIterateeCall(array, n, guard) : n == null) { n = (guard || n === undefined) ? 1 : toInteger(n);
n = 1; return baseSlice(array, n < 0 ? 0 : n, length);
}
return baseSlice(array, n < 0 ? 0 : n);
} }
/** /**
* Creates a slice of `array` with `n` elements dropped from the end. * Creates a slice of `array` with `n` elements dropped from the end.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop. * @param {number} [n=1] The number of elements to drop.
* @param- {Object} [guard] Enables use as a callback for functions like `_. map`. * @param- {Object} [guard] Enables use as an iteratee for functions like `_ .map`.
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
* *
* _.dropRight([1, 2, 3]); * _.dropRight([1, 2, 3]);
* // => [1, 2] * // => [1, 2]
* *
* _.dropRight([1, 2, 3], 2); * _.dropRight([1, 2, 3], 2);
* // => [1] * // => [1]
* *
* _.dropRight([1, 2, 3], 5); * _.dropRight([1, 2, 3], 5);
* // => [] * // => []
* *
* _.dropRight([1, 2, 3], 0); * _.dropRight([1, 2, 3], 0);
* // => [1, 2, 3] * // => [1, 2, 3]
*/ */
function dropRight(array, n, guard) { function dropRight(array, n, guard) {
var length = array ? array.length : 0; var length = array ? array.length : 0;
if (!length) { if (!length) {
return []; return [];
} }
if (guard ? isIterateeCall(array, n, guard) : n == null) { n = (guard || n === undefined) ? 1 : toInteger(n);
n = 1; n = length - n;
}
n = length - (+n || 0);
return baseSlice(array, 0, n < 0 ? 0 : n); return baseSlice(array, 0, n < 0 ? 0 : n);
} }
/** /**
* Creates a slice of `array` excluding elements dropped from the end. * Creates a slice of `array` excluding elements dropped from the end.
* Elements are dropped until `predicate` returns falsey. The predicate is * Elements are dropped until `predicate` returns falsey. The predicate is
* bound to `thisArg` and invoked with three arguments; (value, index, array * invoked with three arguments: (value, index, array).
).
*
* If a property name is provided for `predicate` the created "_.property"
* style callback returns the property value of the given element.
*
* If an object is provided for `predicate` the created "_.matches" style
* callback returns `true` for elements that have the properties of the give
n
* object, else `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invok * @param {Function|Object|string} [predicate=_.identity] The function invok
ed ed per iteration.
* per element.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
* *
* _.dropRightWhile([1, 2, 3], function(n) { return n > 1; });
* // => [1]
*
* var users = [ * var users = [
* { 'user': 'barney', 'status': 'busy', 'active': false }, * { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'status': 'busy', 'active': true }, * { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'status': 'away', 'active': true } * { 'user': 'pebbles', 'active': false }
* ]; * ];
* *
* // using the "_.property" callback shorthand * _.dropRightWhile(users, function(o) { return !o.active; });
* _.pluck(_.dropRightWhile(users, 'active'), 'user'); * // => objects for ['barney']
* // => ['barney']
* *
* // using the "_.matches" callback shorthand * // using the `_.matches` iteratee shorthand
* _.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user'); * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
* // => ['barney', 'fred'] * // => objects for ['barney', 'fred']
*/ *
function dropRightWhile(array, predicate, thisArg) { * // using the `_.matchesProperty` iteratee shorthand
var length = array ? array.length : 0; * _.dropRightWhile(users, ['active', false]);
if (!length) { * // => objects for ['barney']
return []; *
} * // using the `_.property` iteratee shorthand
predicate = getCallback(predicate, thisArg, 3); * _.dropRightWhile(users, 'active');
while (length-- && predicate(array[length], length, array)) {} * // => objects for ['barney', 'fred', 'pebbles']
return baseSlice(array, 0, length + 1); */
function dropRightWhile(array, predicate) {
return (array && array.length)
? baseWhile(array, getIteratee(predicate, 3), true, true)
: [];
} }
/** /**
* Creates a slice of `array` excluding elements dropped from the beginning. * Creates a slice of `array` excluding elements dropped from the beginning.
* Elements are dropped until `predicate` returns falsey. The predicate is * Elements are dropped until `predicate` returns falsey. The predicate is
* bound to `thisArg` and invoked with three arguments; (value, index, array * invoked with three arguments: (value, index, array).
).
*
* If a property name is provided for `predicate` the created "_.property"
* style callback returns the property value of the given element.
*
* If an object is provided for `predicate` the created "_.matches" style
* callback returns `true` for elements that have the properties of the give
n
* object, else `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invok * @param {Function|Object|string} [predicate=_.identity] The function invok
ed ed per iteration.
* per element.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
* *
* _.dropWhile([1, 2, 3], function(n) { return n < 3; });
* // => [3]
*
* var users = [ * var users = [
* { 'user': 'barney', 'status': 'busy', 'active': true }, * { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'status': 'busy', 'active': false }, * { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'status': 'away', 'active': true } * { 'user': 'pebbles', 'active': true }
* ]; * ];
* *
* // using the "_.property" callback shorthand * _.dropWhile(users, function(o) { return !o.active; });
* _.pluck(_.dropWhile(users, 'active'), 'user'); * // => objects for ['pebbles']
* // => ['fred', 'pebbles'] *
* * // using the `_.matches` iteratee shorthand
* // using the "_.matches" callback shorthand * _.dropWhile(users, { 'user': 'barney', 'active': false });
* _.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user'); * // => objects for ['fred', 'pebbles']
* // => ['pebbles'] *
* // using the `_.matchesProperty` iteratee shorthand
* _.dropWhile(users, ['active', false]);
* // => objects for ['pebbles']
*
* // using the `_.property` iteratee shorthand
* _.dropWhile(users, 'active');
* // => objects for ['barney', 'fred', 'pebbles']
*/
function dropWhile(array, predicate) {
return (array && array.length)
? baseWhile(array, getIteratee(predicate, 3), true)
: [];
}
/**
* Fills elements of `array` with `value` from `start` up to, but not
* including, `end`.
*
* **Note:** This method mutates `array`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to fill.
* @param {*} value The value to fill `array` with.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns `array`.
* @example
*
* var array = [1, 2, 3];
*
* _.fill(array, 'a');
* console.log(array);
* // => ['a', 'a', 'a']
*
* _.fill(Array(3), 2);
* // => [2, 2, 2]
*
* _.fill([4, 6, 8, 10], '*', 1, 3);
* // => [4, '*', '*', 10]
*/ */
function dropWhile(array, predicate, thisArg) { function fill(array, value, start, end) {
var length = array ? array.length : 0; var length = array ? array.length : 0;
if (!length) { if (!length) {
return []; return [];
} }
var index = -1; if (start && typeof start != 'number' && isIterateeCall(array, value, star
predicate = getCallback(predicate, thisArg, 3); t)) {
while (++index < length && predicate(array[index], index, array)) {} start = 0;
return baseSlice(array, index); end = length;
}
return baseFill(array, value, start, end);
} }
/** /**
* This method is like `_.find` except that it returns the index of the firs t * This method is like `_.find` except that it returns the index of the firs t
* element `predicate` returns truthy for, instead of the element itself. * element `predicate` returns truthy for instead of the element itself.
*
* If a property name is provided for `predicate` the created "_.property"
* style callback returns the property value of the given element.
*
* If an object is provided for `predicate` the created "_.matches" style
* callback returns `true` for elements that have the properties of the give
n
* object, else `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {Function|Object|string} [predicate=_.identity] The function invok * @param {Function|Object|string} [predicate=_.identity] The function invok
ed ed per iteration.
* per iteration. If a property name or object is provided it is used to
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {number} Returns the index of the found element, else `-1`. * @returns {number} Returns the index of the found element, else `-1`.
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': false }, * { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'age': 40, 'active': true }, * { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'age': 1, 'active': false } * { 'user': 'pebbles', 'active': true }
* ]; * ];
* *
* _.findIndex(users, function(chr) { return chr.age < 40; }); * _.findIndex(users, function(o) { return o.user == 'barney'; });
* // => 0 * // => 0
* *
* // using the "_.matches" callback shorthand * // using the `_.matches` iteratee shorthand
* _.findIndex(users, { 'age': 1 }); * _.findIndex(users, { 'user': 'fred', 'active': false });
* // => 2 * // => 1
*
* // using the `_.matchesProperty` iteratee shorthand
* _.findIndex(users, ['active', false]);
* // => 0
* *
* // using the "_.property" callback shorthand * // using the `_.property` iteratee shorthand
* _.findIndex(users, 'active'); * _.findIndex(users, 'active');
* // => 1 * // => 2
*/ */
function findIndex(array, predicate, thisArg) { function findIndex(array, predicate) {
var index = -1, return (array && array.length)
length = array ? array.length : 0; ? baseFindIndex(array, getIteratee(predicate, 3))
: -1;
predicate = getCallback(predicate, thisArg, 3);
while (++index < length) {
if (predicate(array[index], index, array)) {
return index;
}
}
return -1;
} }
/** /**
* This method is like `_.findIndex` except that it iterates over elements * This method is like `_.findIndex` except that it iterates over elements
* of `collection` from right to left. * of `collection` from right to left.
* *
* If a property name is provided for `predicate` the created "_.property"
* style callback returns the property value of the given element.
*
* If an object is provided for `predicate` the created "_.matches" style
* callback returns `true` for elements that have the properties of the give
n
* object, else `false`.
*
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {Function|Object|string} [predicate=_.identity] The function invok * @param {Function|Object|string} [predicate=_.identity] The function invok
ed ed per iteration.
* per iteration. If a property name or object is provided it is used to
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {number} Returns the index of the found element, else `-1`. * @returns {number} Returns the index of the found element, else `-1`.
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': true }, * { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }, * { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'age': 1, 'active': false } * { 'user': 'pebbles', 'active': false }
* ]; * ];
* *
* _.findLastIndex(users, function(chr) { return chr.age < 40; }); * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
* // => 2 * // => 2
* *
* // using the "_.matches" callback shorthand * // using the `_.matches` iteratee shorthand
* _.findLastIndex(users, { 'age': 40 }); * _.findLastIndex(users, { 'user': 'barney', 'active': true });
* // => 1 * // => 0
*
* // using the `_.matchesProperty` iteratee shorthand
* _.findLastIndex(users, ['active', false]);
* // => 2
* *
* // using the "_.property" callback shorthand * // using the `_.property` iteratee shorthand
* _.findLastIndex(users, 'active'); * _.findLastIndex(users, 'active');
* // => 0 * // => 0
*/ */
function findLastIndex(array, predicate, thisArg) { function findLastIndex(array, predicate) {
var length = array ? array.length : 0; return (array && array.length)
predicate = getCallback(predicate, thisArg, 3); ? baseFindIndex(array, getIteratee(predicate, 3), true)
while (length--) { : -1;
if (predicate(array[length], length, array)) {
return length;
}
}
return -1;
} }
/** /**
* Gets the first element of `array`. * Creates an array of flattened values by running each element in `array`
* through `iteratee` and concating its result to the other mapped values.
* The iteratee is invoked with three arguments: (value, index|key, array).
* *
* @static * @static
* @memberOf _ * @memberOf _
* @alias head
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to iterate over.
* @returns {*} Returns the first element of `array`. * @param {Function|Object|string} [iteratee=_.identity] The function invoke
d per iteration.
* @returns {Array} Returns the new array.
* @example * @example
* *
* _.first([1, 2, 3]); * function duplicate(n) {
* // => 1 * return [n, n];
* }
* *
* _.first([]); * _.flatMap([1, 2], duplicate);
* // => undefined * // => [1, 1, 2, 2]
*/ */
function first(array) { function flatMap(array, iteratee) {
return array ? array[0] : undefined; var length = array ? array.length : 0;
return length ? baseFlatten(arrayMap(array, getIteratee(iteratee, 3))) : [
];
} }
/** /**
* Flattens a nested array. If `isDeep` is `true` the array is recursively * Flattens `array` a single level.
* flattened, otherwise it is only flattened a single level.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
* @param {Array} array The array to flatten. * @param {Array} array The array to flatten.
* @param {boolean} [isDeep] Specify a deep flatten.
* @param- {Object} [guard] Enables use as a callback for functions like `_.
map`.
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
* @example * @example
* *
* _.flatten([1, [2], [3, [[4]]]]); * _.flatten([1, [2, 3, [4]]]);
* // => [1, 2, 3, [[4]]]; * // => [1, 2, 3, [4]]
*
* // using `isDeep`
* _.flatten([1, [2], [3, [[4]]]], true);
* // => [1, 2, 3, 4];
*/ */
function flatten(array, isDeep, guard) { function flatten(array) {
var length = array ? array.length : 0; var length = array ? array.length : 0;
if (guard && isIterateeCall(array, isDeep, guard)) { return length ? baseFlatten(array) : [];
isDeep = false;
}
return length ? baseFlatten(array, isDeep) : [];
} }
/** /**
* Recursively flattens a nested array. * This method is like `_.flatten` except that it recursively flattens `arra y`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
* @param {Array} array The array to recursively flatten. * @param {Array} array The array to recursively flatten.
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
* @example * @example
* *
* _.flattenDeep([1, [2], [3, [[4]]]]); * _.flattenDeep([1, [2, 3, [4]]]);
* // => [1, 2, 3, 4]; * // => [1, 2, 3, 4]
*/ */
function flattenDeep(array) { function flattenDeep(array) {
var length = array ? array.length : 0; var length = array ? array.length : 0;
return length ? baseFlatten(array, true) : []; return length ? baseFlatten(array, true) : [];
} }
/** /**
* The inverse of `_.toPairs`; this method returns an object composed
* from key-value `pairs`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} pairs The key-value pairs.
* @returns {Object} Returns the new object.
* @example
*
* _.fromPairs([['fred', 30], ['barney', 40]]);
* // => { 'fred': 30, 'barney': 40 }
*/
function fromPairs(pairs) {
var index = -1,
length = pairs ? pairs.length : 0,
result = {};
while (++index < length) {
var pair = pairs[index];
baseSet(result, pair[0], pair[1]);
}
return result;
}
/**
* Gets the first element of `array`.
*
* @static
* @memberOf _
* @alias first
* @category Array
* @param {Array} array The array to query.
* @returns {*} Returns the first element of `array`.
* @example
*
* _.head([1, 2, 3]);
* // => 1
*
* _.head([]);
* // => undefined
*/
function head(array) {
return array ? array[0] : undefined;
}
/**
* Gets the index at which the first occurrence of `value` is found in `arra y` * Gets the index at which the first occurrence of `value` is found in `arra y`
* using `SameValueZero` for equality comparisons. If `fromIndex` is negativ * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-s
e, amevaluezero)
* it is used as the offset from the end of `array`. If `array` is sorted * for equality comparisons. If `fromIndex` is negative, it's used as the of
* providing `true` for `fromIndex` performs a faster binary search. fset
* * from the end of `array`. If `array` is sorted providing `true` for `fromI
* **Note:** `SameValueZero` comparisons are like strict equality comparison ndex`
s, * performs a faster binary search.
* e.g. `===`, except that `NaN` matches `NaN`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samev
aluezero)
* for more details.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {*} value The value to search for. * @param {*} value The value to search for.
* @param {boolean|number} [fromIndex=0] The index to search from or `true` * @param {number} [fromIndex=0] The index to search from.
* to perform a binary search on a sorted array.
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
* @example * @example
* *
* _.indexOf([1, 2, 3, 1, 2, 3], 2); * _.indexOf([1, 2, 1, 2], 2);
* // => 1 * // => 1
* *
* // using `fromIndex` * // using `fromIndex`
* _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); * _.indexOf([1, 2, 1, 2], 2, 2);
* // => 4 * // => 3
*
* // performing a binary search
* _.indexOf([4, 4, 5, 5, 6, 6], 5, true);
* // => 2
*/ */
function indexOf(array, value, fromIndex) { function indexOf(array, value, fromIndex) {
var length = array ? array.length : 0; var length = array ? array.length : 0;
if (!length) { if (!length) {
return -1; return -1;
} }
if (typeof fromIndex == 'number') { fromIndex = toInteger(fromIndex);
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromInde if (fromIndex < 0) {
x || 0); fromIndex = nativeMax(length + fromIndex, 0);
} else if (fromIndex) {
var index = binaryIndex(array, value),
other = array[index];
return (value === value ? value === other : other !== other) ? index : -
1;
} }
return baseIndexOf(array, value, fromIndex); return baseIndexOf(array, value, fromIndex);
} }
/** /**
* Gets all but the last element of `array`. * Gets all but the last element of `array`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
skipping to change at line 4399 skipping to change at line 5830
* @example * @example
* *
* _.initial([1, 2, 3]); * _.initial([1, 2, 3]);
* // => [1, 2] * // => [1, 2]
*/ */
function initial(array) { function initial(array) {
return dropRight(array, 1); return dropRight(array, 1);
} }
/** /**
* Creates an array of unique values in all provided arrays using `SameValue * Creates an array of unique values that are included in all of the provide
Zero` d
* arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0
/#sec-samevaluezero)
* for equality comparisons. * for equality comparisons.
* *
* **Note:** `SameValueZero` comparisons are like strict equality comparison * @static
s, * @memberOf _
* e.g. `===`, except that `NaN` matches `NaN`. See the * @category Array
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samev * @param {...Array} [arrays] The arrays to inspect.
aluezero) * @returns {Array} Returns the new array of shared values.
* for more details. * @example
* _.intersection([2, 1], [4, 2], [1, 2]);
* // => [2]
*/
var intersection = rest(function(arrays) {
var mapped = arrayMap(arrays, toArrayLikeObject);
return (mapped.length && mapped[0] === arrays[0])
? baseIntersection(mapped)
: [];
});
/**
* This method is like `_.intersection` except that it accepts `iteratee`
* which is invoked for each element of each `arrays` to generate the criter
ion
* by which uniqueness is computed. The iteratee is invoked with one argumen
t: (value).
* *
* @static * @static
* @memberOf _ * @memberOf _
* @category Array * @category Array
* @param {...Array} [arrays] The arrays to inspect. * @param {...Array} [arrays] The arrays to inspect.
* @param {Function|Object|string} [iteratee=_.identity] The iteratee invoke d per element.
* @returns {Array} Returns the new array of shared values. * @returns {Array} Returns the new array of shared values.
* @example * @example
* *
* _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); * _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor);
* // => [1, 2] * // => [2.1]
*/ *
function intersection() { * // using the `_.property` iteratee shorthand
var args = [], * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
argsIndex = -1, * // => [{ 'x': 1 }]
argsLength = arguments.length, */
caches = [], var intersectionBy = rest(function(arrays) {
indexOf = getIndexOf(), var iteratee = last(arrays),
isCommon = indexOf == baseIndexOf; mapped = arrayMap(arrays, toArrayLikeObject);
while (++argsIndex < argsLength) { if (iteratee === last(mapped)) {
var value = arguments[argsIndex]; iteratee = undefined;
if (isArray(value) || isArguments(value)) { } else {
args.push(value); mapped.pop();
caches.push(isCommon && value.length >= 120 && createCache(argsIndex &
& value));
}
} }
argsLength = args.length; return (mapped.length && mapped[0] === arrays[0])
var array = args[0], ? baseIntersection(mapped, getIteratee(iteratee))
index = -1, : [];
length = array ? array.length : 0, });
result = [],
seen = caches[0];
outer: /**
while (++index < length) { * This method is like `_.intersection` except that it accepts `comparator`
value = array[index]; * which is invoked to compare elements of `arrays`. The comparator is invok
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value)) < 0) { ed
argsIndex = argsLength; * with two arguments: (arrVal, othVal).
while (--argsIndex) { *
var cache = caches[argsIndex]; * @static
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], v * @memberOf _
alue)) < 0) { * @category Array
continue outer; * @param {...Array} [arrays] The arrays to inspect.
} * @param {Function} [comparator] The comparator invoked per element.
} * @returns {Array} Returns the