vendor/assets/javascripts/lodash.compat.js in lodash-rails-3.5.0 vs vendor/assets/javascripts/lodash.compat.js in lodash-rails-3.6.0
- old
+ new
@@ -1,8 +1,8 @@
/**
* @license
- * lodash 3.5.0 (Custom Build) <https://lodash.com/>
+ * lodash 3.6.0 (Custom Build) <https://lodash.com/>
* Build: `lodash compat -o ./lodash.js`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.8.2 <http://underscorejs.org/LICENSE>
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <https://lodash.com/license>
@@ -11,22 +11,22 @@
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/** Used as the semantic version number. */
- var VERSION = '3.5.0';
+ var VERSION = '3.6.0';
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
BIND_KEY_FLAG = 2,
CURRY_BOUND_FLAG = 4,
CURRY_FLAG = 8,
CURRY_RIGHT_FLAG = 16,
PARTIAL_FLAG = 32,
PARTIAL_RIGHT_FLAG = 64,
- REARG_FLAG = 128,
- ARY_FLAG = 256;
+ ARY_FLAG = 128,
+ REARG_FLAG = 256;
/** Used as default options for `_.trunc`. */
var DEFAULT_TRUNC_LENGTH = 30,
DEFAULT_TRUNC_OMISSION = '...';
@@ -86,22 +86,22 @@
var reEscape = /<%-([\s\S]+?)%>/g,
reEvaluate = /<%([\s\S]+?)%>/g,
reInterpolate = /<%=([\s\S]+?)%>/g;
/**
- * Used to match ES template delimiters.
- * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
- * for more details.
+ * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
*/
+ var reComboMarks = /[\u0300-\u036f\ufe20-\ufe23]/g;
+
+ /**
+ * Used to match [ES template delimiters](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components).
+ */
var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
/** Used to match `RegExp` flags from their coerced string values. */
var reFlags = /\w*$/;
- /** Used to detect named functions. */
- var reFuncName = /^\s*function[ \n\r\t]+\w/;
-
/** Used to detect hexadecimal string values. */
var reHexPrefix = /^0[xX]/;
/** Used to detect host constructors (Safari > 5). */
var reHostCtor = /^\[object .+?Constructor\]$/;
@@ -111,20 +111,17 @@
/** Used to ensure capturing order of template delimiters. */
var reNoMatch = /($^)/;
/**
- * Used to match `RegExp` special characters.
- * See this [article on `RegExp` characters](http://www.regular-expressions.info/characters.html#special)
- * for more details.
+ * Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special).
+ * In addition to special characters the forward slash is escaped to allow for
+ * easier `eval` use and `Function` compilation.
*/
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. */
var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
/** Used to match words to create compound words. */
var reWords = (function() {
@@ -151,11 +148,11 @@
'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'document',
'isFinite', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
- 'window', 'WinRTError'
+ 'window'
];
/** Used to fix the JScript `[[DontEnum]]` bug. */
var shadowProps = [
'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
@@ -266,23 +263,26 @@
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
/** Detect free variable `global` from Node.js. */
var freeGlobal = freeExports && freeModule && typeof global == 'object' && global;
+ /** Detect free variable `self`. */
+ var freeSelf = objectTypes[typeof self] && self && self.Object && self;
+
/** Detect free variable `window`. */
- var freeWindow = objectTypes[typeof window] && window;
+ var freeWindow = objectTypes[typeof window] && window && window.Object && window;
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
/**
* Used as a reference to the global object.
*
* The `this` value is used if it is the global object to avoid Greasemonkey's
* restricted `window` object, otherwise the `window` object is used.
*/
- var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || this;
+ var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
/*--------------------------------------------------------------------------*/
/**
* The base implementation of `compareAscending` which compares values and
@@ -307,10 +307,32 @@
}
return 0;
}
/**
+ * The base implementation of `_.findIndex` and `_.findLastIndex` without
+ * support for callback shorthands and `this` binding.
+ *
+ * @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 support for binary searches.
*
* @private
* @param {Array} array The array to search.
* @param {*} value The value to search for.
@@ -492,11 +514,10 @@
return '\\' + stringEscapes[chr];
}
/**
* 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 left.
*
* @private
* @param {Array} array The array to search.
* @param {number} fromIndex The index to search from.
* @param {boolean} [fromRight] Specify iterating from right to left.
@@ -541,11 +562,11 @@
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
*/
function isObjectLike(value) {
- return (value && typeof value == 'object') || false;
+ return !!value && typeof value == 'object';
}
/**
* Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
* character code is whitespace.
@@ -663,23 +684,23 @@
* @category Utility
* @param {Object} [context=root] The context object.
* @returns {Function} Returns a new `lodash` function.
* @example
*
- * _.mixin({ 'add': function(a, b) { return a + b; } });
+ * _.mixin({ 'foo': _.constant('foo') });
*
* var lodash = _.runInContext();
- * lodash.mixin({ 'sub': function(a, b) { return a - b; } });
+ * lodash.mixin({ 'bar': lodash.constant('bar') });
*
- * _.isFunction(_.add);
+ * _.isFunction(_.foo);
* // => true
- * _.isFunction(_.sub);
+ * _.isFunction(_.bar);
* // => false
*
- * lodash.isFunction(lodash.add);
+ * lodash.isFunction(lodash.foo);
* // => false
- * lodash.isFunction(lodash.sub);
+ * lodash.isFunction(lodash.bar);
* // => true
*
* // using `context` to mock `Date#getTime` use in `_.now`
* var mock = _.runInContext({
* 'Date': function() {
@@ -729,13 +750,12 @@
/** Used to generate unique IDs. */
var idCounter = 0;
/**
- * Used to resolve the `toStringTag` of values.
- * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
- * for more details.
+ * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
+ * of values.
*/
var objToString = objectProto.toString;
/** Used to restore the original `_` reference in `_.noConflict`. */
var oldDash = context._;
@@ -796,19 +816,21 @@
/** Used as the size, in bytes, of each `Float64Array` element. */
var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
/**
- * Used as the maximum length of an array-like value.
- * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
- * for more details.
+ * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
+ * of an array-like value.
*/
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
/** Used to store function metadata. */
var metaMap = WeakMap && new WeakMap;
+ /** Used to lookup unminified function names. */
+ var realNames = {};
+
/** Used to lookup a type array constructors by `toStringTag`. */
var ctorByTag = {};
ctorByTag[float32Tag] = context.Float32Array;
ctorByTag[float64Tag] = context.Float64Array;
ctorByTag[int8Tag] = context.Int8Array;
@@ -1020,11 +1042,11 @@
* the PlayStation 3; forced `false` for Windows 8 apps).
*
* @memberOf _.support
* @type boolean
*/
- support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
+ support.funcDecomp = /\bthis\b/.test(function() { return this; });
/**
* Detect if `Function#name` is supported (all but IE).
*
* @memberOf _.support
@@ -1459,11 +1481,11 @@
return array;
}
/**
* A specialized version of `_.forEach` for arrays without support for callback
- * shorthands or `this` binding.
+ * shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns `array`.
@@ -1480,11 +1502,11 @@
return array;
}
/**
* A specialized version of `_.forEachRight` for arrays without support for
- * callback shorthands or `this` binding.
+ * callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns `array`.
@@ -1500,11 +1522,11 @@
return array;
}
/**
* A specialized version of `_.every` for arrays without support for callback
- * shorthands or `this` binding.
+ * shorthands and `this` binding.
*
* @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,
@@ -1522,11 +1544,11 @@
return true;
}
/**
* A specialized version of `_.filter` for arrays without support for callback
- * shorthands or `this` binding.
+ * shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
@@ -1546,11 +1568,11 @@
return result;
}
/**
* A specialized version of `_.map` for arrays without support for callback
- * shorthands or `this` binding.
+ * shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
@@ -1608,11 +1630,11 @@
return result;
}
/**
* A specialized version of `_.reduce` for arrays without support for callback
- * shorthands or `this` binding.
+ * shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
@@ -1633,11 +1655,11 @@
return accumulator;
}
/**
* A specialized version of `_.reduceRight` for arrays without support for
- * callback shorthands or `this` binding.
+ * callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
@@ -1656,11 +1678,11 @@
return accumulator;
}
/**
* A specialized version of `_.some` for arrays without support for callback
- * shorthands or `this` binding.
+ * shorthands and `this` binding.
*
* @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,
@@ -1677,10 +1699,27 @@
}
return false;
}
/**
+ * A specialized version of `_.sum` for arrays without support for iteratees.
+ *
+ * @private
+ * @param {Array} array The array to iterate over.
+ * @returns {number} Returns the sum.
+ */
+ function arraySum(array) {
+ var length = array.length,
+ result = 0;
+
+ while (length--) {
+ result += +array[length] || 0;
+ }
+ return result;
+ }
+
+ /**
* Used by `_.defaults` to customize its `_.assign` use.
*
* @private
* @param {*} objectValue The destination object property value.
* @param {*} sourceValue The source object property value.
@@ -1791,30 +1830,10 @@
}
return object;
}
/**
- * The base implementation of `_.bindAll` without support for individual
- * method name arguments.
- *
- * @private
- * @param {Object} object The object to bind and assign the bound methods to.
- * @param {string[]} methodNames The object method names to bind.
- * @returns {Object} Returns `object`.
- */
- function baseBindAll(object, methodNames) {
- var index = -1,
- length = methodNames.length;
-
- while (++index < length) {
- var key = methodNames[index];
- object[key] = createWrapper(object[key], BIND_FLAG, object);
- }
- return object;
- }
-
- /**
* The base implementation of `_.callback` which supports specifying the
* number of arguments to provide to `func`.
*
* @private
* @param {*} [func=_.identity] The value to convert to a callback.
@@ -1823,13 +1842,13 @@
* @returns {Function} Returns the callback.
*/
function baseCallback(func, thisArg, argCount) {
var type = typeof func;
if (type == 'function') {
- return (typeof thisArg != 'undefined' && isBindable(func))
- ? bindCallback(func, thisArg, argCount)
- : func;
+ return typeof thisArg == 'undefined'
+ ? func
+ : bindCallback(func, thisArg, argCount);
}
if (func == null) {
return identity;
}
if (type == 'object') {
@@ -1935,18 +1954,18 @@
* of where to slice the arguments to provide to `func`.
*
* @private
* @param {Function} func The function to delay.
* @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.
*/
- function baseDelay(func, wait, args, fromIndex) {
+ function baseDelay(func, wait, args) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
- return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);
+ return setTimeout(function() { func.apply(undefined, args); }, wait);
}
/**
* The base implementation of `_.difference` which accepts a single array
* of values to exclude.
@@ -2001,52 +2020,26 @@
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object|string} Returns `collection`.
*/
- function baseEach(collection, iteratee) {
- var length = collection ? collection.length : 0;
- if (!isLength(length)) {
- return baseForOwn(collection, iteratee);
- }
- var index = -1,
- iterable = toObject(collection);
+ var baseEach = createBaseEach(baseForOwn);
- while (++index < length) {
- if (iteratee(iterable[index], index, iterable) === false) {
- break;
- }
- }
- return collection;
- }
-
/**
* The base implementation of `_.forEachRight` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object|string} Returns `collection`.
*/
- function baseEachRight(collection, iteratee) {
- 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;
- }
+ var baseEachRight = createBaseEach(baseForOwnRight, true);
/**
* The base implementation of `_.every` without support for callback
- * shorthands or `this` binding.
+ * shorthands and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if all elements pass the predicate check,
@@ -2091,11 +2084,11 @@
return array;
}
/**
* The base implementation of `_.filter` without support for callback
- * shorthands or `this` binding.
+ * shorthands and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
@@ -2140,26 +2133,25 @@
*
* @private
* @param {Array} array The array to flatten.
* @param {boolean} isDeep Specify a deep flatten.
* @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
- * @param {number} fromIndex The index to start from.
* @returns {Array} Returns the new flattened array.
*/
- function baseFlatten(array, isDeep, isStrict, fromIndex) {
- var index = fromIndex - 1,
+ function baseFlatten(array, isDeep, isStrict) {
+ var index = -1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index];
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
if (isDeep) {
// Recursively flatten arrays (susceptible to call stack limits).
- value = baseFlatten(value, isDeep, isStrict, 0);
+ value = baseFlatten(value, isDeep, isStrict);
}
var valIndex = -1,
valLength = value.length;
result.length += valLength;
@@ -2183,49 +2175,24 @@
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {Function} keysFunc The function to get the keys of `object`.
* @returns {Object} Returns `object`.
*/
- function baseFor(object, iteratee, keysFunc) {
- var index = -1,
- iterable = toObject(object),
- props = keysFunc(object),
- length = props.length;
+ var baseFor = createBaseFor();
- 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
* in the opposite order.
*
* @private
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {Function} keysFunc The function to get the keys of `object`.
* @returns {Object} Returns `object`.
*/
- function baseForRight(object, iteratee, keysFunc) {
- var iterable = toObject(object),
- props = keysFunc(object),
- length = props.length;
+ var baseForRight = createBaseFor(true);
- 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
* shorthands and `this` binding.
*
* @private
@@ -2286,47 +2253,23 @@
}
return result;
}
/**
- * The base implementation of `_.invoke` which requires additional arguments
- * to be provided as an array of arguments rather than individually.
- *
- * @private
- * @param {Array|Object|string} collection The collection to iterate over.
- * @param {Function|string} methodName The name of the method to invoke or
- * the function invoked per iteration.
- * @param {Array} [args] The arguments to invoke the method with.
- * @returns {Array} Returns the array of results.
- */
- function baseInvoke(collection, methodName, args) {
- var index = -1,
- isFunc = typeof methodName == 'function',
- length = collection ? collection.length : 0,
- result = isLength(length) ? Array(length) : [];
-
- baseEach(collection, function(value) {
- var func = isFunc ? methodName : (value != null && value[methodName]);
- result[++index] = func ? func.apply(value, args) : undefined;
- });
- return result;
- }
-
- /**
* The base implementation of `_.isEqual` without support for `this` binding
* `customizer` functions.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @param {Function} [customizer] The function to customize comparing values.
- * @param {boolean} [isWhere] Specify performing partial comparisons.
+ * @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA] Tracks traversed `value` objects.
* @param {Array} [stackB] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/
- function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) {
+ function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
// Exit early for identical values.
if (value === other) {
// Treat `+0` vs. `-0` as not equal.
return value !== 0 || (1 / value == 1 / other);
}
@@ -2337,11 +2280,11 @@
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 baseIsEqualDeep(value, other, baseIsEqual, customizer, isWhere, stackA, stackB);
+ return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
}
/**
* A specialized version of `baseIsEqual` for arrays and objects which performs
* deep comparisons and tracks traversed objects enabling objects with circular
@@ -2350,16 +2293,16 @@
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Function} [customizer] The function to customize comparing objects.
- * @param {boolean} [isWhere] Specify performing partial comparisons.
+ * @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA=[]] Tracks traversed `value` objects.
* @param {Array} [stackB=[]] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
- function baseIsEqualDeep(object, other, equalFunc, customizer, isWhere, stackA, stackB) {
+ function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
var objIsArr = isArray(object),
othIsArr = isArray(other),
objTag = arrayTag,
othTag = arrayTag;
@@ -2377,26 +2320,32 @@
othTag = objectTag;
} else if (othTag != objectTag) {
othIsArr = isTypedArray(other);
}
}
- var objIsObj = objTag == objectTag && !isHostObject(object),
- othIsObj = othTag == objectTag && !isHostObject(other),
+ var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)) && !isHostObject(object),
+ othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)) && !isHostObject(other),
isSameTag = objTag == othTag;
if (isSameTag && !(objIsArr || objIsObj)) {
return equalByTag(object, other, objTag);
}
- var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
- othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
+ if (isLoose) {
+ if (!isSameTag && !(objIsObj && othIsObj)) {
+ return false;
+ }
+ } else {
+ var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
+ othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
- if (valWrapped || othWrapped) {
- return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isWhere, stackA, stackB);
+ if (valWrapped || othWrapped) {
+ return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
+ }
+ if (!isSameTag) {
+ return false;
+ }
}
- if (!isSameTag) {
- return false;
- }
// Assume cyclic values are equal.
// For more information on detecting circular references see https://es5.github.io/#JO.
stackA || (stackA = []);
stackB || (stackB = []);
@@ -2408,55 +2357,52 @@
}
// Add `object` and `other` to the stack of traversed objects.
stackA.push(object);
stackB.push(other);
- var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isWhere, stackA, stackB);
+ var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
stackA.pop();
stackB.pop();
return result;
}
/**
* The base implementation of `_.isMatch` without support for callback
- * shorthands or `this` binding.
+ * shorthands and `this` binding.
*
* @private
* @param {Object} object The object to inspect.
* @param {Array} props The source property names to match.
* @param {Array} values The source values to match.
* @param {Array} strictCompareFlags Strict comparison flags for source values.
* @param {Function} [customizer] The function to customize comparing objects.
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/
function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
- var length = props.length;
- if (object == null) {
- return !length;
- }
var index = -1,
+ length = props.length,
noCustomizer = !customizer;
while (++index < length) {
if ((noCustomizer && strictCompareFlags[index])
? values[index] !== object[props[index]]
- : !hasOwnProperty.call(object, props[index])
+ : !(props[index] in object)
) {
return false;
}
}
index = -1;
while (++index < length) {
- var key = props[index];
+ var key = props[index],
+ objValue = object[key],
+ srcValue = values[index];
+
if (noCustomizer && strictCompareFlags[index]) {
- var result = hasOwnProperty.call(object, key);
+ var result = typeof objValue != 'undefined' || (key in object);
} else {
- var objValue = object[key],
- srcValue = values[index];
-
result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (typeof result == 'undefined') {
result = baseIsEqual(srcValue, objValue, customizer, true);
}
}
@@ -2467,11 +2413,11 @@
return true;
}
/**
* The base implementation of `_.map` without support for callback shorthands
- * or `this` binding.
+ * and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
@@ -2493,17 +2439,21 @@
*/
function baseMatches(source) {
var props = keys(source),
length = props.length;
+ if (!length) {
+ return constant(true);
+ }
if (length == 1) {
var key = props[0],
value = source[key];
if (isStrictComparable(value)) {
return function(object) {
- return object != null && object[key] === value && hasOwnProperty.call(object, key);
+ return object != null && object[key] === value &&
+ (typeof value != 'undefined' || (key in toObject(object)));
};
}
}
var values = Array(length),
strictCompareFlags = Array(length);
@@ -2512,11 +2462,11 @@
value = source[props[length]];
values[length] = value;
strictCompareFlags[length] = isStrictComparable(value);
}
return function(object) {
- return baseIsMatch(object, props, values, strictCompareFlags);
+ return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
};
}
/**
* The base implementation of `_.matchesProperty` which does not coerce `key`
@@ -2528,11 +2478,12 @@
* @returns {Function} Returns the new function.
*/
function baseMatchesProperty(key, value) {
if (isStrictComparable(value)) {
return function(object) {
- return object != null && object[key] === value;
+ return object != null && object[key] === value &&
+ (typeof value != 'undefined' || (key in toObject(object)));
};
}
return function(object) {
return object != null && baseIsEqual(value, object[key], null, true);
};
@@ -2608,11 +2559,11 @@
if (isCommon) {
result = srcValue;
if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
result = isArray(value)
? value
- : (value ? arrayCopy(value) : []);
+ : ((value && value.length) ? arrayCopy(value) : []);
}
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
result = isArguments(value)
? toPlainObject(value)
: (isPlainObject(value) ? value : {});
@@ -2646,34 +2597,10 @@
return object == null ? undefined : object[key];
};
}
/**
- * The base implementation of `_.pullAt` without support for individual
- * index arguments.
- *
- * @private
- * @param {Array} array The array to modify.
- * @param {number[]} indexes The indexes of elements to remove.
- * @returns {Array} Returns the new array of removed elements.
- */
- function basePullAt(array, indexes) {
- var length = indexes.length,
- result = baseAt(array, indexes);
-
- indexes.sort(baseCompareAscending);
- while (length--) {
- var index = parseFloat(indexes[length]);
- if (index != previous && isIndex(index)) {
- var previous = index;
- splice.call(array, index, 1);
- }
- }
- return result;
- }
-
- /**
* The base implementation of `_.random` without support for argument juggling
* and returning floating-point numbers.
*
* @private
* @param {number} min The minimum possible value.
@@ -2684,11 +2611,11 @@
return min + floor(nativeRandom() * (max - min + 1));
}
/**
* The base implementation of `_.reduce` and `_.reduceRight` without support
- * for callback shorthands or `this` binding, which iterates over `collection`
+ * for callback shorthands and `this` binding, which iterates over `collection`
* using the provided `eachFunc`.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
@@ -2751,11 +2678,11 @@
return result;
}
/**
* The base implementation of `_.some` without support for callback shorthands
- * or `this` binding.
+ * and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate check,
@@ -2819,10 +2746,27 @@
return compareMultiple(object, other, orders);
});
}
/**
+ * The base implementation of `_.sum` without support for callback shorthands
+ * and `this` binding.
+ *
+ * @private
+ * @param {Array|Object|string} collection The collection to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {number} Returns the sum.
+ */
+ function baseSum(collection, iteratee) {
+ var result = 0;
+ baseEach(collection, function(value, index, collection) {
+ result += +iteratee(value, index, collection) || 0;
+ });
+ return result;
+ }
+
+ /**
* The base implementation of `_.uniq` without support for callback shorthands
* and `this` binding.
*
* @private
* @param {Array} array The array to inspect.
@@ -2892,18 +2836,39 @@
}
return result;
}
/**
+ * The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
+ * and `_.takeWhile` without support for callback shorthands and `this` binding.
+ *
+ * @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 them.
+ * @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 : length))
+ : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
+ }
+
+ /**
* The base implementation of `wrapperValue` which returns the result of
* performing a sequence of actions on the unwrapped `value`, where each
* successive action is supplied the return value of the previous.
*
* @private
* @param {*} value The unwrapped value.
* @param {Array} actions Actions to peform to resolve the unwrapped value.
- * @returns {*} Returns the resolved unwrapped value.
+ * @returns {*} Returns the resolved value.
*/
function baseWrapperValue(value, actions) {
var result = value;
if (result instanceof LazyWrapper) {
result = result.value();
@@ -2926,12 +2891,11 @@
* 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, instead
- * of the lowest, index at which a value should be inserted into `array`.
+ * @param {boolean} [retHighest] Specify returning the highest qualified index.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
*/
function binaryIndex(array, value, retHighest) {
var low = 0,
@@ -2960,12 +2924,11 @@
*
* @private
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @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`.
+ * @param {boolean} [retHighest] Specify returning the highest qualified index.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
*/
function binaryIndexBy(array, value, iteratee, retHighest) {
value = iteratee(value);
@@ -3127,10 +3090,13 @@
/**
* Creates a function that aggregates a collection, creating an accumulator
* object composed from the results of running each element in the collection
* through an iteratee.
*
+ * **Note:** This function is used to create `_.countBy`, `_.groupBy`, `_.indexBy`,
+ * and `_.partition`.
+ *
* @private
* @param {Function} setter The function to set keys and values of the accumulator object.
* @param {Function} [initializer] The function to initialize the accumulator object.
* @returns {Function} Returns the new aggregator function.
*/
@@ -3158,10 +3124,12 @@
/**
* Creates a function that assigns properties of source object(s) to a given
* destination object.
*
+ * **Note:** This function is used to create `_.assign`, `_.defaults`, and `_.merge`.
+ *
* @private
* @param {Function} assigner The function to assign values.
* @returns {Function} Returns the new assigner function.
*/
function createAssigner(assigner) {
@@ -3198,10 +3166,60 @@
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) {
+ var length = collection ? collection.length : 0;
+ if (!isLength(length)) {
+ return eachFunc(collection, iteratee);
+ }
+ var index = fromRight ? length : -1,
+ iterable = toObject(collection);
+
+ while ((fromRight ? index-- : ++index < length)) {
+ if (iteratee(iterable[index], index, iterable) === false) {
+ break;
+ }
+ }
+ return collection;
+ };
+ }
+
+ /**
+ * Creates a base function for `_.forIn` or `_.forInRight`.
+ *
+ * @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 iterable = toObject(object),
+ props = keysFunc(object),
+ length = props.length,
+ index = fromRight ? length : -1;
+
+ while ((fromRight ? index-- : ++index < length)) {
+ var key = props[index];
+ if (iteratee(iterable[key], key, iterable) === false) {
+ break;
+ }
+ }
+ return object;
+ };
+ }
+
+ /**
* Creates a function that wraps `func` and invokes it with the `this`
* binding of `thisArg`.
*
* @private
* @param {Function} func The function to bind.
@@ -3228,45 +3246,10 @@
var createCache = !(nativeCreate && Set) ? constant(null) : function(values) {
return new SetCache(values);
};
/**
- * Creates a function to compose other functions into a single function.
- *
- * @private
- * @param {boolean} [fromRight] Specify iterating from right to left.
- * @returns {Function} Returns the new composer function.
- */
- function createComposer(fromRight) {
- return function() {
- var length = arguments.length,
- index = length,
- fromIndex = fromRight ? (length - 1) : 0;
-
- if (!length) {
- return function() { return arguments[0]; };
- }
- var funcs = Array(length);
- while (index--) {
- funcs[index] = arguments[index];
- if (typeof funcs[index] != 'function') {
- throw new TypeError(FUNC_ERROR_TEXT);
- }
- }
- return function() {
- var index = fromIndex,
- result = funcs[index].apply(this, arguments);
-
- while ((fromRight ? index-- : ++index < length)) {
- result = funcs[index].call(this, result);
- }
- return result;
- };
- };
- }
-
- /**
* Creates a function that produces compound words out of the words in a
* given string.
*
* @private
* @param {Function} callback The function to combine each word.
@@ -3304,13 +3287,32 @@
return isObject(result) ? result : thisBinding;
};
}
/**
- * Creates a function that gets the extremum value of a collection.
+ * Creates a `_.curry` or `_.curryRight` function.
*
* @private
+ * @param {boolean} flag The curry bit flag.
+ * @returns {Function} Returns the new curry function.
+ */
+ function createCurry(flag) {
+ function curryFunc(func, arity, guard) {
+ if (guard && isIterateeCall(func, arity, guard)) {
+ arity = null;
+ }
+ var result = createWrapper(func, flag, null, null, null, null, null, arity);
+ result.placeholder = curryFunc.placeholder;
+ return result;
+ }
+ return curryFunc;
+ }
+
+ /**
+ * Creates a `_.max` or `_.min` function.
+ *
+ * @private
* @param {Function} arrayFunc The function to get the extremum value from an array.
* @param {boolean} [isMin] Specify returning the minimum, instead of the maximum,
* extremum value.
* @returns {Function} Returns the new extremum function.
*/
@@ -3337,10 +3339,208 @@
return extremumBy(collection, iteratee, isMin);
};
}
/**
+ * Creates a `_.find` or `_.findLast` 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 find function.
+ */
+ function createFind(eachFunc, fromRight) {
+ return function(collection, predicate, thisArg) {
+ predicate = getCallback(predicate, thisArg, 3);
+ if (isArray(collection)) {
+ var index = baseFindIndex(collection, predicate, fromRight);
+ return index > -1 ? collection[index] : undefined;
+ }
+ return baseFind(collection, predicate, eachFunc);
+ }
+ }
+
+ /**
+ * Creates a `_.findIndex` or `_.findLastIndex` function.
+ *
+ * @private
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {Function} Returns the new find function.
+ */
+ function createFindIndex(fromRight) {
+ return function(array, predicate, thisArg) {
+ if (!(array && array.length)) {
+ return -1;
+ }
+ predicate = getCallback(predicate, thisArg, 3);
+ return baseFindIndex(array, predicate, fromRight);
+ };
+ }
+
+ /**
+ * Creates a `_.findKey` or `_.findLastKey` function.
+ *
+ * @private
+ * @param {Function} objectFunc The function to iterate over an object.
+ * @returns {Function} Returns the new find function.
+ */
+ function createFindKey(objectFunc) {
+ return function(object, predicate, thisArg) {
+ predicate = getCallback(predicate, thisArg, 3);
+ return baseFind(object, predicate, objectFunc, true);
+ };
+ }
+
+ /**
+ * Creates a `_.flow` or `_.flowRight` function.
+ *
+ * @private
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {Function} Returns the new flow function.
+ */
+ function createFlow(fromRight) {
+ return function() {
+ var length = arguments.length;
+ if (!length) {
+ return function() { return arguments[0]; };
+ }
+ var wrapper,
+ index = fromRight ? length : -1,
+ leftIndex = 0,
+ funcs = Array(length);
+
+ while ((fromRight ? index-- : ++index < length)) {
+ var func = funcs[leftIndex++] = arguments[index];
+ if (typeof func != 'function') {
+ throw new TypeError(FUNC_ERROR_TEXT);
+ }
+ var funcName = wrapper ? '' : getFuncName(func);
+ wrapper = funcName == 'wrapper' ? new LodashWrapper([]) : wrapper;
+ }
+ index = wrapper ? -1 : length;
+ while (++index < length) {
+ func = funcs[index];
+ funcName = getFuncName(func);
+
+ var data = funcName == 'wrapper' ? getData(func) : null;
+ if (data && isLaziable(data[0])) {
+ wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
+ } else {
+ wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
+ }
+ }
+ return function() {
+ var args = arguments;
+ if (wrapper && args.length == 1 && isArray(args[0])) {
+ return wrapper.plant(args[0]).value();
+ }
+ var index = 0,
+ result = funcs[index].apply(this, args);
+
+ while (++index < length) {
+ result = funcs[index].call(this, result);
+ }
+ return result;
+ };
+ };
+ }
+
+ /**
+ * Creates a function for `_.forEach` or `_.forEachRight`.
+ *
+ * @private
+ * @param {Function} arrayFunc The function to iterate over an array.
+ * @param {Function} eachFunc The function to iterate over a collection.
+ * @returns {Function} Returns the new each function.
+ */
+ function createForEach(arrayFunc, eachFunc) {
+ return function(collection, iteratee, thisArg) {
+ return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
+ ? arrayFunc(collection, iteratee)
+ : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
+ };
+ }
+
+ /**
+ * Creates a function for `_.forIn` or `_.forInRight`.
+ *
+ * @private
+ * @param {Function} objectFunc The function to iterate over an object.
+ * @returns {Function} Returns the new each function.
+ */
+ function createForIn(objectFunc) {
+ return function(object, iteratee, thisArg) {
+ if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
+ iteratee = bindCallback(iteratee, thisArg, 3);
+ }
+ return objectFunc(object, iteratee, keysIn);
+ };
+ }
+
+ /**
+ * Creates a function for `_.forOwn` or `_.forOwnRight`.
+ *
+ * @private
+ * @param {Function} objectFunc The function to iterate over an object.
+ * @returns {Function} Returns the new each function.
+ */
+ function createForOwn(objectFunc) {
+ return function(object, iteratee, thisArg) {
+ if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
+ iteratee = bindCallback(iteratee, thisArg, 3);
+ }
+ return objectFunc(object, iteratee);
+ };
+ }
+
+ /**
+ * Creates a function for `_.padLeft` or `_.padRight`.
+ *
+ * @private
+ * @param {boolean} [fromRight] Specify padding from the right.
+ * @returns {Function} Returns the new pad function.
+ */
+ function createPadDir(fromRight) {
+ return function(string, length, chars) {
+ string = baseToString(string);
+ return string && ((fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string));
+ };
+ }
+
+ /**
+ * Creates a `_.partial` or `_.partialRight` function.
+ *
+ * @private
+ * @param {boolean} flag The partial bit flag.
+ * @returns {Function} Returns the new partial function.
+ */
+ function createPartial(flag) {
+ var partialFunc = restParam(function(func, partials) {
+ var holders = replaceHolders(partials, partialFunc.placeholder);
+ return createWrapper(func, flag, null, partials, holders);
+ });
+ return partialFunc;
+ }
+
+ /**
+ * Creates a function for `_.reduce` or `_.reduceRight`.
+ *
+ * @private
+ * @param {Function} arrayFunc The function to iterate over an array.
+ * @param {Function} eachFunc The function to iterate over a collection.
+ * @returns {Function} Returns the new each function.
+ */
+ function createReduce(arrayFunc, eachFunc) {
+ return function(collection, iteratee, accumulator, thisArg) {
+ var initFromArray = arguments.length < 3;
+ return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
+ ? arrayFunc(collection, iteratee, accumulator, initFromArray)
+ : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
+ };
+ }
+
+ /**
* Creates a function that wraps `func` and invokes it with optional `this`
* binding of, partial application, and currying.
*
* @private
* @param {Function|string} func The function or method name to reference.
@@ -3399,11 +3599,16 @@
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);
+ var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
+ result = createHybridWrapper.apply(undefined, newData);
+
+ if (isLaziable(func)) {
+ setData(result, newData);
+ }
result.placeholder = placeholder;
return result;
}
}
var thisBinding = isBind ? thisArg : this;
@@ -3421,21 +3626,20 @@
}
return wrapper;
}
/**
- * Creates the pad required for `string` based on the given padding length.
- * The `chars` string may be truncated if the number of padding characters
- * exceeds the padding length.
+ * Creates the padding required for `string` based on the given `length`.
+ * The `chars` string is truncated if the number of characters exceeds `length`.
*
* @private
* @param {string} string The string to create padding for.
* @param {number} [length=0] The padding length.
* @param {string} [chars=' '] The string used as padding.
* @returns {string} Returns the pad for `string`.
*/
- function createPad(string, length, chars) {
+ function createPadding(string, length, chars) {
var strLength = string.length;
length = +length;
if (strLength >= length || !nativeIsFinite(length)) {
return '';
@@ -3481,10 +3685,26 @@
}
return wrapper;
}
/**
+ * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
+ *
+ * @private
+ * @param {boolean} [retHighest] Specify returning the highest qualified index.
+ * @returns {Function} Returns the new index function.
+ */
+ function createSortedIndex(retHighest) {
+ return function(array, value, iteratee, thisArg) {
+ var func = getCallback(iteratee);
+ return (func === baseCallback && iteratee == null)
+ ? binaryIndex(array, value, retHighest)
+ : binaryIndexBy(array, value, func(iteratee, thisArg, 1), retHighest);
+ };
+ }
+
+ /**
* Creates a function that either curries or invokes `func` with optional
* `this` binding and partially applied arguments.
*
* @private
* @param {Function|string} func The function or method name to reference.
@@ -3522,14 +3742,14 @@
var partialsRight = partials,
holdersRight = holders;
partials = holders = null;
}
- var data = !isBindKey && getData(func),
+ var data = isBindKey ? null : getData(func),
newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
- if (data && data !== true) {
+ if (data) {
mergeData(newData, data);
bitmask = newData[1];
arity = newData[9];
}
newData[9] = arity == null
@@ -3554,48 +3774,48 @@
* @private
* @param {Array} array The array to compare.
* @param {Array} other The other array to compare.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Function} [customizer] The function to customize comparing arrays.
- * @param {boolean} [isWhere] Specify performing partial comparisons.
+ * @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA] Tracks traversed `value` objects.
* @param {Array} [stackB] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
*/
- function equalArrays(array, other, equalFunc, customizer, isWhere, stackA, stackB) {
+ function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
var index = -1,
arrLength = array.length,
othLength = other.length,
result = true;
- if (arrLength != othLength && !(isWhere && othLength > arrLength)) {
+ if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
return false;
}
// Deep compare the contents, ignoring non-numeric properties.
while (result && ++index < arrLength) {
var arrValue = array[index],
othValue = other[index];
result = undefined;
if (customizer) {
- result = isWhere
+ result = isLoose
? customizer(othValue, arrValue, index)
: customizer(arrValue, othValue, index);
}
if (typeof result == 'undefined') {
// Recursively compare arrays (susceptible to call stack limits).
- if (isWhere) {
+ if (isLoose) {
var othIndex = othLength;
while (othIndex--) {
othValue = other[othIndex];
- result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isWhere, stackA, stackB);
+ result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
if (result) {
break;
}
}
} else {
- result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isWhere, stackA, stackB);
+ result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
}
}
}
return !!result;
}
@@ -3647,52 +3867,52 @@
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Function} [customizer] The function to customize comparing values.
- * @param {boolean} [isWhere] Specify performing partial comparisons.
+ * @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA] Tracks traversed `value` objects.
* @param {Array} [stackB] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
- function equalObjects(object, other, equalFunc, customizer, isWhere, stackA, stackB) {
+ function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
var objProps = keys(object),
objLength = objProps.length,
othProps = keys(other),
othLength = othProps.length;
- if (objLength != othLength && !isWhere) {
+ if (objLength != othLength && !isLoose) {
return false;
}
- var hasCtor,
+ var skipCtor = isLoose,
index = -1;
while (++index < objLength) {
var key = objProps[index],
- result = hasOwnProperty.call(other, key);
+ result = isLoose ? key in other : hasOwnProperty.call(other, key);
if (result) {
var objValue = object[key],
othValue = other[key];
result = undefined;
if (customizer) {
- result = isWhere
+ result = isLoose
? customizer(othValue, objValue, key)
: customizer(objValue, othValue, key);
}
if (typeof result == 'undefined') {
// Recursively compare objects (susceptible to call stack limits).
- result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isWhere, stackA, stackB);
+ result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB);
}
}
if (!result) {
return false;
}
- hasCtor || (hasCtor = key == 'constructor');
+ skipCtor || (skipCtor = key == 'constructor');
}
- if (!hasCtor) {
+ if (!skipCtor) {
var objCtor = object.constructor,
othCtor = other.constructor;
// Non `Object` object instances with different constructors are not equal.
if (objCtor != othCtor &&
@@ -3706,11 +3926,11 @@
}
/**
* Gets the extremum value of `collection` invoking `iteratee` for each value
* in `collection` to generate the criterion by which the value is ranked.
- * The `iteratee` is invoked with three arguments; (value, index, collection).
+ * The `iteratee` is invoked with three arguments: (value, index, collection).
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {boolean} [isMin] Specify returning the minimum, instead of the
@@ -3758,10 +3978,41 @@
var getData = !metaMap ? noop : function(func) {
return metaMap.get(func);
};
/**
+ * Gets the name of `func`.
+ *
+ * @private
+ * @param {Function} func The function to query.
+ * @returns {string} Returns the function name.
+ */
+ var getFuncName = (function() {
+ if (!support.funcNames) {
+ return constant('');
+ }
+ if (constant.name == 'constant') {
+ return baseProperty('name');
+ }
+ return function(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;
+ };
+ }());
+
+ /**
* Gets the appropriate "indexOf" function. If the `_.indexOf` method is
* 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.
*
@@ -3879,35 +4130,10 @@
}
return result;
}
/**
- * Checks if `func` is eligible for `this` binding.
- *
- * @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) {
- var source = fnToString.call(func);
- 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.
*
* @private
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
@@ -3945,15 +4171,25 @@
}
return false;
}
/**
+ * 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);
+ return !!funcName && func === lodash[funcName] && funcName in LazyWrapper.prototype;
+ }
+
+ /**
* Checks if `value` is a valid array-like length.
*
- * **Note:** This function is based on ES `ToLength`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
- * for more details.
+ * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
*/
@@ -3989,27 +4225,18 @@
* @returns {Array} Returns `data`.
*/
function mergeData(data, source) {
var bitmask = data[1],
srcBitmask = source[1],
- newBitmask = bitmask | srcBitmask;
+ newBitmask = bitmask | srcBitmask,
+ isCommon = newBitmask < ARY_FLAG;
- var arityFlags = ARY_FLAG | REARG_FLAG,
- bindFlags = BIND_FLAG | BIND_KEY_FLAG,
- comboFlags = arityFlags | bindFlags | CURRY_BOUND_FLAG | CURRY_RIGHT_FLAG;
+ var isCombo =
+ (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
+ (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
+ (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
- 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) &&
- !(bitmask > bindFlags && srcBitmask >= REARG_FLAG);
-
- var isCombo = (newBitmask >= arityFlags && newBitmask <= comboFlags) &&
- (bitmask < REARG_FLAG || ((isRearg || isAry) && argPos.length <= ary));
-
// Exit early if metadata can't be merged.
if (!(isCommon || isCombo)) {
return data;
}
// Use source `thisArg` if available.
@@ -4345,14 +4572,13 @@
/**
* Creates an array excluding all values of the provided arrays using
* `SameValueZero` for equality comparisons.
*
- * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
- * e.g. `===`, except that `NaN` matches `NaN`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
- * for more details.
+ * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * comparisons are like strict equality comparisons, e.g. `===`, except that
+ * `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to inspect.
@@ -4361,24 +4587,16 @@
* @example
*
* _.difference([1, 2, 3], [4, 2]);
* // => [1, 3]
*/
- function difference() {
- var args = arguments,
- index = -1,
- length = args.length;
+ var difference = restParam(function(array, values) {
+ return (isArray(array) || isArguments(array))
+ ? baseDifference(array, baseFlatten(values, false, true))
+ : [];
+ });
- while (++index < length) {
- var value = args[index];
- if (isArray(value) || isArguments(value)) {
- break;
- }
- }
- return baseDifference(value, baseFlatten(args, false, true, ++index));
- }
-
/**
* Creates a slice of `array` with `n` elements dropped from the beginning.
*
* @static
* @memberOf _
@@ -4449,11 +4667,11 @@
}
/**
* Creates a slice of `array` excluding elements dropped from the end.
* Elements are dropped until `predicate` returns falsey. The predicate is
- * bound to `thisArg` and invoked with three arguments; (value, index, array).
+ * bound to `thisArg` and 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 a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -4496,23 +4714,19 @@
* // using the `_.property` callback shorthand
* _.pluck(_.dropRightWhile(users, 'active'), 'user');
* // => ['barney', 'fred', 'pebbles']
*/
function dropRightWhile(array, predicate, thisArg) {
- var length = array ? array.length : 0;
- if (!length) {
- return [];
- }
- predicate = getCallback(predicate, thisArg, 3);
- while (length-- && predicate(array[length], length, array)) {}
- return baseSlice(array, 0, length + 1);
+ return (array && array.length)
+ ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
+ : [];
}
/**
* Creates a slice of `array` excluding elements dropped from the beginning.
* Elements are dropped until `predicate` returns falsey. The predicate is
- * bound to `thisArg` and invoked with three arguments; (value, index, array).
+ * bound to `thisArg` and 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 a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -4555,18 +4769,13 @@
* // using the `_.property` callback shorthand
* _.pluck(_.dropWhile(users, 'active'), 'user');
* // => ['barney', 'fred', 'pebbles']
*/
function dropWhile(array, predicate, thisArg) {
- var length = array ? array.length : 0;
- if (!length) {
- return [];
- }
- var index = -1;
- predicate = getCallback(predicate, thisArg, 3);
- while (++index < length && predicate(array[index], index, array)) {}
- return baseSlice(array, index);
+ return (array && array.length)
+ ? baseWhile(array, getCallback(predicate, thisArg, 3), true)
+ : [];
}
/**
* Fills elements of `array` with `value` from `start` up to, but not
* including, `end`.
@@ -4579,10 +4788,23 @@
* @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], '*', 1, 2);
+ * // => [4, '*', 8]
*/
function fill(array, value, start, end) {
var length = array ? array.length : 0;
if (!length) {
return [];
@@ -4594,11 +4816,11 @@
return baseFill(array, value, start, end);
}
/**
* This method is like `_.find` except that it returns the index of the first
- * 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 a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -4640,23 +4862,12 @@
*
* // using the `_.property` callback shorthand
* _.findIndex(users, 'active');
* // => 2
*/
- function findIndex(array, predicate, thisArg) {
- var index = -1,
- length = array ? array.length : 0;
+ var findIndex = createFindIndex();
- 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
* of `collection` from right to left.
*
* If a property name is provided for `predicate` the created `_.property`
@@ -4701,20 +4912,11 @@
*
* // using the `_.property` callback shorthand
* _.findLastIndex(users, 'active');
* // => 0
*/
- function findLastIndex(array, predicate, thisArg) {
- var length = array ? array.length : 0;
- predicate = getCallback(predicate, thisArg, 3);
- while (length--) {
- if (predicate(array[length], length, array)) {
- return length;
- }
- }
- return -1;
- }
+ var findLastIndex = createFindIndex(true);
/**
* Gets the first element of `array`.
*
* @static
@@ -4747,22 +4949,22 @@
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the new flattened array.
* @example
*
* _.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];
+ * // => [1, 2, 3, 4]
*/
function flatten(array, isDeep, guard) {
var length = array ? array.length : 0;
if (guard && isIterateeCall(array, isDeep, guard)) {
isDeep = false;
}
- return length ? baseFlatten(array, isDeep, false, 0) : [];
+ return length ? baseFlatten(array, isDeep) : [];
}
/**
* Recursively flattens a nested array.
*
@@ -4772,27 +4974,26 @@
* @param {Array} array The array to recursively flatten.
* @returns {Array} Returns the new flattened array.
* @example
*
* _.flattenDeep([1, [2, 3, [4]]]);
- * // => [1, 2, 3, 4];
+ * // => [1, 2, 3, 4]
*/
function flattenDeep(array) {
var length = array ? array.length : 0;
- return length ? baseFlatten(array, true, false, 0) : [];
+ return length ? baseFlatten(array, true) : [];
}
/**
* Gets the index at which the first occurrence of `value` is found in `array`
* using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
* it is used as the offset from the end of `array`. If `array` is sorted
* providing `true` for `fromIndex` performs a faster binary search.
*
- * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
- * e.g. `===`, except that `NaN` matches `NaN`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
- * for more details.
+ * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * comparisons are like strict equality comparisons, e.g. `===`, except that
+ * `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to search.
@@ -4851,14 +5052,13 @@
/**
* Creates an array of unique values in all provided arrays using `SameValueZero`
* for equality comparisons.
*
- * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
- * e.g. `===`, except that `NaN` matches `NaN`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
- * for more details.
+ * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * comparisons are like strict equality comparisons, e.g. `===`, except that
+ * `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
@@ -4982,14 +5182,14 @@
/**
* Removes all provided values from `array` using `SameValueZero` for equality
* comparisons.
*
* **Notes:**
- * - Unlike `_.without`, this method mutates `array`.
- * - `SameValueZero` comparisons are like strict equality comparisons, e.g. `===`,
- * except that `NaN` matches `NaN`. See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
- * for more details.
+ * - Unlike `_.without`, this method mutates `array`
+ * - [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * comparisons are like strict equality comparisons, e.g. `===`, except
+ * that `NaN` matches `NaN`
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to modify.
@@ -5048,18 +5248,32 @@
* // => [5, 15]
*
* console.log(evens);
* // => [10, 20]
*/
- function pullAt(array) {
- return basePullAt(array || [], baseFlatten(arguments, false, false, 1));
- }
+ var pullAt = restParam(function(array, indexes) {
+ array || (array = []);
+ indexes = baseFlatten(indexes);
+ var length = indexes.length,
+ result = baseAt(array, indexes);
+
+ indexes.sort(baseCompareAscending);
+ while (length--) {
+ var index = parseFloat(indexes[length]);
+ if (index != previous && isIndex(index)) {
+ var previous = index;
+ splice.call(array, index, 1);
+ }
+ }
+ return result;
+ });
+
/**
* Removes all elements from `array` that `predicate` returns truthy for
* and returns an array of the removed elements. The predicate is bound to
- * `thisArg` and invoked with three arguments; (value, index, array).
+ * `thisArg` and 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 a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -5159,18 +5373,18 @@
* be inserted into `array` in order to maintain its sort order. If an iteratee
* function is provided it is invoked for `value` and each element of `array`
* to compute their sort ranking. The iteratee is bound to `thisArg` and
* invoked with one argument; (value).
*
- * If a property name is provided for `predicate` the created `_.property`
+ * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
- * If an object is provided for `predicate` the created `_.matches` style
+ * If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
@@ -5200,16 +5414,11 @@
*
* // using the `_.property` callback shorthand
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
* // => 1
*/
- function sortedIndex(array, value, iteratee, thisArg) {
- var func = getCallback(iteratee);
- return (func === baseCallback && iteratee == null)
- ? binaryIndex(array, value)
- : binaryIndexBy(array, value, func(iteratee, thisArg, 1));
- }
+ var sortedIndex = createSortedIndex();
/**
* This method is like `_.sortedIndex` except that it returns the highest
* index at which `value` should be inserted into `array` in order to
* maintain its sort order.
@@ -5227,16 +5436,11 @@
* @example
*
* _.sortedLastIndex([4, 4, 5, 5], 5);
* // => 4
*/
- function sortedLastIndex(array, value, iteratee, thisArg) {
- var func = getCallback(iteratee);
- return (func === baseCallback && iteratee == null)
- ? binaryIndex(array, value, true)
- : binaryIndexBy(array, value, func(iteratee, thisArg, 1), true);
- }
+ var sortedLastIndex = createSortedIndex(true);
/**
* Creates a slice of `array` with `n` elements taken from the beginning.
*
* @static
@@ -5308,11 +5512,11 @@
}
/**
* Creates a slice of `array` with elements taken from the end. Elements are
* taken until `predicate` returns falsey. The predicate is bound to `thisArg`
- * and invoked with three arguments; (value, index, array).
+ * and 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 a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -5355,23 +5559,19 @@
* // using the `_.property` callback shorthand
* _.pluck(_.takeRightWhile(users, 'active'), 'user');
* // => []
*/
function takeRightWhile(array, predicate, thisArg) {
- var length = array ? array.length : 0;
- if (!length) {
- return [];
- }
- predicate = getCallback(predicate, thisArg, 3);
- while (length-- && predicate(array[length], length, array)) {}
- return baseSlice(array, length + 1);
+ return (array && array.length)
+ ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
+ : [];
}
/**
* Creates a slice of `array` with elements taken from the beginning. Elements
* are taken until `predicate` returns falsey. The predicate is bound to
- * `thisArg` and invoked with three arguments; (value, index, array).
+ * `thisArg` and 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 a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -5414,28 +5614,22 @@
* // using the `_.property` callback shorthand
* _.pluck(_.takeWhile(users, 'active'), 'user');
* // => []
*/
function takeWhile(array, predicate, thisArg) {
- var length = array ? array.length : 0;
- if (!length) {
- return [];
- }
- var index = -1;
- predicate = getCallback(predicate, thisArg, 3);
- while (++index < length && predicate(array[index], index, array)) {}
- return baseSlice(array, 0, index);
+ return (array && array.length)
+ ? baseWhile(array, getCallback(predicate, thisArg, 3))
+ : [];
}
/**
* Creates an array of unique values, in order, of the provided arrays using
* `SameValueZero` for equality comparisons.
*
- * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
- * e.g. `===`, except that `NaN` matches `NaN`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
- * for more details.
+ * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * comparisons are like strict equality comparisons, e.g. `===`, except that
+ * `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
@@ -5443,37 +5637,36 @@
* @example
*
* _.union([1, 2], [4, 2], [2, 1]);
* // => [1, 2, 4]
*/
- function union() {
- return baseUniq(baseFlatten(arguments, false, true, 0));
- }
+ var union = restParam(function(arrays) {
+ return baseUniq(baseFlatten(arrays, false, true));
+ });
/**
* Creates a duplicate-value-free version of an array using `SameValueZero`
* for equality comparisons. Providing `true` for `isSorted` performs a faster
* search algorithm for sorted arrays. If an iteratee function is provided it
* is invoked for each value in the array to generate the criterion by which
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
- * with three arguments; (value, index, array).
+ * with three arguments: (value, index, array).
*
- * If a property name is provided for `predicate` the created `_.property`
+ * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
- * If an object is provided for `predicate` the created `_.matches` style
+ * If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
- * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
- * e.g. `===`, except that `NaN` matches `NaN`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
- * for more details.
+ * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * comparisons are like strict equality comparisons, e.g. `===`, except that
+ * `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @alias unique
* @category Array
@@ -5551,14 +5744,13 @@
/**
* Creates an array excluding all provided values using `SameValueZero` for
* equality comparisons.
*
- * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
- * e.g. `===`, except that `NaN` matches `NaN`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
- * for more details.
+ * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * comparisons are like strict equality comparisons, e.g. `===`, except that
+ * `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to filter.
@@ -5567,18 +5759,19 @@
* @example
*
* _.without([1, 2, 1, 3], 1, 2);
* // => [3]
*/
- function without(array) {
- return baseDifference(array, baseSlice(arguments, 1));
- }
+ var without = restParam(function(array, values) {
+ return (isArray(array) || isArguments(array))
+ ? baseDifference(array, values)
+ : [];
+ });
/**
- * Creates an array that is the symmetric difference of the provided arrays.
- * See [Wikipedia](https://en.wikipedia.org/wiki/Symmetric_difference) for
- * more details.
+ * Creates an array that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
+ * of the provided arrays.
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
@@ -5616,34 +5809,30 @@
* @example
*
* _.zip(['fred', 'barney'], [30, 40], [true, false]);
* // => [['fred', 30, true], ['barney', 40, false]]
*/
- function zip() {
- var length = arguments.length,
- array = Array(length);
+ var zip = restParam(unzip);
- while (length--) {
- array[length] = arguments[length];
- }
- return unzip(array);
- }
-
/**
- * Creates an object composed from arrays of property names and values. Provide
- * either a single two dimensional array, e.g. `[[key1, value1], [key2, value2]]`
- * or two arrays, one of property names and one of corresponding values.
+ * The inverse of `_.pairs`; this method returns an object composed from arrays
+ * of property names and values. Provide either a single two dimensional array,
+ * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
+ * and one of corresponding values.
*
* @static
* @memberOf _
* @alias object
* @category Array
* @param {Array} props The property names.
* @param {Array} [values=[]] The property values.
* @returns {Object} Returns the new object.
* @example
*
+ * _.zipObject([['fred', 30], ['barney', 40]]);
+ * // => { 'fred': 30, 'barney': 40 }
+ *
* _.zipObject(['fred', 'barney'], [30, 40]);
* // => { 'fred': 30, 'barney': 40 }
*/
function zipObject(props, values) {
var index = -1,
@@ -5736,17 +5925,18 @@
* @param {Function} interceptor The function to invoke.
* @param {*} [thisArg] The `this` binding of `interceptor`.
* @returns {*} Returns the result of `interceptor`.
* @example
*
- * _([1, 2, 3])
- * .last()
+ * _(' abc ')
+ * .chain()
+ * .trim()
* .thru(function(value) {
* return [value];
* })
* .value();
- * // => [3]
+ * // => ['abc']
*/
function thru(value, interceptor, thisArg) {
return interceptor.call(thisArg, value);
}
@@ -5932,36 +6122,36 @@
* @example
*
* _.at(['a', 'b', 'c'], [0, 2]);
* // => ['a', 'c']
*
- * _.at(['fred', 'barney', 'pebbles'], 0, 2);
- * // => ['fred', 'pebbles']
+ * _.at(['barney', 'fred', 'pebbles'], 0, 2);
+ * // => ['barney', 'pebbles']
*/
- function at(collection) {
+ var at = restParam(function(collection, props) {
var length = collection ? collection.length : 0;
if (isLength(length)) {
collection = toIterable(collection);
}
- return baseAt(collection, baseFlatten(arguments, false, false, 1));
- }
+ return baseAt(collection, baseFlatten(props));
+ });
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
* of each key is the number of times the key was returned by `iteratee`.
- * The `iteratee` is bound to `thisArg` and invoked with three arguments;
+ * The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
- * If a property name is provided for `predicate` the created `_.property`
+ * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
- * If an object is provided for `predicate` the created `_.matches` style
+ * If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
@@ -5990,11 +6180,11 @@
hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
});
/**
* Checks if `predicate` returns truthy for **all** elements of `collection`.
- * The predicate is bound to `thisArg` and invoked with three arguments;
+ * The predicate is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
@@ -6038,20 +6228,23 @@
* _.every(users, 'active');
* // => false
*/
function every(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayEvery : baseEvery;
+ if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
+ predicate = null;
+ }
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
predicate = getCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
/**
* Iterates over elements of `collection`, returning an array of all elements
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
- * invoked with three arguments; (value, index|key, collection).
+ * invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -6102,11 +6295,11 @@
}
/**
* Iterates over elements of `collection`, returning the first element
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
- * invoked with three arguments; (value, index|key, collection).
+ * invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -6149,18 +6342,11 @@
*
* // using the `_.property` callback shorthand
* _.result(_.find(users, 'active'), 'user');
* // => 'barney'
*/
- function find(collection, predicate, thisArg) {
- if (isArray(collection)) {
- var index = findIndex(collection, predicate, thisArg);
- return index > -1 ? collection[index] : undefined;
- }
- predicate = getCallback(predicate, thisArg, 3);
- return baseFind(collection, predicate, baseEach);
- }
+ var find = createFind(baseEach);
/**
* This method is like `_.find` except that it iterates over elements of
* `collection` from right to left.
*
@@ -6177,14 +6363,11 @@
* _.findLast([1, 2, 3, 4], function(n) {
* return n % 2 == 1;
* });
* // => 3
*/
- function findLast(collection, predicate, thisArg) {
- predicate = getCallback(predicate, thisArg, 3);
- return baseFind(collection, predicate, baseEachRight);
- }
+ var findLast = createFind(baseEachRight, true);
/**
* Performs a deep comparison between each element in `collection` and the
* source object, returning the first element that has equivalent property
* values.
@@ -6217,11 +6400,11 @@
return find(collection, baseMatches(source));
}
/**
* Iterates over elements of `collection` invoking `iteratee` for each element.
- * The `iteratee` is bound to `thisArg` and invoked with three arguments;
+ * The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection). Iterator functions may exit iteration early
* by explicitly returning `false`.
*
* **Note:** As with other "Collections" methods, objects with a `length` property
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
@@ -6245,15 +6428,11 @@
* _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
* console.log(n, key);
* });
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
*/
- function forEach(collection, iteratee, thisArg) {
- return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
- ? arrayEach(collection, iteratee)
- : baseEach(collection, bindCallback(iteratee, thisArg, 3));
- }
+ var forEach = createForEach(arrayEach, baseEach);
/**
* This method is like `_.forEach` except that it iterates over elements of
* `collection` from right to left.
*
@@ -6267,34 +6446,30 @@
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2]).forEachRight(function(n) {
* console.log(n);
- * }).join(',');
+ * }).value();
* // => logs each value from right to left and returns the array
*/
- function forEachRight(collection, iteratee, thisArg) {
- return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
- ? arrayEachRight(collection, iteratee)
- : baseEachRight(collection, bindCallback(iteratee, thisArg, 3));
- }
+ var forEachRight = createForEach(arrayEachRight, baseEachRight);
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
* of each key is an array of the elements responsible for generating the key.
- * The `iteratee` is bound to `thisArg` and invoked with three arguments;
+ * The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
- * If a property name is provided for `predicate` the created `_.property`
+ * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
- * If an object is provided for `predicate` the created `_.matches` style
+ * If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
@@ -6331,22 +6506,22 @@
/**
* Checks if `value` is in `collection` using `SameValueZero` for equality
* comparisons. If `fromIndex` is negative, it is used as the offset from
* the end of `collection`.
*
- * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
- * e.g. `===`, except that `NaN` matches `NaN`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
- * for more details.
+ * **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * comparisons are like strict equality comparisons, e.g. `===`, except that
+ * `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @alias contains, include
* @category Collection
* @param {Array|Object|string} collection The collection to search.
* @param {*} target The value to search for.
* @param {number} [fromIndex=0] The index to search from.
+ * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
* @returns {boolean} Returns `true` if a matching element is found, else `false`.
* @example
*
* _.includes([1, 2, 3], 1);
* // => true
@@ -6358,44 +6533,44 @@
* // => true
*
* _.includes('pebbles', 'eb');
* // => true
*/
- function includes(collection, target, fromIndex) {
+ function includes(collection, target, fromIndex, guard) {
var length = collection ? collection.length : 0;
if (!isLength(length)) {
collection = values(collection);
length = collection.length;
}
if (!length) {
return false;
}
- if (typeof fromIndex == 'number') {
- fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
- } else {
+ if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
fromIndex = 0;
+ } else {
+ fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
}
return (typeof collection == 'string' || !isArray(collection) && isString(collection))
? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)
: (getIndexOf(collection, target, fromIndex) > -1);
}
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
* of each key is the last element responsible for generating the key. The
- * iteratee function is bound to `thisArg` and invoked with three arguments;
+ * iteratee function is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
- * If a property name is provided for `predicate` the created `_.property`
+ * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
- * If an object is provided for `predicate` the created `_.matches` style
+ * If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
@@ -6449,38 +6624,47 @@
* // => [[1, 5, 7], [1, 2, 3]]
*
* _.invoke([123, 456], String.prototype.split, '');
* // => [['1', '2', '3'], ['4', '5', '6']]
*/
- function invoke(collection, methodName) {
- return baseInvoke(collection, methodName, baseSlice(arguments, 2));
- }
+ var invoke = restParam(function(collection, methodName, args) {
+ var index = -1,
+ isFunc = typeof methodName == 'function',
+ length = collection ? collection.length : 0,
+ result = isLength(length) ? Array(length) : [];
+ baseEach(collection, function(value) {
+ var func = isFunc ? methodName : (value != null && value[methodName]);
+ result[++index] = func ? func.apply(value, args) : undefined;
+ });
+ return result;
+ });
+
/**
* Creates an array of values by running each element in `collection` through
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
- * arguments; (value, index|key, collection).
+ * arguments: (value, index|key, collection).
*
- * If a property name is provided for `predicate` the created `_.property`
+ * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
- * If an object is provided for `predicate` the created `_.matches` style
+ * If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* Many lodash methods are guarded to work as interatees for methods like
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
*
* The guarded methods are:
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
- * `dropRight`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, `slice`,
- * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, `trimRight`,
- * `trunc`, `random`, `range`, `sample`, `uniq`, and `words`
+ * `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`,
+ * `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`,
+ * `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words`
*
* @static
* @memberOf _
* @alias collect
* @category Collection
@@ -6519,11 +6703,11 @@
/**
* Creates an array of elements split into two groups, the first of which
* contains elements `predicate` returns truthy for, while the second of which
* contains elements `predicate` returns falsey for. The predicate is bound
- * to `thisArg` and invoked with three arguments; (value, index|key, collection).
+ * to `thisArg` and invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -6610,18 +6794,18 @@
/**
* Reduces `collection` to a value which is the accumulated result of running
* each element in `collection` through `iteratee`, where each successive
* invocation is supplied the return value of the previous. If `accumulator`
* is not provided the first element of `collection` is used as the initial
- * value. The `iteratee` is bound to `thisArg`and invoked with four arguments;
+ * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
* (accumulator, value, index|key, collection).
*
* Many lodash methods are guarded to work as interatees for methods like
* `_.reduce`, `_.reduceRight`, and `_.transform`.
*
* The guarded methods are:
- * `assign`, `defaults`, `merge`, and `sortAllBy`
+ * `assign`, `defaults`, `includes`, `merge`, `sortByAll`, and `sortByOrder`
*
* @static
* @memberOf _
* @alias foldl, inject
* @category Collection
@@ -6641,14 +6825,11 @@
* result[key] = n * 3;
* return result;
* }, {});
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
*/
- function reduce(collection, iteratee, accumulator, thisArg) {
- var func = isArray(collection) ? arrayReduce : baseReduce;
- return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEach);
- }
+ var reduce = createReduce(arrayReduce, baseEach);
/**
* This method is like `_.reduce` except that it iterates over elements of
* `collection` from right to left.
*
@@ -6668,14 +6849,11 @@
* _.reduceRight(array, function(flattened, other) {
* return flattened.concat(other);
* }, []);
* // => [4, 5, 2, 3, 0, 1]
*/
- function reduceRight(collection, iteratee, accumulator, thisArg) {
- var func = isArray(collection) ? arrayReduceRight : baseReduce;
- return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEachRight);
- }
+ var reduceRight = createReduce(arrayReduceRight, baseEachRight);
/**
* The opposite of `_.filter`; this method returns the elements of `collection`
* that `predicate` does **not** return truthy for.
*
@@ -6758,13 +6936,12 @@
result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
return result;
}
/**
- * Creates an array of shuffled values, using a version of the Fisher-Yates
- * shuffle. See [Wikipedia](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle)
- * for more details.
+ * Creates an array of shuffled values, using a version of the
+ * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to shuffle.
@@ -6818,11 +6995,11 @@
/**
* Checks if `predicate` returns truthy for **any** element of `collection`.
* The function returns as soon as it finds a passing value and does not iterate
* over the entire collection. The predicate is bound to `thisArg` and invoked
- * with three arguments; (value, index|key, collection).
+ * with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -6865,31 +7042,34 @@
* _.some(users, 'active');
* // => true
*/
function some(collection, predicate, thisArg) {
var func = isArray(collection) ? arraySome : baseSome;
+ if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
+ predicate = null;
+ }
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
predicate = getCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
/**
* Creates an array of elements, sorted in ascending order by the results of
* running each element in a collection through `iteratee`. This method performs
* a stable sort, that is, it preserves the original sort order of equal elements.
- * The `iteratee` is bound to `thisArg` and invoked with three arguments;
+ * The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
- * If a property name is provided for `predicate` the created `_.property`
+ * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
- * If an object is provided for `predicate` the created `_.matches` style
+ * If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
@@ -6961,21 +7141,28 @@
* ];
*
* _.map(_.sortByAll(users, ['user', 'age']), _.values);
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
*/
- function sortByAll(collection) {
+ function sortByAll() {
+ var args = arguments,
+ collection = args[0],
+ guard = args[3],
+ index = 0,
+ length = args.length - 1;
+
if (collection == null) {
return [];
}
- var args = arguments,
- guard = args[3];
-
+ var props = Array(length);
+ while (index < length) {
+ props[index] = args[++index];
+ }
if (guard && isIterateeCall(args[1], args[2], guard)) {
- args = [collection, args[1]];
+ props = args[1];
}
- return baseSortByOrder(collection, baseFlatten(args, false, false, 1), []);
+ return baseSortByOrder(collection, baseFlatten(props), []);
}
/**
* This method is like `_.sortByAll` except that it allows specifying the
* sort orders of the property names to sort by. A truthy value in `orders`
@@ -7190,11 +7377,11 @@
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to bind.
* @param {*} thisArg The `this` binding of `func`.
- * @param {...*} [args] The arguments to be partially applied.
+ * @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* var greet = function(greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
@@ -7209,20 +7396,18 @@
* // using placeholders
* var bound = _.bind(greet, object, _, '!');
* bound('hi');
* // => 'hi fred!'
*/
- function bind(func, thisArg) {
+ var bind = restParam(function(func, thisArg, partials) {
var bitmask = BIND_FLAG;
- if (arguments.length > 2) {
- var partials = baseSlice(arguments, 2),
- holders = replaceHolders(partials, bind.placeholder);
-
+ if (partials.length) {
+ var holders = replaceHolders(partials, bind.placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(func, bitmask, thisArg, partials, holders);
- }
+ });
/**
* Binds methods of an object to the object itself, overwriting the existing
* method. Method names may be specified as individual arguments or as arrays
* of method names. If no method names are provided all enumerable function
@@ -7248,18 +7433,23 @@
*
* _.bindAll(view);
* jQuery('#docs').on('click', view.onClick);
* // => logs 'clicked docs' when the element is clicked
*/
- function bindAll(object) {
- return baseBindAll(object,
- arguments.length > 1
- ? baseFlatten(arguments, false, false, 1)
- : functions(object)
- );
- }
+ var bindAll = restParam(function(object, methodNames) {
+ methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
+ var index = -1,
+ length = methodNames.length;
+
+ while (++index < length) {
+ var key = methodNames[index];
+ object[key] = createWrapper(object[key], BIND_FLAG, object);
+ }
+ return object;
+ });
+
/**
* Creates a function that invokes the method at `object[key]` and prepends
* any additional `_.bindKey` arguments to those provided to the bound function.
*
* This method differs from `_.bind` by allowing bound functions to reference
@@ -7273,11 +7463,11 @@
* @static
* @memberOf _
* @category Function
* @param {Object} object The object the method belongs to.
* @param {string} key The key of the method.
- * @param {...*} [args] The arguments to be partially applied.
+ * @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* var object = {
* 'user': 'fred',
@@ -7300,20 +7490,18 @@
* // using placeholders
* var bound = _.bindKey(object, 'greet', _, '!');
* bound('hi');
* // => 'hiya fred!'
*/
- function bindKey(object, key) {
+ var bindKey = restParam(function(object, key, partials) {
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
- if (arguments.length > 2) {
- var partials = baseSlice(arguments, 2),
- holders = replaceHolders(partials, bindKey.placeholder);
-
+ if (partials.length) {
+ var holders = replaceHolders(partials, bindKey.placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(key, bitmask, object, partials, holders);
- }
+ });
/**
* Creates a function that accepts one or more arguments of `func` that when
* called either invokes `func` returning its result, if all `func` arguments
* have been provided, or returns a function that accepts one or more of the
@@ -7351,18 +7539,11 @@
*
* // using placeholders
* curried(1)(_, 3)(2);
* // => [1, 2, 3]
*/
- function curry(func, arity, guard) {
- if (guard && isIterateeCall(func, arity, guard)) {
- arity = null;
- }
- var result = createWrapper(func, CURRY_FLAG, null, null, null, null, null, arity);
- result.placeholder = curry.placeholder;
- return result;
- }
+ var curry = createCurry(CURRY_FLAG);
/**
* This method is like `_.curry` except that arguments are applied to `func`
* in the manner of `_.partialRight` instead of `_.partial`.
*
@@ -7397,18 +7578,11 @@
*
* // using placeholders
* curried(3)(1, _)(2);
* // => [1, 2, 3]
*/
- function curryRight(func, arity, guard) {
- if (guard && isIterateeCall(func, arity, guard)) {
- arity = null;
- }
- var result = createWrapper(func, CURRY_RIGHT_FLAG, null, null, null, null, null, arity);
- result.placeholder = curryRight.placeholder;
- return result;
- }
+ var curryRight = createCurry(CURRY_RIGHT_FLAG);
/**
* Creates a function that delays invoking `func` until after `wait` milliseconds
* have elapsed since the last time it was invoked. The created function comes
* with a `cancel` method to cancel delayed invocations. Provide an options
@@ -7599,13 +7773,13 @@
* _.defer(function(text) {
* console.log(text);
* }, 'deferred');
* // logs 'deferred' after one or more milliseconds
*/
- function defer(func) {
- return baseDelay(func, 1, arguments, 1);
- }
+ var defer = restParam(function(func, args) {
+ return baseDelay(func, 1, args);
+ });
/**
* Invokes `func` after `wait` milliseconds. Any additional arguments are
* provided to `func` when it is invoked.
*
@@ -7621,13 +7795,13 @@
* _.delay(function(text) {
* console.log(text);
* }, 1000, 'later');
* // => logs 'later' after one second
*/
- function delay(func, wait) {
- return baseDelay(func, wait, arguments, 2);
- }
+ var delay = restParam(function(func, wait, args) {
+ return baseDelay(func, wait, args);
+ });
/**
* Creates a function that returns the result of invoking the provided
* functions with the `this` binding of the created function, where each
* successive invocation is supplied the return value of the previous.
@@ -7645,11 +7819,11 @@
*
* var addSquare = _.flow(_.add, square);
* addSquare(1, 2);
* // => 9
*/
- var flow = createComposer();
+ var flow = createFlow();
/**
* This method is like `_.flow` except that it creates a function that
* invokes the provided functions from right to left.
*
@@ -7667,11 +7841,11 @@
*
* var addSquare = _.flowRight(square, _.add);
* addSquare(1, 2);
* // => 9
*/
- var flowRight = createComposer(true);
+ var flowRight = createFlow(true);
/**
* Creates a function that memoizes the result of `func`. If `resolver` is
* provided it determines the cache key for storing the result based on the
* arguments provided to the memoized function. By default, the first argument
@@ -7679,14 +7853,12 @@
* cache key. The `func` is invoked with the `this` binding of the memoized
* function.
*
* **Note:** The cache is exposed as the `cache` property on the memoized
* function. Its creation may be customized by replacing the `_.memoize.Cache`
- * constructor with one whose instances implement the ES `Map` method interface
- * of `get`, `has`, and `set`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
- * for more details.
+ * constructor with one whose instances implement the [`Map`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
+ * method interface of `get`, `has`, and `set`.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to have its output memoized.
@@ -7773,11 +7945,11 @@
}
/**
* Creates a function that is restricted to invoking `func` once. Repeat calls
* to the function return the value of the first call. The `func` is invoked
- * with the `this` binding of the created function.
+ * with the `this` binding and arguments of the created function.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to restrict.
@@ -7806,11 +7978,11 @@
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to partially apply arguments to.
- * @param {...*} [args] The arguments to be partially applied.
+ * @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
* var greet = function(greeting, name) {
* return greeting + ' ' + name;
@@ -7823,17 +7995,12 @@
* // using placeholders
* var greetFred = _.partial(greet, _, 'fred');
* greetFred('hi');
* // => 'hi fred'
*/
- function partial(func) {
- var partials = baseSlice(arguments, 1),
- holders = replaceHolders(partials, partial.placeholder);
+ var partial = createPartial(PARTIAL_FLAG);
- return createWrapper(func, PARTIAL_FLAG, null, partials, holders);
- }
-
/**
* This method is like `_.partial` except that partially applied arguments
* are appended to those provided to the new function.
*
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
@@ -7844,11 +8011,11 @@
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to partially apply arguments to.
- * @param {...*} [args] The arguments to be partially applied.
+ * @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
* var greet = function(greeting, name) {
* return greeting + ' ' + name;
@@ -7861,17 +8028,12 @@
* // using placeholders
* var sayHelloTo = _.partialRight(greet, 'hello', _);
* sayHelloTo('fred');
* // => 'hello fred'
*/
- function partialRight(func) {
- var partials = baseSlice(arguments, 1),
- holders = replaceHolders(partials, partialRight.placeholder);
+ var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
- return createWrapper(func, PARTIAL_RIGHT_FLAG, null, partials, holders);
- }
-
/**
* Creates a function that invokes `func` with arguments arranged according
* to the specified indexes where the argument value at the first index is
* provided as the first argument, the argument value at the second index is
* provided as the second argument, and so on.
@@ -7896,33 +8058,84 @@
* map(function(n) {
* return n * 3;
* }, [1, 2, 3]);
* // => [3, 6, 9]
*/
- function rearg(func) {
- var indexes = baseFlatten(arguments, false, false, 1);
- return createWrapper(func, REARG_FLAG, null, null, null, indexes);
- }
+ var rearg = restParam(function(func, indexes) {
+ return createWrapper(func, REARG_FLAG, null, null, null, baseFlatten(indexes));
+ });
/**
* Creates a function that invokes `func` with the `this` binding of the
- * created function and the array of arguments provided to the created
- * function much like [Function#apply](http://es5.github.io/#x15.3.4.3).
+ * created function and arguments from `start` and beyond provided as an array.
*
+ * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
+ *
* @static
* @memberOf _
* @category Function
+ * @param {Function} func The function to apply a rest parameter to.
+ * @param {number} [start=func.length-1] The start position of the rest parameter.
+ * @returns {Function} Returns the new function.
+ * @example
+ *
+ * var say = _.restParam(function(what, names) {
+ * return what + ' ' + _.initial(names).join(', ') +
+ * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
+ * });
+ *
+ * say('hello', 'fred', 'barney', 'pebbles');
+ * // => 'hello fred, barney, & pebbles'
+ */
+ function restParam(func, start) {
+ if (typeof func != 'function') {
+ throw new TypeError(FUNC_ERROR_TEXT);
+ }
+ start = nativeMax(typeof start == 'undefined' ? (func.length - 1) : (+start || 0), 0);
+ return function() {
+ var args = arguments,
+ index = -1,
+ length = nativeMax(args.length - start, 0),
+ rest = Array(length);
+
+ while (++index < length) {
+ rest[index] = args[start + index];
+ }
+ switch (start) {
+ case 0: return func.call(this, rest);
+ case 1: return func.call(this, args[0], rest);
+ case 2: return func.call(this, args[0], args[1], rest);
+ }
+ var otherArgs = Array(start + 1);
+ index = -1;
+ while (++index < start) {
+ otherArgs[index] = args[index];
+ }
+ otherArgs[start] = rest;
+ return func.apply(this, otherArgs);
+ };
+ }
+
+ /**
+ * Creates a function that invokes `func` with the `this` binding of the created
+ * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
+ *
+ * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
+ *
+ * @static
+ * @memberOf _
+ * @category Function
* @param {Function} func The function to spread arguments over.
- * @returns {*} Returns the new function.
+ * @returns {Function} Returns the new function.
* @example
*
- * var spread = _.spread(function(who, what) {
+ * var say = _.spread(function(who, what) {
* return who + ' says ' + what;
* });
*
- * spread(['Fred', 'hello']);
- * // => 'Fred says hello'
+ * say(['fred', 'hello']);
+ * // => 'fred says hello'
*
* // with a Promise
* var numbers = Promise.all([
* Promise.resolve(40),
* Promise.resolve(36)
@@ -8033,16 +8246,16 @@
* otherwise they are assigned by reference. If `customizer` is provided it is
* invoked to produce the cloned values. If `customizer` returns `undefined`
* cloning is handled by the method instead. The `customizer` is bound to
* `thisArg` and invoked with two argument; (value [, index|key, object]).
*
- * **Note:** This method is loosely based on the structured clone algorithm.
+ * **Note:** This method is loosely based on the
+ * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
* The enumerable properties of `arguments` objects and objects created by
* constructors other than `Object` are cloned to plain `Object` objects. An
* empty object is returned for uncloneable values such as functions, DOM nodes,
- * Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm)
- * for more details.
+ * Maps, Sets, and WeakMaps.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to clone.
@@ -8096,16 +8309,16 @@
* Creates a deep clone of `value`. If `customizer` is provided it is invoked
* to produce the cloned values. If `customizer` returns `undefined` cloning
* is handled by the method instead. The `customizer` is bound to `thisArg`
* and invoked with two argument; (value [, index|key, object]).
*
- * **Note:** This method is loosely based on the structured clone algorithm.
+ * **Note:** This method is loosely based on the
+ * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
* The enumerable properties of `arguments` objects and objects created by
* constructors other than `Object` are cloned to plain `Object` objects. An
* empty object is returned for uncloneable values such as functions, DOM nodes,
- * Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm)
- * for more details.
+ * Maps, Sets, and WeakMaps.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to deep clone.
@@ -8158,18 +8371,18 @@
* _.isArguments([1, 2, 3]);
* // => false
*/
function isArguments(value) {
var length = isObjectLike(value) ? value.length : undefined;
- return (isLength(length) && objToString.call(value) == argsTag) || false;
+ return isLength(length) && objToString.call(value) == argsTag;
}
// Fallback for environments without a `toStringTag` for `arguments` objects.
if (!support.argsTag) {
isArguments = function(value) {
var length = isObjectLike(value) ? value.length : undefined;
- return (isLength(length) && hasOwnProperty.call(value, 'callee') &&
- !propertyIsEnumerable.call(value, 'callee')) || false;
+ return isLength(length) && hasOwnProperty.call(value, 'callee') &&
+ !propertyIsEnumerable.call(value, 'callee');
};
}
/**
* Checks if `value` is classified as an `Array` object.
@@ -8186,11 +8399,11 @@
*
* _.isArray(function() { return arguments; }());
* // => false
*/
var isArray = nativeIsArray || function(value) {
- return (isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag) || false;
+ return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
};
/**
* Checks if `value` is classified as a boolean primitive or object.
*
@@ -8206,11 +8419,11 @@
*
* _.isBoolean(null);
* // => false
*/
function isBoolean(value) {
- return (value === true || value === false || isObjectLike(value) && objToString.call(value) == boolTag) || false;
+ return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
}
/**
* Checks if `value` is classified as a `Date` object.
*
@@ -8226,11 +8439,11 @@
*
* _.isDate('Mon April 23 2012');
* // => false
*/
function isDate(value) {
- return (isObjectLike(value) && objToString.call(value) == dateTag) || false;
+ return isObjectLike(value) && objToString.call(value) == dateTag;
}
/**
* Checks if `value` is a DOM element.
*
@@ -8246,17 +8459,17 @@
*
* _.isElement('<body>');
* // => false
*/
function isElement(value) {
- return (value && value.nodeType === 1 && isObjectLike(value) &&
- (lodash.support.nodeTag ? (objToString.call(value).indexOf('Element') > -1) : isHostObject(value))) || false;
+ return !!value && value.nodeType === 1 && isObjectLike(value) &&
+ (lodash.support.nodeTag ? (objToString.call(value).indexOf('Element') > -1) : isHostObject(value));
}
// Fallback for environments without DOM support.
if (!support.dom) {
isElement = function(value) {
- return (value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value)) || false;
+ return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
};
}
/**
* Checks if `value` is empty. A value is considered empty unless it is an
@@ -8300,11 +8513,11 @@
/**
* Performs a deep comparison between two values to determine if they are
* equivalent. If `customizer` is provided it is invoked to compare values.
* If `customizer` returns `undefined` comparisons are handled by the method
* instead. The `customizer` is bound to `thisArg` and invoked with three
- * arguments; (value, other [, index|key]).
+ * arguments: (value, other [, index|key]).
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. Functions and DOM nodes
* are **not** supported. Provide a customizer function to extend support
@@ -8365,19 +8578,17 @@
*
* _.isError(Error);
* // => false
*/
function isError(value) {
- return (isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag) || false;
+ return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
}
/**
* Checks if `value` is a finite primitive number.
*
- * **Note:** This method is based on ES `Number.isFinite`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite)
- * for more details.
+ * **Note:** This method is based on [`Number.isFinite`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite).
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
@@ -8425,15 +8636,13 @@
// and Safari 8 equivalents which return 'object' for typed array constructors.
return objToString.call(value) == funcTag;
};
/**
- * Checks if `value` is the language type of `Object`.
+ * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
- * **Note:** See the [ES5 spec](https://es5.github.io/#x8) for more details.
- *
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
@@ -8450,19 +8659,19 @@
*/
function isObject(value) {
// Avoid a V8 JIT bug in Chrome 19-20.
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
var type = typeof value;
- return type == 'function' || (value && type == 'object') || false;
+ return type == 'function' || (!!value && type == 'object');
}
/**
* Performs a deep comparison between `object` and `source` to determine if
* `object` contains equivalent property values. If `customizer` is provided
* it is invoked to compare values. If `customizer` returns `undefined`
* comparisons are handled by the method instead. The `customizer` is bound
- * to `thisArg` and invoked with three arguments; (value, other, index|key).
+ * to `thisArg` and invoked with three arguments: (value, other, index|key).
*
* **Note:** This method supports comparing properties of arrays, booleans,
* `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
* and DOM nodes are **not** supported. Provide a customizer function to extend
* support for comparing other values.
@@ -8496,35 +8705,40 @@
*/
function isMatch(object, source, customizer, thisArg) {
var props = keys(source),
length = props.length;
+ if (!length) {
+ return true;
+ }
+ if (object == null) {
+ return false;
+ }
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
if (!customizer && length == 1) {
var key = props[0],
value = source[key];
if (isStrictComparable(value)) {
- return object != null && value === object[key] && hasOwnProperty.call(object, key);
+ return value === object[key] && (typeof value != 'undefined' || (key in toObject(object)));
}
}
var values = Array(length),
strictCompareFlags = Array(length);
while (length--) {
value = values[length] = source[props[length]];
strictCompareFlags[length] = isStrictComparable(value);
}
- return baseIsMatch(object, props, values, strictCompareFlags, customizer);
+ return baseIsMatch(toObject(object), props, values, strictCompareFlags, customizer);
}
/**
* Checks if `value` is `NaN`.
*
- * **Note:** This method is not the same as native `isNaN` which returns `true`
- * for `undefined` and other non-numeric values. See the [ES5 spec](https://es5.github.io/#x15.1.2.4)
- * for more details.
+ * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
+ * which returns `true` for `undefined` and other non-numeric values.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
@@ -8570,12 +8784,11 @@
return false;
}
if (objToString.call(value) == funcTag) {
return reNative.test(fnToString.call(value));
}
- return (isObjectLike(value) &&
- (isHostObject(value) ? reNative : reHostCtor).test(value)) || false;
+ return isObjectLike(value) && (isHostObject(value) ? reNative : reHostCtor).test(value);
}
/**
* Checks if `value` is `null`.
*
@@ -8617,11 +8830,11 @@
*
* _.isNumber('8.4');
* // => false
*/
function isNumber(value) {
- return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag) || false;
+ return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
}
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
@@ -8679,11 +8892,11 @@
*
* _.isRegExp('/abc/');
* // => false
*/
function isRegExp(value) {
- return (isObject(value) && objToString.call(value) == regexpTag) || false;
+ return isObject(value) && objToString.call(value) == regexpTag;
}
/**
* Checks if `value` is classified as a `String` primitive or object.
*
@@ -8699,11 +8912,11 @@
*
* _.isString(1);
* // => false
*/
function isString(value) {
- return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag) || false;
+ return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
}
/**
* Checks if `value` is classified as a typed array.
*
@@ -8719,11 +8932,11 @@
*
* _.isTypedArray([]);
* // => false
*/
function isTypedArray(value) {
- return (isObjectLike(value) && isLength(value.length) && typedArrayTags[objToString.call(value)]) || false;
+ return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
}
/**
* Checks if `value` is `undefined`.
*
@@ -8803,11 +9016,11 @@
/**
* Assigns own enumerable properties of source object(s) to the destination
* object. Subsequent sources overwrite property assignments of previous sources.
* If `customizer` is provided it is invoked to produce the assigned values.
- * The `customizer` is bound to `thisArg` and invoked with five arguments;
+ * The `customizer` is bound to `thisArg` and invoked with five arguments:
* (objectValue, sourceValue, key, object, source).
*
* @static
* @memberOf _
* @alias extend
@@ -8888,22 +9101,22 @@
* @example
*
* _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
* // => { 'user': 'barney', 'age': 36 }
*/
- function defaults(object) {
+ var defaults = restParam(function(args) {
+ var object = args[0];
if (object == null) {
return object;
}
- var args = arrayCopy(arguments);
args.push(assignDefaults);
return assign.apply(undefined, args);
- }
+ });
/**
- * This method is like `_.findIndex` except that it returns the key of the
- * first element `predicate` returns truthy for, instead of the element itself.
+ * This method is like `_.find` except that it returns the key of the first
+ * 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 a value is also provided for `thisArg` the created `_.matchesProperty`
@@ -8945,14 +9158,11 @@
*
* // using the `_.property` callback shorthand
* _.findKey(users, 'active');
* // => 'barney'
*/
- function findKey(object, predicate, thisArg) {
- predicate = getCallback(predicate, thisArg, 3);
- return baseFind(object, predicate, baseForOwn, true);
- }
+ var findKey = createFindKey(baseForOwn);
/**
* This method is like `_.findKey` except that it iterates over elements of
* a collection in the opposite order.
*
@@ -8998,19 +9208,16 @@
*
* // using the `_.property` callback shorthand
* _.findLastKey(users, 'active');
* // => 'pebbles'
*/
- function findLastKey(object, predicate, thisArg) {
- predicate = getCallback(predicate, thisArg, 3);
- return baseFind(object, predicate, baseForOwnRight, true);
- }
+ var findLastKey = createFindKey(baseForOwnRight);
/**
* Iterates over own and inherited enumerable properties of an object invoking
* `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
- * with three arguments; (value, key, object). Iterator functions may exit
+ * with three arguments: (value, key, object). Iterator functions may exit
* iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Object
@@ -9030,16 +9237,11 @@
* _.forIn(new Foo, function(value, key) {
* console.log(key);
* });
* // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
*/
- function forIn(object, iteratee, thisArg) {
- if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
- iteratee = bindCallback(iteratee, thisArg, 3);
- }
- return baseFor(object, iteratee, keysIn);
- }
+ var forIn = createForIn(baseFor);
/**
* This method is like `_.forIn` except that it iterates over properties of
* `object` in the opposite order.
*
@@ -9062,19 +9264,16 @@
* _.forInRight(new Foo, function(value, key) {
* console.log(key);
* });
* // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
*/
- function forInRight(object, iteratee, thisArg) {
- iteratee = bindCallback(iteratee, thisArg, 3);
- return baseForRight(object, iteratee, keysIn);
- }
+ var forInRight = createForIn(baseForRight);
/**
* Iterates over own enumerable properties of an object invoking `iteratee`
* for each property. The `iteratee` is bound to `thisArg` and invoked with
- * three arguments; (value, key, object). Iterator functions may exit iteration
+ * three arguments: (value, key, object). Iterator functions may exit iteration
* early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Object
@@ -9094,16 +9293,11 @@
* _.forOwn(new Foo, function(value, key) {
* console.log(key);
* });
* // => logs 'a' and 'b' (iteration order is not guaranteed)
*/
- function forOwn(object, iteratee, thisArg) {
- if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
- iteratee = bindCallback(iteratee, thisArg, 3);
- }
- return baseForOwn(object, iteratee);
- }
+ var forOwn = createForOwn(baseForOwn);
/**
* This method is like `_.forOwn` except that it iterates over properties of
* `object` in the opposite order.
*
@@ -9126,14 +9320,11 @@
* _.forOwnRight(new Foo, function(value, key) {
* console.log(key);
* });
* // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
*/
- function forOwnRight(object, iteratee, thisArg) {
- iteratee = bindCallback(iteratee, thisArg, 3);
- return baseForRight(object, iteratee, keys);
- }
+ var forOwnRight = createForOwn(baseForOwnRight);
/**
* Creates an array of function property names from all enumerable properties,
* own and inherited, of `object`.
*
@@ -9343,11 +9534,11 @@
}
/**
* Creates an object with the same keys as `object` and values generated by
* running each own enumerable property of `object` through `iteratee`. The
- * iteratee function is bound to `thisArg` and invoked with three arguments;
+ * iteratee function is bound to `thisArg` and invoked with three arguments:
* (value, key, object).
*
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
@@ -9398,11 +9589,11 @@
* don't resolve to `undefined` into the destination object. Subsequent sources
* overwrite property assignments of previous sources. If `customizer` is
* provided it is invoked to produce the merged values of the destination and
* source properties. If `customizer` returns `undefined` merging is handled
* by the method instead. The `customizer` is bound to `thisArg` and invoked
- * with five arguments; (objectValue, sourceValue, key, object, source).
+ * with five arguments: (objectValue, sourceValue, key, object, source).
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The destination object.
@@ -9447,11 +9638,11 @@
* The opposite of `_.pick`; this method creates an object composed of the
* own and inherited enumerable properties of `object` that are not omitted.
* Property names may be specified as individual arguments or as arrays of
* property names. If `predicate` is provided it is invoked for each property
* of `object` omitting the properties `predicate` returns truthy for. The
- * predicate is bound to `thisArg` and invoked with three arguments;
+ * predicate is bound to `thisArg` and invoked with three arguments:
* (value, key, object).
*
* @static
* @memberOf _
* @category Object
@@ -9469,23 +9660,23 @@
* // => { 'user': 'fred' }
*
* _.omit(object, _.isNumber);
* // => { 'user': 'fred' }
*/
- function omit(object, predicate, thisArg) {
+ var omit = restParam(function(object, props) {
if (object == null) {
return {};
}
- if (typeof predicate != 'function') {
- var props = arrayMap(baseFlatten(arguments, false, false, 1), String);
+ if (typeof props[0] != 'function') {
+ var props = arrayMap(baseFlatten(props), String);
return pickByArray(object, baseDifference(keysIn(object), props));
}
- predicate = bindCallback(predicate, thisArg, 3);
+ var predicate = bindCallback(props[0], props[1], 3);
return pickByCallback(object, function(value, key, object) {
return !predicate(value, key, object);
});
- }
+ });
/**
* Creates a two dimensional array of the key-value pairs for `object`,
* e.g. `[[key1, value1], [key2, value2]]`.
*
@@ -9515,11 +9706,11 @@
/**
* Creates an object composed of the picked `object` properties. Property
* names may be specified as individual arguments or as arrays of property
* names. If `predicate` is provided it is invoked for each property of `object`
* picking the properties `predicate` returns truthy for. The predicate is
- * bound to `thisArg` and invoked with three arguments; (value, key, object).
+ * bound to `thisArg` and invoked with three arguments: (value, key, object).
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The source object.
@@ -9536,18 +9727,18 @@
* // => { 'user': 'fred' }
*
* _.pick(object, _.isString);
* // => { 'user': 'fred' }
*/
- function pick(object, predicate, thisArg) {
+ var pick = restParam(function(object, props) {
if (object == null) {
return {};
}
- return typeof predicate == 'function'
- ? pickByCallback(object, bindCallback(predicate, thisArg, 3))
- : pickByArray(object, baseFlatten(arguments, false, false, 1));
- }
+ return typeof props[0] == 'function'
+ ? pickByCallback(object, bindCallback(props[0], props[1], 3))
+ : pickByArray(object, baseFlatten(props));
+ });
/**
* Resolves the value of property `key` on `object`. If the value of `key` is
* a function it is invoked with the `this` binding of `object` and its result
* is returned, else the property value is returned. If the property value is
@@ -9588,11 +9779,11 @@
/**
* An alternative to `_.reduce`; this method transforms `object` to a new
* `accumulator` object which is the result of running each of its own enumerable
* properties through `iteratee`, with each invocation potentially mutating
* the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
- * with four arguments; (accumulator, value, key, object). Iterator functions
+ * with four arguments: (accumulator, value, key, object). Iterator functions
* may exit iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Object
@@ -9799,12 +9990,11 @@
}
/*------------------------------------------------------------------------*/
/**
- * Converts `string` to camel case.
- * See [Wikipedia](https://en.wikipedia.org/wiki/CamelCase) for more details.
+ * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
@@ -9842,13 +10032,12 @@
string = baseToString(string);
return string && (string.charAt(0).toUpperCase() + string.slice(1));
}
/**
- * Deburrs `string` by converting latin-1 supplementary letters to basic latin letters.
- * See [Wikipedia](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
- * for more details.
+ * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
+ * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to deburr.
@@ -9858,11 +10047,11 @@
* _.deburr('déjà vu');
* // => 'deja vu'
*/
function deburr(string) {
string = baseToString(string);
- return string && string.replace(reLatin1, deburrLetter);
+ return string && string.replace(reLatin1, deburrLetter).replace(reComboMarks, '');
}
/**
* Checks if `string` ends with the given target string.
*
@@ -9913,13 +10102,12 @@
* Backticks are escaped because in Internet Explorer < 9, they can break out
* of attribute values or HTML comments. See [#102](https://html5sec.org/#102),
* [#108](https://html5sec.org/#108), and [#133](https://html5sec.org/#133) of
* the [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
*
- * When working with HTML you should always quote attribute values to reduce
- * XSS vectors. See [Ryan Grove's article](http://wonko.com/post/html-escaping)
- * for more details.
+ * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
+ * to reduce XSS vectors.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to escape.
@@ -9936,34 +10124,32 @@
? string.replace(reUnescapedHtml, escapeHtmlChar)
: string;
}
/**
- * Escapes the `RegExp` special characters "\", "^", "$", ".", "|", "?", "*",
- * "+", "(", ")", "[", "]", "{" and "}" in `string`.
+ * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
+ * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to escape.
* @returns {string} Returns the escaped string.
* @example
*
* _.escapeRegExp('[lodash](https://lodash.com/)');
- * // => '\[lodash\]\(https://lodash\.com/\)'
+ * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
*/
function escapeRegExp(string) {
string = baseToString(string);
return (string && reHasRegExpChars.test(string))
? string.replace(reRegExpChars, '\\$&')
: string;
}
/**
- * Converts `string` to kebab case.
- * See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for
- * more details.
+ * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
@@ -9982,13 +10168,12 @@
var kebabCase = createCompounder(function(result, word, index) {
return result + (index ? '-' : '') + word.toLowerCase();
});
/**
- * Pads `string` on the left and right sides if it is shorter then the given
- * padding length. The `chars` string may be truncated if the number of padding
- * characters can't be evenly divided by the padding length.
+ * Pads `string` on the left and right sides if it is shorter than `length`.
+ * Padding characters are truncated if they can't be evenly divided by `length`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to pad.
@@ -10016,18 +10201,17 @@
}
var mid = (length - strLength) / 2,
leftLength = floor(mid),
rightLength = ceil(mid);
- chars = createPad('', rightLength, chars);
+ chars = createPadding('', rightLength, chars);
return chars.slice(0, leftLength) + string + chars;
}
/**
- * Pads `string` on the left side if it is shorter then the given padding
- * length. The `chars` string may be truncated if the number of padding
- * characters exceeds the padding length.
+ * Pads `string` on the left side if it is shorter than `length`. Padding
+ * characters are truncated if they exceed `length`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to pad.
@@ -10043,19 +10227,15 @@
* // => '_-_abc'
*
* _.padLeft('abc', 3);
* // => 'abc'
*/
- function padLeft(string, length, chars) {
- string = baseToString(string);
- return string && (createPad(string, length, chars) + string);
- }
+ var padLeft = createPadDir();
/**
- * Pads `string` on the right side if it is shorter then the given padding
- * length. The `chars` string may be truncated if the number of padding
- * characters exceeds the padding length.
+ * Pads `string` on the right side if it is shorter than `length`. Padding
+ * characters are truncated if they exceed `length`.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to pad.
@@ -10071,22 +10251,19 @@
* // => 'abc_-_'
*
* _.padRight('abc', 3);
* // => 'abc'
*/
- function padRight(string, length, chars) {
- string = baseToString(string);
- return string && (string + createPad(string, length, chars));
- }
+ var padRight = createPadDir(true);
/**
* Converts `string` to an integer of the specified radix. If `radix` is
* `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
* in which case a `radix` of `16` is used.
*
- * **Note:** This method aligns with the ES5 implementation of `parseInt`.
- * See the [ES5 spec](https://es5.github.io/#E) for more details.
+ * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
+ * of `parseInt`.
*
* @static
* @memberOf _
* @category String
* @param {string} string The string to convert.
@@ -10162,12 +10339,11 @@
return result;
}
/**
- * Converts `string` to snake case.
- * See [Wikipedia](https://en.wikipedia.org/wiki/Snake_case) for more details.
+ * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
@@ -10186,13 +10362,11 @@
var snakeCase = createCompounder(function(result, word, index) {
return result + (index ? '_' : '') + word.toLowerCase();
});
/**
- * Converts `string` to start case.
- * See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage)
- * for more details.
+ * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
@@ -10247,13 +10421,13 @@
* in "interpolate" delimiters, HTML-escape interpolated data properties in
* "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
* properties may be accessed as free variables in the template. If a setting
* object is provided it takes precedence over `_.templateSettings` values.
*
- * **Note:** In the development build `_.template` utilizes sourceURLs for easier debugging.
- * See the [HTML5 Rocks article on sourcemaps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
- * for more details.
+ * **Note:** In the development build `_.template` utilizes
+ * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
+ * for easier debugging.
*
* For more information on precompiling templates see
* [lodash's custom builds documentation](https://lodash.com/custom-builds).
*
* For more information on Chrome extension sandboxes see
@@ -10461,11 +10635,11 @@
*
* _.trim('-_-abc-_-', '_-');
* // => 'abc'
*
* _.map([' foo ', ' bar '], _.trim);
- * // => ['foo', 'bar]
+ * // => ['foo', 'bar']
*/
function trim(string, chars, guard) {
var value = string;
string = baseToString(string);
if (!string) {
@@ -10569,11 +10743,11 @@
*
* _.trunc('hi-diddly-ho there, neighborino', {
* 'length': 24,
* 'separator': /,? +/
* });
- * //=> 'hi-diddly-ho there...'
+ * // => 'hi-diddly-ho there...'
*
* _.trunc('hi-diddly-ho there, neighborino', {
* 'omission': ' [...]'
* });
* // => 'hi-diddly-ho there, neig [...]'
@@ -10688,11 +10862,11 @@
* object. Any additional arguments are provided to `func` when it is invoked.
*
* @static
* @memberOf _
* @category Utility
- * @param {*} func The function to attempt.
+ * @param {Function} func The function to attempt.
* @returns {*} Returns the `func` result or error object.
* @example
*
* // avoid throwing errors for invalid selectors
* var elements = _.attempt(function(selector) {
@@ -10701,24 +10875,17 @@
*
* if (_.isError(elements)) {
* elements = [];
* }
*/
- function attempt() {
- var func = arguments[0],
- length = arguments.length,
- args = Array(length ? (length - 1) : 0);
-
- while (--length > 0) {
- args[length - 1] = arguments[length];
- }
+ var attempt = restParam(function(func, args) {
try {
return func.apply(undefined, args);
} catch(e) {
return isError(e) ? e : new Error(e);
}
- }
+ });
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg`
* and arguments of the created function. If `func` is a property name the
* created callback returns the property value for a given element. If `func`
@@ -10851,26 +11018,28 @@
* @returns {Function} Returns the new function.
* @example
*
* var users = [
* { 'user': 'barney' },
- * { 'user': 'fred' },
- * { 'user': 'pebbles' }
+ * { 'user': 'fred' }
* ];
*
* _.find(users, _.matchesProperty('user', 'fred'));
- * // => { 'user': 'fred', 'age': 40 }
+ * // => { 'user': 'fred' }
*/
function matchesProperty(key, value) {
return baseMatchesProperty(key + '', baseClone(value, true));
}
/**
* Adds all own enumerable function properties of a source object to the
* destination object. If `object` is a function then methods are added to
* its prototype as well.
*
+ * **Note:** Use `_.runInContext` to create a pristine `lodash` function
+ * for mixins to avoid conflicts caused by modifying the original.
+ *
* @static
* @memberOf _
* @category Utility
* @param {Function|Object} [object=this] object The destination object.
* @param {Object} source The object of functions to add.
@@ -10884,11 +11053,11 @@
* return _.filter(string, function(v) {
* return /[aeiou]/i.test(v);
* });
* }
*
- * // use `_.runInContext` to avoid potential conflicts (esp. in Node.js)
+ * // use `_.runInContext` to avoid conflicts (esp. in Node.js)
* var _ = require('lodash').runInContext();
*
* _.mixin({ 'vowels': vowels });
* _.vowels('fred');
* // => ['e']
@@ -10934,16 +11103,14 @@
if (isFunc) {
object.prototype[methodName] = (function(func) {
return function() {
var chainAll = this.__chain__;
if (chain || chainAll) {
- var result = object(this.__wrapped__);
- (result.__actions__ = arrayCopy(this.__actions__)).push({
- 'func': func,
- 'args': arguments,
- 'thisArg': object
- });
+ var result = object(this.__wrapped__),
+ actions = result.__actions__ = arrayCopy(this.__actions__);
+
+ actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
result.__chain__ = chainAll;
return result;
}
var args = [this.value()];
push.apply(args, arguments);
@@ -11006,21 +11173,21 @@
* ];
*
* var getName = _.property('user');
*
* _.map(users, getName);
- * // => ['fred', barney']
+ * // => ['fred', 'barney']
*
* _.pluck(_.sortBy(users, getName), 'user');
* // => ['barney', 'fred']
*/
function property(key) {
return baseProperty(key + '');
}
/**
- * The inverse of `_.property`; this method creates a function which returns
+ * The opposite of `_.property`; this method creates a function which returns
* the property value of a given key on `object`.
*
* @static
* @memberOf _
* @category Utility
@@ -11194,20 +11361,20 @@
/**
* Gets the maximum value of `collection`. If `collection` is empty or falsey
* `-Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
- * arguments; (value, index, collection).
+ * arguments: (value, index, collection).
*
- * If a property name is provided for `predicate` the created `_.property`
+ * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
- * If an object is provided for `predicate` the created `_.matches` style
+ * If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
@@ -11230,33 +11397,33 @@
* ];
*
* _.max(users, function(chr) {
* return chr.age;
* });
- * // => { 'user': 'fred', 'age': 40 };
+ * // => { 'user': 'fred', 'age': 40 }
*
* // using the `_.property` callback shorthand
* _.max(users, 'age');
- * // => { 'user': 'fred', 'age': 40 };
+ * // => { 'user': 'fred', 'age': 40 }
*/
var max = createExtremum(arrayMax);
/**
* Gets the minimum value of `collection`. If `collection` is empty or falsey
* `Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
- * arguments; (value, index, collection).
+ * arguments: (value, index, collection).
*
- * If a property name is provided for `predicate` the created `_.property`
+ * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
- * If an object is provided for `predicate` the created `_.matches` style
+ * If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
@@ -11279,45 +11446,64 @@
* ];
*
* _.min(users, function(chr) {
* return chr.age;
* });
- * // => { 'user': 'barney', 'age': 36 };
+ * // => { 'user': 'barney', 'age': 36 }
*
* // using the `_.property` callback shorthand
* _.min(users, 'age');
- * // => { 'user': 'barney', 'age': 36 };
+ * // => { 'user': 'barney', 'age': 36 }
*/
var min = createExtremum(arrayMin, true);
/**
* Gets the sum of the values in `collection`.
*
* @static
* @memberOf _
* @category Math
* @param {Array|Object|string} collection The collection to iterate over.
+ * @param {Function|Object|string} [iteratee] The function invoked per iteration.
+ * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {number} Returns the sum.
* @example
*
- * _.sum([4, 6, 2]);
- * // => 12
+ * _.sum([4, 6]);
+ * // => 10
*
- * _.sum({ 'a': 4, 'b': 6, 'c': 2 });
- * // => 12
+ * _.sum({ 'a': 4, 'b': 6 });
+ * // => 10
+ *
+ * var objects = [
+ * { 'n': 4 },
+ * { 'n': 6 }
+ * ];
+ *
+ * _.sum(objects, function(object) {
+ * return object.n;
+ * });
+ * // => 10
+ *
+ * // using the `_.property` callback shorthand
+ * _.sum(objects, 'n');
+ * // => 10
*/
- function sum(collection) {
- if (!isArray(collection)) {
- collection = toIterable(collection);
+ function sum(collection, iteratee, thisArg) {
+ if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
+ iteratee = null;
}
- var length = collection.length,
- result = 0;
+ var func = getCallback(),
+ noIteratee = iteratee == null;
- while (length--) {
- result += +collection[length] || 0;
+ if (!(func === baseCallback && noIteratee)) {
+ noIteratee = false;
+ iteratee = func(iteratee, thisArg, 3);
}
- return result;
+ return noIteratee
+ ? arraySum(isArray(collection) ? collection : toIterable(collection))
+ : baseSum(collection, iteratee);
}
/*------------------------------------------------------------------------*/
// Ensure wrappers are instances of `baseLodash`.
@@ -11412,10 +11598,11 @@
lodash.range = range;
lodash.rearg = rearg;
lodash.reject = reject;
lodash.remove = remove;
lodash.rest = rest;
+ lodash.restParam = restParam;
lodash.shuffle = shuffle;
lodash.slice = slice;
lodash.sortBy = sortBy;
lodash.sortByAll = sortByAll;
lodash.sortByOrder = sortByOrder;
@@ -11703,12 +11890,15 @@
return this.drop(0);
};
// Add `LazyWrapper` methods to `lodash.prototype`.
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
- var lodashFunc = lodash[methodName],
- checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
+ var lodashFunc = lodash[methodName];
+ if (!lodashFunc) {
+ return;
+ }
+ var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
retUnwrapped = /^(?:first|last)$/.test(methodName);
lodash.prototype[methodName] = function() {
var args = arguments,
length = args.length,
@@ -11773,9 +11963,22 @@
return this[chainName](function(value) {
return func.apply(value, args);
});
};
});
+
+ // Map minified function names to their real names.
+ baseForOwn(LazyWrapper.prototype, function(func, methodName) {
+ var lodashFunc = lodash[methodName];
+ if (lodashFunc) {
+ var key = lodashFunc.name,
+ names = realNames[key] || (realNames[key] = []);
+
+ names.push({ 'name': methodName, 'func': lodashFunc });
+ }
+ });
+
+ realNames[createHybridWrapper(null, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': null }];
// Add functions to the lazy wrapper.
LazyWrapper.prototype.clone = lazyClone;
LazyWrapper.prototype.reverse = lazyReverse;
LazyWrapper.prototype.value = lazyValue;