mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Bump to v3.10.0.
This commit is contained in:
@@ -12,13 +12,12 @@ var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
||||
*/
|
||||
function LazyWrapper(value) {
|
||||
this.__wrapped__ = value;
|
||||
this.__actions__ = null;
|
||||
this.__actions__ = [];
|
||||
this.__dir__ = 1;
|
||||
this.__dropCount__ = 0;
|
||||
this.__filtered__ = false;
|
||||
this.__iteratees__ = null;
|
||||
this.__iteratees__ = [];
|
||||
this.__takeCount__ = POSITIVE_INFINITY;
|
||||
this.__views__ = null;
|
||||
this.__views__ = [];
|
||||
}
|
||||
|
||||
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||
|
||||
25
internal/arrayConcat.js
Normal file
25
internal/arrayConcat.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Creates a new array joining `array` with `other`.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to join.
|
||||
* @param {Array} other The other array to join.
|
||||
* @returns {Array} Returns the new concatenated array.
|
||||
*/
|
||||
function arrayConcat(array, other) {
|
||||
var index = -1,
|
||||
length = array.length,
|
||||
othIndex = -1,
|
||||
othLength = other.length,
|
||||
result = Array(length + othLength);
|
||||
|
||||
while (++index < length) {
|
||||
result[index] = array[index];
|
||||
}
|
||||
while (++othIndex < othLength) {
|
||||
result[index++] = other[othIndex];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default arrayConcat;
|
||||
20
internal/arrayPush.js
Normal file
20
internal/arrayPush.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Appends the elements of `values` to `array`.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to modify.
|
||||
* @param {Array} values The values to append.
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function arrayPush(array, values) {
|
||||
var index = -1,
|
||||
length = values.length,
|
||||
offset = array.length;
|
||||
|
||||
while (++index < length) {
|
||||
array[offset + index] = values[index];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
export default arrayPush;
|
||||
@@ -1,16 +1,18 @@
|
||||
/**
|
||||
* A specialized version of `_.sum` for arrays without support for iteratees.
|
||||
* A specialized version of `_.sum` for arrays without support for callback
|
||||
* shorthands and `this` binding..
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {number} Returns the sum.
|
||||
*/
|
||||
function arraySum(array) {
|
||||
function arraySum(array, iteratee) {
|
||||
var length = array.length,
|
||||
result = 0;
|
||||
|
||||
while (length--) {
|
||||
result += +array[length] || 0;
|
||||
result += +iteratee(array[length]) || 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ cloneableTags[weakMapTag] = false;
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
||||
* of values.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
@@ -104,7 +104,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
|
||||
: (object ? value : {});
|
||||
}
|
||||
}
|
||||
// Check for circular references and return corresponding clone.
|
||||
// Check for circular references and return its corresponding clone.
|
||||
stackA || (stackA = []);
|
||||
stackB || (stackB = []);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ var baseCreate = (function() {
|
||||
if (isObject(prototype)) {
|
||||
object.prototype = prototype;
|
||||
var result = new object;
|
||||
object.prototype = null;
|
||||
object.prototype = undefined;
|
||||
}
|
||||
return result || {};
|
||||
};
|
||||
|
||||
@@ -2,6 +2,9 @@ import baseIndexOf from './baseIndexOf';
|
||||
import cacheIndexOf from './cacheIndexOf';
|
||||
import createCache from './createCache';
|
||||
|
||||
/** Used as the size to enable large array optimizations. */
|
||||
var LARGE_ARRAY_SIZE = 200;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.difference` which accepts a single array
|
||||
* of values to exclude.
|
||||
@@ -21,7 +24,7 @@ function baseDifference(array, values) {
|
||||
var index = -1,
|
||||
indexOf = baseIndexOf,
|
||||
isCommon = true,
|
||||
cache = (isCommon && values.length >= 200) ? createCache(values) : null,
|
||||
cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
|
||||
valuesLength = values.length;
|
||||
|
||||
if (cache) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import arrayPush from './arrayPush';
|
||||
import isArguments from '../lang/isArguments';
|
||||
import isArray from '../lang/isArray';
|
||||
import isArrayLike from './isArrayLike';
|
||||
@@ -11,13 +12,14 @@ 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-like objects.
|
||||
* @param {Array} [result=[]] The initial result value.
|
||||
* @returns {Array} Returns the new flattened array.
|
||||
*/
|
||||
function baseFlatten(array, isDeep, isStrict) {
|
||||
function baseFlatten(array, isDeep, isStrict, result) {
|
||||
result || (result = []);
|
||||
|
||||
var index = -1,
|
||||
length = array.length,
|
||||
resIndex = -1,
|
||||
result = [];
|
||||
length = array.length;
|
||||
|
||||
while (++index < length) {
|
||||
var value = array[index];
|
||||
@@ -25,16 +27,12 @@ function baseFlatten(array, isDeep, isStrict) {
|
||||
(isStrict || isArray(value) || isArguments(value))) {
|
||||
if (isDeep) {
|
||||
// Recursively flatten arrays (susceptible to call stack limits).
|
||||
value = baseFlatten(value, isDeep, isStrict);
|
||||
}
|
||||
var valIndex = -1,
|
||||
valLength = value.length;
|
||||
|
||||
while (++valIndex < valLength) {
|
||||
result[++resIndex] = value[valIndex];
|
||||
baseFlatten(value, isDeep, isStrict, result);
|
||||
} else {
|
||||
arrayPush(result, value);
|
||||
}
|
||||
} else if (!isStrict) {
|
||||
result[++resIndex] = value;
|
||||
result[result.length] = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -16,7 +16,7 @@ var objectProto = Object.prototype;
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
||||
* of values.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
@@ -14,7 +14,7 @@ import keys from '../object/keys';
|
||||
* @private
|
||||
* @param {Object} object The destination object.
|
||||
* @param {Object} source The source object.
|
||||
* @param {Function} [customizer] The function to customize merging properties.
|
||||
* @param {Function} [customizer] The function to customize merged values.
|
||||
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
||||
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
||||
* @returns {Object} Returns `object`.
|
||||
@@ -24,7 +24,7 @@ function baseMerge(object, source, customizer, stackA, stackB) {
|
||||
return object;
|
||||
}
|
||||
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
|
||||
props = isSrcArr ? null : keys(source);
|
||||
props = isSrcArr ? undefined : keys(source);
|
||||
|
||||
arrayEach(props || source, function(srcValue, key) {
|
||||
if (props) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import toPlainObject from '../lang/toPlainObject';
|
||||
* @param {Object} source The source object.
|
||||
* @param {string} key The key of the value to merge.
|
||||
* @param {Function} mergeFunc The function to merge values.
|
||||
* @param {Function} [customizer] The function to customize merging properties.
|
||||
* @param {Function} [customizer] The function to customize merged values.
|
||||
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
||||
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
||||
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
/** Native method references. */
|
||||
var floor = Math.floor;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeRandom = Math.random;
|
||||
var nativeFloor = Math.floor,
|
||||
nativeRandom = Math.random;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.random` without support for argument juggling
|
||||
@@ -14,7 +12,7 @@ var nativeRandom = Math.random;
|
||||
* @returns {number} Returns the random number.
|
||||
*/
|
||||
function baseRandom(min, max) {
|
||||
return min + floor(nativeRandom() * (max - min + 1));
|
||||
return min + nativeFloor(nativeRandom() * (max - min + 1));
|
||||
}
|
||||
|
||||
export default baseRandom;
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
* @returns {string} Returns the string.
|
||||
*/
|
||||
function baseToString(value) {
|
||||
if (typeof value == 'string') {
|
||||
return value;
|
||||
}
|
||||
return value == null ? '' : (value + '');
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ import baseIndexOf from './baseIndexOf';
|
||||
import cacheIndexOf from './cacheIndexOf';
|
||||
import createCache from './createCache';
|
||||
|
||||
/** Used as the size to enable large array optimizations. */
|
||||
var LARGE_ARRAY_SIZE = 200;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.uniq` without support for callback shorthands
|
||||
* and `this` binding.
|
||||
@@ -16,7 +19,7 @@ function baseUniq(array, iteratee) {
|
||||
indexOf = baseIndexOf,
|
||||
length = array.length,
|
||||
isCommon = true,
|
||||
isLarge = isCommon && length >= 200,
|
||||
isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
|
||||
seen = isLarge ? createCache() : null,
|
||||
result = [];
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import LazyWrapper from './LazyWrapper';
|
||||
|
||||
/** Used for native method references. */
|
||||
var arrayProto = Array.prototype;
|
||||
|
||||
/** Native method references. */
|
||||
var push = arrayProto.push;
|
||||
import arrayPush from './arrayPush';
|
||||
|
||||
/**
|
||||
* The base implementation of `wrapperValue` which returns the result of
|
||||
@@ -25,11 +20,8 @@ function baseWrapperValue(value, actions) {
|
||||
length = actions.length;
|
||||
|
||||
while (++index < length) {
|
||||
var args = [result],
|
||||
action = actions[index];
|
||||
|
||||
push.apply(args, action.args);
|
||||
result = action.func.apply(action.thisArg, args);
|
||||
var action = actions[index];
|
||||
result = action.func.apply(action.thisArg, arrayPush([result], action.args));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
/** Native method references. */
|
||||
var floor = Math.floor;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeMin = Math.min;
|
||||
var nativeFloor = Math.floor,
|
||||
nativeMin = Math.min;
|
||||
|
||||
/** Used as references for the maximum length and index of an array. */
|
||||
var MAX_ARRAY_LENGTH = 4294967295,
|
||||
@@ -31,7 +29,7 @@ function binaryIndexBy(array, value, iteratee, retHighest) {
|
||||
valIsUndef = value === undefined;
|
||||
|
||||
while (low < high) {
|
||||
var mid = floor((low + high) / 2),
|
||||
var mid = nativeFloor((low + high) / 2),
|
||||
computed = iteratee(array[mid]),
|
||||
isDef = computed !== undefined,
|
||||
isReflexive = computed === computed;
|
||||
|
||||
@@ -1,27 +1,8 @@
|
||||
import constant from '../utility/constant';
|
||||
import getNative from './getNative';
|
||||
import root from './root';
|
||||
|
||||
/** Native method references. */
|
||||
var ArrayBuffer = getNative(root, 'ArrayBuffer'),
|
||||
bufferSlice = getNative(ArrayBuffer && new ArrayBuffer(0), 'slice'),
|
||||
floor = Math.floor,
|
||||
Uint8Array = getNative(root, 'Uint8Array');
|
||||
|
||||
/** Used to clone array buffers. */
|
||||
var Float64Array = (function() {
|
||||
// Safari 5 errors when using an array buffer to initialize a typed array
|
||||
// where the array buffer's `byteLength` is not a multiple of the typed
|
||||
// array's `BYTES_PER_ELEMENT`.
|
||||
try {
|
||||
var func = getNative(root, 'Float64Array'),
|
||||
result = new func(new ArrayBuffer(10), 0, 1) && func;
|
||||
} catch(e) {}
|
||||
return result || null;
|
||||
}());
|
||||
|
||||
/** Used as the size, in bytes, of each `Float64Array` element. */
|
||||
var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
|
||||
var ArrayBuffer = root.ArrayBuffer,
|
||||
Uint8Array = root.Uint8Array;
|
||||
|
||||
/**
|
||||
* Creates a clone of the given array buffer.
|
||||
@@ -31,26 +12,11 @@ var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT :
|
||||
* @returns {ArrayBuffer} Returns the cloned array buffer.
|
||||
*/
|
||||
function bufferClone(buffer) {
|
||||
return bufferSlice.call(buffer, 0);
|
||||
}
|
||||
if (!bufferSlice) {
|
||||
// PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array`.
|
||||
bufferClone = !(ArrayBuffer && Uint8Array) ? constant(null) : function(buffer) {
|
||||
var byteLength = buffer.byteLength,
|
||||
floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0,
|
||||
offset = floatLength * FLOAT64_BYTES_PER_ELEMENT,
|
||||
result = new ArrayBuffer(byteLength);
|
||||
var result = new ArrayBuffer(buffer.byteLength),
|
||||
view = new Uint8Array(result);
|
||||
|
||||
if (floatLength) {
|
||||
var view = new Float64Array(result, 0, floatLength);
|
||||
view.set(new Float64Array(buffer, 0, floatLength));
|
||||
}
|
||||
if (byteLength != offset) {
|
||||
view = new Uint8Array(result, offset);
|
||||
view.set(new Uint8Array(buffer, offset));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
view.set(new Uint8Array(buffer));
|
||||
return result;
|
||||
}
|
||||
|
||||
export default bufferClone;
|
||||
|
||||
@@ -5,8 +5,8 @@ import baseCompareAscending from './baseCompareAscending';
|
||||
* sort them in ascending order.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to compare to `other`.
|
||||
* @param {Object} other The object to compare to `object`.
|
||||
* @param {Object} object The object to compare.
|
||||
* @param {Object} other The other object to compare.
|
||||
* @returns {number} Returns the sort order indicator for `object`.
|
||||
*/
|
||||
function compareAscending(object, other) {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import baseCompareAscending from './baseCompareAscending';
|
||||
|
||||
/**
|
||||
* Used by `_.sortByOrder` to compare multiple properties of each element
|
||||
* in a collection and stable sort them in the following order:
|
||||
* Used by `_.sortByOrder` to compare multiple properties of a value to another
|
||||
* and stable sort them.
|
||||
*
|
||||
* If `orders` is unspecified, sort in ascending order for all properties.
|
||||
* Otherwise, for each property, sort in ascending order if its corresponding value in
|
||||
* orders is true, and descending order if false.
|
||||
* If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
|
||||
* a value is sorted in ascending order if its corresponding order is "asc", and
|
||||
* descending if "desc".
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to compare to `other`.
|
||||
* @param {Object} other The object to compare to `object`.
|
||||
* @param {Object} object The object to compare.
|
||||
* @param {Object} other The other object to compare.
|
||||
* @param {boolean[]} orders The order to sort by for each property.
|
||||
* @returns {number} Returns the sort order indicator for `object`.
|
||||
*/
|
||||
@@ -27,7 +27,8 @@ function compareMultiple(object, other, orders) {
|
||||
if (index >= ordersLength) {
|
||||
return result;
|
||||
}
|
||||
return result * (orders[index] ? 1 : -1);
|
||||
var order = orders[index];
|
||||
return result * ((order === 'asc' || order === true) ? 1 : -1);
|
||||
}
|
||||
}
|
||||
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
||||
|
||||
@@ -17,7 +17,7 @@ function composeArgs(args, partials, holders) {
|
||||
argsLength = nativeMax(args.length - holdersLength, 0),
|
||||
leftIndex = -1,
|
||||
leftLength = partials.length,
|
||||
result = Array(argsLength + leftLength);
|
||||
result = Array(leftLength + argsLength);
|
||||
|
||||
while (++leftIndex < leftLength) {
|
||||
result[leftIndex] = partials[leftIndex];
|
||||
|
||||
@@ -3,12 +3,7 @@ import baseEach from './baseEach';
|
||||
import isArray from '../lang/isArray';
|
||||
|
||||
/**
|
||||
* 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`.
|
||||
* Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} setter The function to set keys and values of the accumulator object.
|
||||
|
||||
@@ -3,10 +3,7 @@ import isIterateeCall from './isIterateeCall';
|
||||
import restParam from '../function/restParam';
|
||||
|
||||
/**
|
||||
* 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`.
|
||||
* Creates a `_.assign`, `_.defaults`, or `_.merge` function.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} assigner The function to assign values.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import SetCache from './SetCache';
|
||||
import constant from '../utility/constant';
|
||||
import getNative from './getNative';
|
||||
import root from './root';
|
||||
|
||||
@@ -16,8 +15,8 @@ var nativeCreate = getNative(Object, 'create');
|
||||
* @param {Array} [values] The values to cache.
|
||||
* @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
|
||||
*/
|
||||
var createCache = !(nativeCreate && Set) ? constant(null) : function(values) {
|
||||
return new SetCache(values);
|
||||
};
|
||||
function createCache(values) {
|
||||
return (nativeCreate && Set) ? new SetCache(values) : null;
|
||||
}
|
||||
|
||||
export default createCache;
|
||||
|
||||
@@ -12,7 +12,7 @@ import isObject from '../lang/isObject';
|
||||
function createCtorWrapper(Ctor) {
|
||||
return function() {
|
||||
// Use a `switch` statement to work with class constructors.
|
||||
// See https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
||||
// See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
||||
// for more details.
|
||||
var args = arguments;
|
||||
switch (args.length) {
|
||||
@@ -22,6 +22,8 @@ function createCtorWrapper(Ctor) {
|
||||
case 3: return new Ctor(args[0], args[1], args[2]);
|
||||
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
|
||||
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
|
||||
case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
|
||||
case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
|
||||
}
|
||||
var thisBinding = baseCreate(Ctor.prototype),
|
||||
result = Ctor.apply(thisBinding, args);
|
||||
|
||||
@@ -11,9 +11,9 @@ import isIterateeCall from './isIterateeCall';
|
||||
function createCurry(flag) {
|
||||
function curryFunc(func, arity, guard) {
|
||||
if (guard && isIterateeCall(func, arity, guard)) {
|
||||
arity = null;
|
||||
arity = undefined;
|
||||
}
|
||||
var result = createWrapper(func, flag, null, null, null, null, null, arity);
|
||||
var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
|
||||
result.placeholder = curryFunc.placeholder;
|
||||
return result;
|
||||
}
|
||||
|
||||
22
internal/createDefaults.js
Normal file
22
internal/createDefaults.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import restParam from '../function/restParam';
|
||||
|
||||
/**
|
||||
* Creates a `_.defaults` or `_.defaultsDeep` function.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} assigner The function to assign values.
|
||||
* @param {Function} customizer The function to customize assigned values.
|
||||
* @returns {Function} Returns the new defaults function.
|
||||
*/
|
||||
function createDefaults(assigner, customizer) {
|
||||
return restParam(function(args) {
|
||||
var object = args[0];
|
||||
if (object == null) {
|
||||
return object;
|
||||
}
|
||||
args.push(customizer);
|
||||
return assigner.apply(undefined, args);
|
||||
});
|
||||
}
|
||||
|
||||
export default createDefaults;
|
||||
@@ -1,6 +1,7 @@
|
||||
import arrayExtremum from './arrayExtremum';
|
||||
import baseCallback from './baseCallback';
|
||||
import baseExtremum from './baseExtremum';
|
||||
import isArray from '../lang/isArray';
|
||||
import isIterateeCall from './isIterateeCall';
|
||||
import toIterable from './toIterable';
|
||||
|
||||
@@ -15,11 +16,11 @@ import toIterable from './toIterable';
|
||||
function createExtremum(comparator, exValue) {
|
||||
return function(collection, iteratee, thisArg) {
|
||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||
iteratee = null;
|
||||
iteratee = undefined;
|
||||
}
|
||||
iteratee = baseCallback(iteratee, thisArg, 3);
|
||||
if (iteratee.length == 1) {
|
||||
collection = toIterable(collection);
|
||||
collection = isArray(collection) ? collection : toIterable(collection);
|
||||
var result = arrayExtremum(collection, iteratee, comparator, exValue);
|
||||
if (!(collection.length && result === exValue)) {
|
||||
return result;
|
||||
|
||||
@@ -10,6 +10,9 @@ var CURRY_FLAG = 8,
|
||||
ARY_FLAG = 128,
|
||||
REARG_FLAG = 256;
|
||||
|
||||
/** Used as the size to enable large array optimizations. */
|
||||
var LARGE_ARRAY_SIZE = 200;
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
@@ -34,7 +37,7 @@ function createFlow(fromRight) {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
|
||||
wrapper = new LodashWrapper([]);
|
||||
wrapper = new LodashWrapper([], true);
|
||||
}
|
||||
}
|
||||
index = wrapper ? -1 : length;
|
||||
@@ -42,7 +45,7 @@ function createFlow(fromRight) {
|
||||
func = funcs[index];
|
||||
|
||||
var funcName = getFuncName(func),
|
||||
data = funcName == 'wrapper' ? getData(func) : null;
|
||||
data = funcName == 'wrapper' ? getData(func) : undefined;
|
||||
|
||||
if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
|
||||
wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
|
||||
@@ -51,12 +54,14 @@ function createFlow(fromRight) {
|
||||
}
|
||||
}
|
||||
return function() {
|
||||
var args = arguments;
|
||||
if (wrapper && args.length == 1 && isArray(args[0])) {
|
||||
return wrapper.plant(args[0]).value();
|
||||
var args = arguments,
|
||||
value = args[0];
|
||||
|
||||
if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
|
||||
return wrapper.plant(value).value();
|
||||
}
|
||||
var index = 0,
|
||||
result = length ? funcs[index].apply(this, args) : args[0];
|
||||
result = length ? funcs[index].apply(this, args) : value;
|
||||
|
||||
while (++index < length) {
|
||||
result = funcs[index].call(this, result);
|
||||
|
||||
@@ -45,7 +45,7 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials
|
||||
isCurry = bitmask & CURRY_FLAG,
|
||||
isCurryBound = bitmask & CURRY_BOUND_FLAG,
|
||||
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
|
||||
Ctor = isBindKey ? null : createCtorWrapper(func);
|
||||
Ctor = isBindKey ? undefined : createCtorWrapper(func);
|
||||
|
||||
function wrapper() {
|
||||
// Avoid `arguments` object use disqualifying optimizations by
|
||||
@@ -69,12 +69,12 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials
|
||||
|
||||
length -= argsHolders.length;
|
||||
if (length < arity) {
|
||||
var newArgPos = argPos ? arrayCopy(argPos) : null,
|
||||
var newArgPos = argPos ? arrayCopy(argPos) : undefined,
|
||||
newArity = nativeMax(arity - length, 0),
|
||||
newsHolders = isCurry ? argsHolders : null,
|
||||
newHoldersRight = isCurry ? null : argsHolders,
|
||||
newPartials = isCurry ? args : null,
|
||||
newPartialsRight = isCurry ? null : args;
|
||||
newsHolders = isCurry ? argsHolders : undefined,
|
||||
newHoldersRight = isCurry ? undefined : argsHolders,
|
||||
newPartials = isCurry ? args : undefined,
|
||||
newPartialsRight = isCurry ? undefined : args;
|
||||
|
||||
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
|
||||
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import repeat from '../string/repeat';
|
||||
import root from './root';
|
||||
|
||||
/** Native method references. */
|
||||
var ceil = Math.ceil;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeIsFinite = root.isFinite;
|
||||
var nativeCeil = Math.ceil,
|
||||
nativeIsFinite = root.isFinite;
|
||||
|
||||
/**
|
||||
* Creates the padding required for `string` based on the given `length`.
|
||||
@@ -26,7 +24,7 @@ function createPadding(string, length, chars) {
|
||||
}
|
||||
var padLength = length - strLength;
|
||||
chars = chars == null ? ' ' : (chars + '');
|
||||
return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
|
||||
return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
|
||||
}
|
||||
|
||||
export default createPadding;
|
||||
|
||||
@@ -12,7 +12,7 @@ import restParam from '../function/restParam';
|
||||
function createPartial(flag) {
|
||||
var partialFunc = restParam(function(func, partials) {
|
||||
var holders = replaceHolders(partials, partialFunc.placeholder);
|
||||
return createWrapper(func, flag, null, partials, holders);
|
||||
return createWrapper(func, flag, undefined, partials, holders);
|
||||
});
|
||||
return partialFunc;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ function createPartialWrapper(func, bitmask, thisArg, partials) {
|
||||
argsLength = arguments.length,
|
||||
leftIndex = -1,
|
||||
leftLength = partials.length,
|
||||
args = Array(argsLength + leftLength);
|
||||
args = Array(leftLength + argsLength);
|
||||
|
||||
while (++leftIndex < leftLength) {
|
||||
args[leftIndex] = partials[leftIndex];
|
||||
|
||||
23
internal/createRound.js
Normal file
23
internal/createRound.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/** Native method references. */
|
||||
var pow = Math.pow;
|
||||
|
||||
/**
|
||||
* Creates a `_.ceil`, `_.floor`, or `_.round` function.
|
||||
*
|
||||
* @private
|
||||
* @param {string} methodName The name of the `Math` method to use when rounding.
|
||||
* @returns {Function} Returns the new round function.
|
||||
*/
|
||||
function createRound(methodName) {
|
||||
var func = Math[methodName];
|
||||
return function(number, precision) {
|
||||
precision = precision === undefined ? 0 : (+precision || 0);
|
||||
if (precision) {
|
||||
precision = pow(10, precision);
|
||||
return func(number * precision) / precision;
|
||||
}
|
||||
return func(number);
|
||||
};
|
||||
}
|
||||
|
||||
export default createRound;
|
||||
@@ -51,16 +51,16 @@ function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, a
|
||||
var length = partials ? partials.length : 0;
|
||||
if (!length) {
|
||||
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
|
||||
partials = holders = null;
|
||||
partials = holders = undefined;
|
||||
}
|
||||
length -= (holders ? holders.length : 0);
|
||||
if (bitmask & PARTIAL_RIGHT_FLAG) {
|
||||
var partialsRight = partials,
|
||||
holdersRight = holders;
|
||||
|
||||
partials = holders = null;
|
||||
partials = holders = undefined;
|
||||
}
|
||||
var data = isBindKey ? null : getData(func),
|
||||
var data = isBindKey ? undefined : getData(func),
|
||||
newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
|
||||
|
||||
if (data) {
|
||||
|
||||
@@ -14,7 +14,7 @@ var boolTag = '[object Boolean]',
|
||||
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} value The object to compare.
|
||||
* @param {Object} object The object to compare.
|
||||
* @param {Object} other The other object to compare.
|
||||
* @param {string} tag The `toStringTag` of the objects to compare.
|
||||
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
||||
|
||||
38
internal/escapeRegExpChar.js
Normal file
38
internal/escapeRegExpChar.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/** Used to escape characters for inclusion in compiled regexes. */
|
||||
var regexpEscapes = {
|
||||
'0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
|
||||
'5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
|
||||
'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
|
||||
'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
|
||||
'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
|
||||
};
|
||||
|
||||
/** Used to escape characters for inclusion in compiled string literals. */
|
||||
var stringEscapes = {
|
||||
'\\': '\\',
|
||||
"'": "'",
|
||||
'\n': 'n',
|
||||
'\r': 'r',
|
||||
'\u2028': 'u2028',
|
||||
'\u2029': 'u2029'
|
||||
};
|
||||
|
||||
/**
|
||||
* Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
|
||||
*
|
||||
* @private
|
||||
* @param {string} chr The matched character to escape.
|
||||
* @param {string} leadingChar The capture group for a leading character.
|
||||
* @param {string} whitespaceChar The capture group for a whitespace character.
|
||||
* @returns {string} Returns the escaped character.
|
||||
*/
|
||||
function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
|
||||
if (leadingChar) {
|
||||
chr = regexpEscapes[chr];
|
||||
} else if (whitespaceChar) {
|
||||
chr = stringEscapes[chr];
|
||||
}
|
||||
return '\\' + chr;
|
||||
}
|
||||
|
||||
export default escapeRegExpChar;
|
||||
@@ -9,8 +9,7 @@ var stringEscapes = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Used by `_.template` to escape characters for inclusion in compiled
|
||||
* string literals.
|
||||
* Used by `_.template` to escape characters for inclusion in compiled string literals.
|
||||
*
|
||||
* @private
|
||||
* @param {string} chr The matched character to escape.
|
||||
|
||||
@@ -8,13 +8,13 @@ var nativeMax = Math.max,
|
||||
* @private
|
||||
* @param {number} start The start of the view.
|
||||
* @param {number} end The end of the view.
|
||||
* @param {Array} [transforms] The transformations to apply to the view.
|
||||
* @param {Array} transforms The transformations to apply to the view.
|
||||
* @returns {Object} Returns an object containing the `start` and `end`
|
||||
* positions of the view.
|
||||
*/
|
||||
function getView(start, end, transforms) {
|
||||
var index = -1,
|
||||
length = transforms ? transforms.length : 0;
|
||||
length = transforms.length;
|
||||
|
||||
while (++index < length) {
|
||||
var data = transforms[index],
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
var reIsUint = /^\d+$/;
|
||||
|
||||
/**
|
||||
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
||||
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
||||
* of an array-like value.
|
||||
*/
|
||||
var MAX_SAFE_INTEGER = 9007199254740991;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
||||
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
||||
* of an array-like value.
|
||||
*/
|
||||
var MAX_SAFE_INTEGER = 9007199254740991;
|
||||
@@ -7,7 +7,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
|
||||
/**
|
||||
* Checks if `value` is a valid array-like length.
|
||||
*
|
||||
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
|
||||
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to check.
|
||||
|
||||
@@ -10,17 +10,13 @@ import arrayCopy from './arrayCopy';
|
||||
* @returns {Object} Returns the cloned `LazyWrapper` object.
|
||||
*/
|
||||
function lazyClone() {
|
||||
var actions = this.__actions__,
|
||||
iteratees = this.__iteratees__,
|
||||
views = this.__views__,
|
||||
result = new LazyWrapper(this.__wrapped__);
|
||||
|
||||
result.__actions__ = actions ? arrayCopy(actions) : null;
|
||||
var result = new LazyWrapper(this.__wrapped__);
|
||||
result.__actions__ = arrayCopy(this.__actions__);
|
||||
result.__dir__ = this.__dir__;
|
||||
result.__filtered__ = this.__filtered__;
|
||||
result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
|
||||
result.__iteratees__ = arrayCopy(this.__iteratees__);
|
||||
result.__takeCount__ = this.__takeCount__;
|
||||
result.__views__ = views ? arrayCopy(views) : null;
|
||||
result.__views__ = arrayCopy(this.__views__);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ import baseWrapperValue from './baseWrapperValue';
|
||||
import getView from './getView';
|
||||
import isArray from '../lang/isArray';
|
||||
|
||||
/** Used as the size to enable large array optimizations. */
|
||||
var LARGE_ARRAY_SIZE = 200;
|
||||
|
||||
/** Used to indicate the type of lazy iteratees. */
|
||||
var LAZY_DROP_WHILE_FLAG = 0,
|
||||
LAZY_FILTER_FLAG = 1,
|
||||
var LAZY_FILTER_FLAG = 1,
|
||||
LAZY_MAP_FLAG = 2;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
@@ -19,22 +21,25 @@ var nativeMin = Math.min;
|
||||
* @returns {*} Returns the unwrapped value.
|
||||
*/
|
||||
function lazyValue() {
|
||||
var array = this.__wrapped__.value();
|
||||
if (!isArray(array)) {
|
||||
return baseWrapperValue(array, this.__actions__);
|
||||
}
|
||||
var dir = this.__dir__,
|
||||
var array = this.__wrapped__.value(),
|
||||
dir = this.__dir__,
|
||||
isArr = isArray(array),
|
||||
isRight = dir < 0,
|
||||
view = getView(0, array.length, this.__views__),
|
||||
arrLength = isArr ? array.length : 0,
|
||||
view = getView(0, arrLength, this.__views__),
|
||||
start = view.start,
|
||||
end = view.end,
|
||||
length = end - start,
|
||||
index = isRight ? end : (start - 1),
|
||||
takeCount = nativeMin(length, this.__takeCount__),
|
||||
iteratees = this.__iteratees__,
|
||||
iterLength = iteratees ? iteratees.length : 0,
|
||||
iterLength = iteratees.length,
|
||||
resIndex = 0,
|
||||
result = [];
|
||||
takeCount = nativeMin(length, this.__takeCount__);
|
||||
|
||||
if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
|
||||
return baseWrapperValue((isRight && isArr) ? array.reverse() : array, this.__actions__);
|
||||
}
|
||||
var result = [];
|
||||
|
||||
outer:
|
||||
while (length-- && resIndex < takeCount) {
|
||||
@@ -46,30 +51,16 @@ function lazyValue() {
|
||||
while (++iterIndex < iterLength) {
|
||||
var data = iteratees[iterIndex],
|
||||
iteratee = data.iteratee,
|
||||
type = data.type;
|
||||
type = data.type,
|
||||
computed = iteratee(value);
|
||||
|
||||
if (type == LAZY_DROP_WHILE_FLAG) {
|
||||
if (data.done && (isRight ? (index > data.index) : (index < data.index))) {
|
||||
data.count = 0;
|
||||
data.done = false;
|
||||
}
|
||||
data.index = index;
|
||||
if (!data.done) {
|
||||
var limit = data.limit;
|
||||
if (!(data.done = limit > -1 ? (data.count++ >= limit) : !iteratee(value))) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var computed = iteratee(value);
|
||||
if (type == LAZY_MAP_FLAG) {
|
||||
value = computed;
|
||||
} else if (!computed) {
|
||||
if (type == LAZY_FILTER_FLAG) {
|
||||
continue outer;
|
||||
} else {
|
||||
break outer;
|
||||
}
|
||||
if (type == LAZY_MAP_FLAG) {
|
||||
value = computed;
|
||||
} else if (!computed) {
|
||||
if (type == LAZY_FILTER_FLAG) {
|
||||
continue outer;
|
||||
} else {
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
internal/mergeDefaults.js
Normal file
15
internal/mergeDefaults.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import merge from '../object/merge';
|
||||
|
||||
/**
|
||||
* Used by `_.defaultsDeep` to customize its `_.merge` use.
|
||||
*
|
||||
* @private
|
||||
* @param {*} objectValue The destination object property value.
|
||||
* @param {*} sourceValue The source object property value.
|
||||
* @returns {*} Returns the value to assign to the destination object.
|
||||
*/
|
||||
function mergeDefaults(objectValue, sourceValue) {
|
||||
return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
|
||||
}
|
||||
|
||||
export default mergeDefaults;
|
||||
@@ -1,50 +0,0 @@
|
||||
import baseForIn from './baseForIn';
|
||||
import isObjectLike from './isObjectLike';
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var objectTag = '[object Object]';
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* of values.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
/**
|
||||
* A fallback implementation of `_.isPlainObject` which checks if `value`
|
||||
* is an object created by the `Object` constructor or has a `[[Prototype]]`
|
||||
* of `null`.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
|
||||
*/
|
||||
function shimIsPlainObject(value) {
|
||||
var Ctor;
|
||||
|
||||
// Exit early for non `Object` objects.
|
||||
if (!(isObjectLike(value) && objToString.call(value) == objectTag) ||
|
||||
(!hasOwnProperty.call(value, 'constructor') &&
|
||||
(Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
|
||||
return false;
|
||||
}
|
||||
// IE < 9 iterates inherited properties before own properties. If the first
|
||||
// iterated property is an object's own property then there are no inherited
|
||||
// enumerable properties.
|
||||
var result;
|
||||
// In most environments an object's own properties are iterated before
|
||||
// its inherited properties. If the last iterated property is an object's
|
||||
// own property then there are no inherited enumerable properties.
|
||||
baseForIn(value, function(subValue, key) {
|
||||
result = key;
|
||||
});
|
||||
return result === undefined || hasOwnProperty.call(value, result);
|
||||
}
|
||||
|
||||
export default shimIsPlainObject;
|
||||
Reference in New Issue
Block a user