mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Bump to v3.6.0.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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.
|
||||
|
||||
18
internal/arraySum.js
Normal file
18
internal/arraySum.js
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default arraySum;
|
||||
@@ -1,26 +0,0 @@
|
||||
import createWrapper from './createWrapper';
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var BIND_FLAG = 1;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default baseBindAll;
|
||||
@@ -3,7 +3,6 @@ import baseMatchesProperty from './baseMatchesProperty';
|
||||
import baseProperty from './baseProperty';
|
||||
import bindCallback from './bindCallback';
|
||||
import identity from '../utility/identity';
|
||||
import isBindable from './isBindable';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.callback` which supports specifying the
|
||||
@@ -18,9 +17,9 @@ import isBindable from './isBindable';
|
||||
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;
|
||||
|
||||
@@ -54,9 +54,8 @@ cloneableTags[weakMapTag] = false;
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import baseSlice from './baseSlice';
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
@@ -10,14 +8,14 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
* @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);
|
||||
}
|
||||
|
||||
export default baseDelay;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import baseForOwn from './baseForOwn';
|
||||
import isLength from './isLength';
|
||||
import toObject from './toObject';
|
||||
import createBaseEach from './createBaseEach';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.forEach` without support for callback
|
||||
@@ -11,20 +10,6 @@ import toObject from './toObject';
|
||||
* @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);
|
||||
|
||||
while (++index < length) {
|
||||
if (iteratee(iterable[index], index, iterable) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
var baseEach = createBaseEach(baseForOwn);
|
||||
|
||||
export default baseEach;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import baseForOwnRight from './baseForOwnRight';
|
||||
import isLength from './isLength';
|
||||
import toObject from './toObject';
|
||||
import createBaseEach from './createBaseEach';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.forEachRight` without support for callback
|
||||
@@ -11,18 +10,6 @@ import toObject from './toObject';
|
||||
* @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);
|
||||
|
||||
export default baseEachRight;
|
||||
|
||||
@@ -2,7 +2,7 @@ import baseEach from './baseEach';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -2,7 +2,7 @@ import baseEach from './baseEach';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
23
internal/baseFindIndex.js
Normal file
23
internal/baseFindIndex.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default baseFindIndex;
|
||||
@@ -11,11 +11,10 @@ import isObjectLike from './isObjectLike';
|
||||
* @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 = [];
|
||||
@@ -26,7 +25,7 @@ function baseFlatten(array, isDeep, isStrict, fromIndex) {
|
||||
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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import toObject from './toObject';
|
||||
import createBaseFor from './createBaseFor';
|
||||
|
||||
/**
|
||||
* The base implementation of `baseForIn` and `baseForOwn` which iterates
|
||||
@@ -12,19 +12,6 @@ import toObject from './toObject';
|
||||
* @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;
|
||||
|
||||
while (++index < length) {
|
||||
var key = props[index];
|
||||
if (iteratee(iterable[key], key, iterable) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
var baseFor = createBaseFor();
|
||||
|
||||
export default baseFor;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import toObject from './toObject';
|
||||
import createBaseFor from './createBaseFor';
|
||||
|
||||
/**
|
||||
* This function is like `baseFor` except that it iterates over properties
|
||||
@@ -10,18 +10,6 @@ import toObject from './toObject';
|
||||
* @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;
|
||||
|
||||
while (length--) {
|
||||
var key = props[length];
|
||||
if (iteratee(iterable[key], key, iterable) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
var baseForRight = createBaseFor(true);
|
||||
|
||||
export default baseForRight;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import baseEach from './baseEach';
|
||||
import isLength from './isLength';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default baseInvoke;
|
||||
@@ -8,12 +8,12 @@ import baseIsEqualDeep from './baseIsEqualDeep';
|
||||
* @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.
|
||||
@@ -28,7 +28,7 @@ function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
export default baseIsEqual;
|
||||
|
||||
@@ -7,6 +7,7 @@ import isTypedArray from '../lang/isTypedArray';
|
||||
/** `Object#toString` result references. */
|
||||
var argsTag = '[object Arguments]',
|
||||
arrayTag = '[object Array]',
|
||||
funcTag = '[object Function]',
|
||||
objectTag = '[object Object]';
|
||||
|
||||
/** Used for native method references. */
|
||||
@@ -16,9 +17,8 @@ var objectProto = Object.prototype;
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
@@ -32,12 +32,12 @@ var objToString = objectProto.toString;
|
||||
* @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,
|
||||
@@ -59,21 +59,27 @@ function baseIsEqualDeep(object, other, equalFunc, customizer, isWhere, stackA,
|
||||
othIsArr = isTypedArray(other);
|
||||
}
|
||||
}
|
||||
var objIsObj = objTag == objectTag,
|
||||
othIsObj = othTag == objectTag,
|
||||
var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)),
|
||||
othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)),
|
||||
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 (!isSameTag) {
|
||||
return false;
|
||||
if (valWrapped || othWrapped) {
|
||||
return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
|
||||
}
|
||||
if (!isSameTag) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Assume cyclic values are equal.
|
||||
// For more information on detecting circular references see https://es5.github.io/#JO.
|
||||
@@ -90,7 +96,7 @@ function baseIsEqualDeep(object, other, equalFunc, customizer, isWhere, stackA,
|
||||
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();
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
import baseIsEqual from './baseIsEqual';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -19,30 +13,27 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* @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];
|
||||
if (noCustomizer && strictCompareFlags[index]) {
|
||||
var result = hasOwnProperty.call(object, key);
|
||||
} else {
|
||||
var objValue = object[key],
|
||||
srcValue = values[index];
|
||||
var key = props[index],
|
||||
objValue = object[key],
|
||||
srcValue = values[index];
|
||||
|
||||
if (noCustomizer && strictCompareFlags[index]) {
|
||||
var result = typeof objValue != 'undefined' || (key in object);
|
||||
} else {
|
||||
result = customizer ? customizer(objValue, srcValue, key) : undefined;
|
||||
if (typeof result == 'undefined') {
|
||||
result = baseIsEqual(srcValue, objValue, customizer, true);
|
||||
|
||||
@@ -2,7 +2,7 @@ import baseEach from './baseEach';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import baseIsMatch from './baseIsMatch';
|
||||
import constant from '../utility/constant';
|
||||
import isStrictComparable from './isStrictComparable';
|
||||
import keys from '../object/keys';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
import toObject from './toObject';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.matches` which does not clone `source`.
|
||||
@@ -19,13 +15,17 @@ 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)));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ function baseMatches(source) {
|
||||
strictCompareFlags[length] = isStrictComparable(value);
|
||||
}
|
||||
return function(object) {
|
||||
return baseIsMatch(object, props, values, strictCompareFlags);
|
||||
return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import baseIsEqual from './baseIsEqual';
|
||||
import isStrictComparable from './isStrictComparable';
|
||||
import toObject from './toObject';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.matchesProperty` which does not coerce `key`
|
||||
@@ -13,7 +14,8 @@ import isStrictComparable from './isStrictComparable';
|
||||
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) {
|
||||
|
||||
@@ -40,7 +40,7 @@ function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stack
|
||||
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)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import baseAt from './baseAt';
|
||||
import baseCompareAscending from './baseCompareAscending';
|
||||
import isIndex from './isIndex';
|
||||
|
||||
/** Used for native method references. */
|
||||
var arrayProto = Array.prototype;
|
||||
|
||||
/** Native method references. */
|
||||
var splice = arrayProto.splice;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default basePullAt;
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -2,7 +2,7 @@ import baseEach from './baseEach';
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
20
internal/baseSum.js
Normal file
20
internal/baseSum.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import baseEach from './baseEach';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default baseSum;
|
||||
24
internal/baseWhile.js
Normal file
24
internal/baseWhile.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import baseSlice from './baseSlice';
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
export default baseWhile;
|
||||
@@ -14,7 +14,7 @@ var push = arrayProto.push;
|
||||
* @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;
|
||||
|
||||
@@ -12,8 +12,7 @@ var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
|
||||
* @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`.
|
||||
*/
|
||||
|
||||
@@ -17,8 +17,7 @@ var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
|
||||
* @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`.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,9 @@ import isArray from '../lang/isArray';
|
||||
* 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.
|
||||
|
||||
@@ -5,6 +5,8 @@ import isIterateeCall from './isIterateeCall';
|
||||
* 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.
|
||||
|
||||
30
internal/createBaseEach.js
Normal file
30
internal/createBaseEach.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import isLength from './isLength';
|
||||
import toObject from './toObject';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
}
|
||||
|
||||
export default createBaseEach;
|
||||
27
internal/createBaseFor.js
Normal file
27
internal/createBaseFor.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import toObject from './toObject';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
}
|
||||
|
||||
export default createBaseFor;
|
||||
@@ -1,39 +0,0 @@
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default createComposer;
|
||||
23
internal/createCurry.js
Normal file
23
internal/createCurry.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import createWrapper from './createWrapper';
|
||||
import isIterateeCall from './isIterateeCall';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default createCurry;
|
||||
@@ -7,7 +7,7 @@ import isString from '../lang/isString';
|
||||
import toIterable from './toIterable';
|
||||
|
||||
/**
|
||||
* Creates a function that gets the extremum value of a collection.
|
||||
* Creates a `_.max` or `_.min` function.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} arrayFunc The function to get the extremum value from an array.
|
||||
|
||||
25
internal/createFind.js
Normal file
25
internal/createFind.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import baseCallback from './baseCallback';
|
||||
import baseFind from './baseFind';
|
||||
import baseFindIndex from './baseFindIndex';
|
||||
import isArray from '../lang/isArray';
|
||||
|
||||
/**
|
||||
* 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 = baseCallback(predicate, thisArg, 3);
|
||||
if (isArray(collection)) {
|
||||
var index = baseFindIndex(collection, predicate, fromRight);
|
||||
return index > -1 ? collection[index] : undefined;
|
||||
}
|
||||
return baseFind(collection, predicate, eachFunc);
|
||||
}
|
||||
}
|
||||
|
||||
export default createFind;
|
||||
21
internal/createFindIndex.js
Normal file
21
internal/createFindIndex.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import baseCallback from './baseCallback';
|
||||
import baseFindIndex from './baseFindIndex';
|
||||
|
||||
/**
|
||||
* 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 = baseCallback(predicate, thisArg, 3);
|
||||
return baseFindIndex(array, predicate, fromRight);
|
||||
};
|
||||
}
|
||||
|
||||
export default createFindIndex;
|
||||
18
internal/createFindKey.js
Normal file
18
internal/createFindKey.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import baseCallback from './baseCallback';
|
||||
import baseFind from './baseFind';
|
||||
|
||||
/**
|
||||
* 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 = baseCallback(predicate, thisArg, 3);
|
||||
return baseFind(object, predicate, objectFunc, true);
|
||||
};
|
||||
}
|
||||
|
||||
export default createFindKey;
|
||||
64
internal/createFlow.js
Normal file
64
internal/createFlow.js
Normal file
@@ -0,0 +1,64 @@
|
||||
import LodashWrapper from './LodashWrapper';
|
||||
import getData from './getData';
|
||||
import getFuncName from './getFuncName';
|
||||
import isArray from '../lang/isArray';
|
||||
import isLaziable from './isLaziable';
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default createFlow;
|
||||
20
internal/createForEach.js
Normal file
20
internal/createForEach.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import bindCallback from './bindCallback';
|
||||
import isArray from '../lang/isArray';
|
||||
|
||||
/**
|
||||
* 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));
|
||||
};
|
||||
}
|
||||
|
||||
export default createForEach;
|
||||
20
internal/createForIn.js
Normal file
20
internal/createForIn.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import bindCallback from './bindCallback';
|
||||
import keysIn from '../object/keysIn';
|
||||
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
}
|
||||
|
||||
export default createForIn;
|
||||
19
internal/createForOwn.js
Normal file
19
internal/createForOwn.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import bindCallback from './bindCallback';
|
||||
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
}
|
||||
|
||||
export default createForOwn;
|
||||
@@ -2,9 +2,11 @@ import arrayCopy from './arrayCopy';
|
||||
import composeArgs from './composeArgs';
|
||||
import composeArgsRight from './composeArgsRight';
|
||||
import createCtorWrapper from './createCtorWrapper';
|
||||
import isLaziable from './isLaziable';
|
||||
import reorder from './reorder';
|
||||
import replaceHolders from './replaceHolders';
|
||||
import root from './root';
|
||||
import setData from './setData';
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var BIND_FLAG = 1,
|
||||
@@ -14,7 +16,7 @@ var BIND_FLAG = 1,
|
||||
CURRY_RIGHT_FLAG = 16,
|
||||
PARTIAL_FLAG = 32,
|
||||
PARTIAL_RIGHT_FLAG = 64,
|
||||
ARY_FLAG = 256;
|
||||
ARY_FLAG = 128;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeMax = Math.max;
|
||||
@@ -82,7 +84,12 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials
|
||||
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;
|
||||
}
|
||||
|
||||
18
internal/createPadDir.js
Normal file
18
internal/createPadDir.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import baseToString from './baseToString';
|
||||
import createPadding from './createPadding';
|
||||
|
||||
/**
|
||||
* 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));
|
||||
};
|
||||
}
|
||||
|
||||
export default createPadDir;
|
||||
@@ -8,9 +8,8 @@ var ceil = Math.ceil;
|
||||
var nativeIsFinite = root.isFinite;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -18,7 +17,7 @@ var nativeIsFinite = root.isFinite;
|
||||
* @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;
|
||||
|
||||
@@ -30,4 +29,4 @@ function createPad(string, length, chars) {
|
||||
return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
|
||||
}
|
||||
|
||||
export default createPad;
|
||||
export default createPadding;
|
||||
20
internal/createPartial.js
Normal file
20
internal/createPartial.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import createWrapper from './createWrapper';
|
||||
import replaceHolders from './replaceHolders';
|
||||
import restParam from '../function/restParam';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default createPartial;
|
||||
22
internal/createReduce.js
Normal file
22
internal/createReduce.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import baseCallback from './baseCallback';
|
||||
import baseReduce from './baseReduce';
|
||||
import isArray from '../lang/isArray';
|
||||
|
||||
/**
|
||||
* 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, baseCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
|
||||
};
|
||||
}
|
||||
|
||||
export default createReduce;
|
||||
20
internal/createSortedIndex.js
Normal file
20
internal/createSortedIndex.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import baseCallback from './baseCallback';
|
||||
import binaryIndex from './binaryIndex';
|
||||
import binaryIndexBy from './binaryIndexBy';
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
return iteratee == null
|
||||
? binaryIndex(array, value, retHighest)
|
||||
: binaryIndexBy(array, value, baseCallback(iteratee, thisArg, 1), retHighest);
|
||||
};
|
||||
}
|
||||
|
||||
export default createSortedIndex;
|
||||
@@ -60,10 +60,10 @@ function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, a
|
||||
|
||||
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];
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
* @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.
|
||||
@@ -28,23 +28,23 @@ function equalArrays(array, other, equalFunc, customizer, isWhere, stackA, stack
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,26 +15,26 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* @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],
|
||||
@@ -42,21 +42,21 @@ function equalObjects(object, other, equalFunc, customizer, isWhere, stackA, sta
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
|
||||
/**
|
||||
* 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.
|
||||
|
||||
37
internal/getFuncName.js
Normal file
37
internal/getFuncName.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import baseProperty from './baseProperty';
|
||||
import constant from '../utility/constant';
|
||||
import realNames from './realNames';
|
||||
import support from '../support';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
}());
|
||||
|
||||
export default getFuncName;
|
||||
@@ -1,6 +1,5 @@
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import baseSetData from './baseSetData';
|
||||
import isNative from '../lang/isNative';
|
||||
import support from '../support';
|
||||
|
||||
/** Used to detect named functions. */
|
||||
var reFuncName = /^\s*function[ \n\r\t]+\w/;
|
||||
|
||||
/** Used to detect functions containing a `this` reference. */
|
||||
var reThis = /\bthis\b/;
|
||||
|
||||
/** Used to resolve the decompiled source of functions. */
|
||||
var fnToString = Function.prototype.toString;
|
||||
|
||||
/**
|
||||
* 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 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;
|
||||
}
|
||||
|
||||
export default isBindable;
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
17
internal/isLaziable.js
Normal file
17
internal/isLaziable.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import LazyWrapper from './LazyWrapper';
|
||||
import getFuncName from './getFuncName';
|
||||
import lodash from '../chain/lodash';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
export default isLaziable;
|
||||
@@ -1,16 +1,13 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @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';
|
||||
}
|
||||
|
||||
export default isObjectLike;
|
||||
|
||||
@@ -5,11 +5,10 @@ import replaceHolders from './replaceHolders';
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var BIND_FLAG = 1,
|
||||
BIND_KEY_FLAG = 2,
|
||||
CURRY_BOUND_FLAG = 4,
|
||||
CURRY_RIGHT_FLAG = 16,
|
||||
REARG_FLAG = 128,
|
||||
ARY_FLAG = 256;
|
||||
CURRY_FLAG = 8,
|
||||
ARY_FLAG = 128,
|
||||
REARG_FLAG = 256;
|
||||
|
||||
/** Used as the internal argument placeholder. */
|
||||
var PLACEHOLDER = '__lodash_placeholder__';
|
||||
@@ -35,22 +34,13 @@ var nativeMin = Math.min;
|
||||
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 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));
|
||||
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);
|
||||
|
||||
// Exit early if metadata can't be merged.
|
||||
if (!(isCommon || isCombo)) {
|
||||
|
||||
4
internal/realNames.js
Normal file
4
internal/realNames.js
Normal file
@@ -0,0 +1,4 @@
|
||||
/** Used to lookup unminified function names. */
|
||||
var realNames = {};
|
||||
|
||||
export default realNames;
|
||||
@@ -13,8 +13,11 @@ var freeModule = objectTypes[typeof module] && module && !module.nodeType && mod
|
||||
/** 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;
|
||||
|
||||
/**
|
||||
* Used as a reference to the global object.
|
||||
@@ -22,6 +25,6 @@ var freeWindow = objectTypes[typeof window] && window;
|
||||
* 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;
|
||||
|
||||
export default root;
|
||||
|
||||
@@ -11,9 +11,8 @@ var objectProto = Object.prototype;
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user