Compare commits

..

3 Commits

Author SHA1 Message Date
jdalton
3d3907ff27 Bump to v3.9.2. 2015-05-24 01:42:23 -07:00
jdalton
30daf83737 Bump to v3.9.0. 2015-05-19 08:43:25 -07:00
jdalton
d7b2bedafc Bump to v3.8.0. 2015-05-01 01:02:48 -07:00
138 changed files with 854 additions and 768 deletions

View File

@@ -1,4 +1,4 @@
# lodash-es v3.7.0
# lodash-es v3.9.2
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [ES](https://people.mozilla.org/~jorendorff/es6-draft.html) modules.
@@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli):
$ lodash modularize modern exports=es -o ./
```
See the [package source](https://github.com/lodash/lodash/tree/3.7.0-es) for more details.
See the [package source](https://github.com/lodash/lodash/tree/3.9.2-es) for more details.

View File

@@ -34,10 +34,12 @@ import union from './array/union';
import uniq from './array/uniq';
import unique from './array/unique';
import unzip from './array/unzip';
import unzipWith from './array/unzipWith';
import without from './array/without';
import xor from './array/xor';
import zip from './array/zip';
import zipObject from './array/zipObject';
import zipWith from './array/zipWith';
export default {
'chunk': chunk,
@@ -76,8 +78,10 @@ export default {
'uniq': uniq,
'unique': unique,
'unzip': unzip,
'unzipWith': unzipWith,
'without': without,
'xor': xor,
'zip': zip,
'zipObject': zipObject
'zipObject': zipObject,
'zipWith': zipWith
};

View File

@@ -1,16 +1,12 @@
import baseDifference from '../internal/baseDifference';
import baseFlatten from '../internal/baseFlatten';
import isArguments from '../lang/isArguments';
import isArray from '../lang/isArray';
import isArrayLike from '../internal/isArrayLike';
import restParam from '../function/restParam';
/**
* Creates an array excluding all values of the provided arrays using
* `SameValueZero` for equality comparisons.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* Creates an array of unique `array` values not included in the other
* provided arrays using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _
@@ -24,7 +20,7 @@ import restParam from '../function/restParam';
* // => [1, 3]
*/
var difference = restParam(function(array, values) {
return (isArray(array) || isArguments(array))
return isArrayLike(array)
? baseDifference(array, baseFlatten(values, false, true))
: [];
});

View File

@@ -6,13 +6,10 @@ var nativeMax = Math.max;
/**
* Gets the index at which the first occurrence of `value` is found in `array`
* using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
* it is used as the offset from the end of `array`. If `array` is sorted
* providing `true` for `fromIndex` performs a faster binary search.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
* performs a faster binary search.
*
* @static
* @memberOf _

View File

@@ -1,17 +1,14 @@
import baseIndexOf from '../internal/baseIndexOf';
import cacheIndexOf from '../internal/cacheIndexOf';
import createCache from '../internal/createCache';
import isArguments from '../lang/isArguments';
import isArray from '../lang/isArray';
import isArrayLike from '../internal/isArrayLike';
import restParam from '../function/restParam';
/**
* Creates an array of unique values in all provided arrays using `SameValueZero`
* Creates an array of unique values that are included in all of the provided
* arrays using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @category Array
@@ -21,27 +18,19 @@ import isArray from '../lang/isArray';
* _.intersection([1, 2], [4, 2], [2, 1]);
* // => [2]
*/
function intersection() {
var args = [],
argsIndex = -1,
argsLength = arguments.length,
caches = [],
var intersection = restParam(function(arrays) {
var othLength = arrays.length,
othIndex = othLength,
caches = Array(length),
indexOf = baseIndexOf,
isCommon = true,
result = [];
while (++argsIndex < argsLength) {
var value = arguments[argsIndex];
if (isArray(value) || isArguments(value)) {
args.push(value);
caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null);
}
while (othIndex--) {
var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
}
argsLength = args.length;
if (argsLength < 2) {
return result;
}
var array = args[0],
var array = arrays[0],
index = -1,
length = array ? array.length : 0,
seen = caches[0];
@@ -50,10 +39,10 @@ function intersection() {
while (++index < length) {
value = array[index];
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
argsIndex = argsLength;
while (--argsIndex) {
var cache = caches[argsIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value, 0)) < 0) {
var othIndex = othLength;
while (--othIndex) {
var cache = caches[othIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
continue outer;
}
}
@@ -64,6 +53,6 @@ function intersection() {
}
}
return result;
}
});
export default intersection;

View File

@@ -7,14 +7,11 @@ var arrayProto = Array.prototype;
var splice = arrayProto.splice;
/**
* Removes all provided values from `array` using `SameValueZero` for equality
* comparisons.
* Removes all provided values from `array` using
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* **Notes:**
* - Unlike `_.without`, this method mutates `array`
* - [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except
* that `NaN` matches `NaN`
* **Note:** Unlike `_.without`, this method mutates `array`.
*
* @static
* @memberOf _

View File

@@ -30,7 +30,6 @@ import restParam from '../function/restParam';
* // => [10, 20]
*/
var pullAt = restParam(function(array, indexes) {
array || (array = []);
indexes = baseFlatten(indexes);
var result = baseAt(array, indexes);

View File

@@ -3,12 +3,9 @@ import baseUniq from '../internal/baseUniq';
import restParam from '../function/restParam';
/**
* Creates an array of unique values, in order, of the provided arrays using
* `SameValueZero` for equality comparisons.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* Creates an array of unique values, in order, from all of the provided arrays
* using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _

View File

@@ -4,8 +4,9 @@ import isIterateeCall from '../internal/isIterateeCall';
import sortedUniq from '../internal/sortedUniq';
/**
* Creates a duplicate-free version of an array, using `SameValueZero` for
* equality comparisons, in which only the first occurence of each element
* Creates a duplicate-free version of an array, using
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons, in which only the first occurence of each element
* is kept. Providing `true` for `isSorted` performs a faster search algorithm
* for sorted arrays. If an iteratee function is provided it is invoked for
* each element in the array to generate the criterion by which uniqueness
@@ -23,10 +24,6 @@ import sortedUniq from '../internal/sortedUniq';
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _
* @alias unique

View File

@@ -1,11 +1,14 @@
import arrayFilter from '../internal/arrayFilter';
import arrayMap from '../internal/arrayMap';
import arrayMax from '../internal/arrayMax';
import baseProperty from '../internal/baseProperty';
import getLength from '../internal/getLength';
import isArrayLike from '../internal/isArrayLike';
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* This method is like `_.zip` except that it accepts an array of grouped
* elements and creates an array regrouping the elements to their pre-`_.zip`
* elements and creates an array regrouping the elements to their pre-zip
* configuration.
*
* @static
@@ -22,10 +25,19 @@ import getLength from '../internal/getLength';
* // => [['fred', 'barney'], [30, 40], [true, false]]
*/
function unzip(array) {
if (!(array && array.length)) {
return [];
}
var index = -1,
length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0,
result = Array(length);
length = 0;
array = arrayFilter(array, function(group) {
if (isArrayLike(group)) {
length = nativeMax(group.length, length);
return true;
}
});
var result = Array(length);
while (++index < length) {
result[index] = arrayMap(array, baseProperty(index));
}

41
array/unzipWith.js Normal file
View File

@@ -0,0 +1,41 @@
import arrayMap from '../internal/arrayMap';
import arrayReduce from '../internal/arrayReduce';
import bindCallback from '../internal/bindCallback';
import unzip from './unzip';
/**
* This method is like `_.unzip` except that it accepts an iteratee to specify
* how regrouped values should be combined. The `iteratee` is bound to `thisArg`
* and invoked with four arguments: (accumulator, value, index, group).
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array of grouped elements to process.
* @param {Function} [iteratee] The function to combine regrouped values.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new array of regrouped elements.
* @example
*
* var zipped = _.zip([1, 2], [10, 20], [100, 200]);
* // => [[1, 10, 100], [2, 20, 200]]
*
* _.unzipWith(zipped, _.add);
* // => [3, 30, 300]
*/
function unzipWith(array, iteratee, thisArg) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
var result = unzip(array);
if (iteratee == null) {
return result;
}
iteratee = bindCallback(iteratee, thisArg, 4);
return arrayMap(result, function(group) {
return arrayReduce(group, iteratee, undefined, true);
});
}
export default unzipWith;

View File

@@ -1,15 +1,11 @@
import baseDifference from '../internal/baseDifference';
import isArguments from '../lang/isArguments';
import isArray from '../lang/isArray';
import isArrayLike from '../internal/isArrayLike';
import restParam from '../function/restParam';
/**
* Creates an array excluding all provided values using `SameValueZero` for
* equality comparisons.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* Creates an array excluding all provided values using
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons.
*
* @static
* @memberOf _
@@ -23,7 +19,7 @@ import restParam from '../function/restParam';
* // => [3]
*/
var without = restParam(function(array, values) {
return (isArray(array) || isArguments(array))
return isArrayLike(array)
? baseDifference(array, values)
: [];
});

View File

@@ -1,10 +1,9 @@
import baseDifference from '../internal/baseDifference';
import baseUniq from '../internal/baseUniq';
import isArguments from '../lang/isArguments';
import isArray from '../lang/isArray';
import isArrayLike from '../internal/isArrayLike';
/**
* Creates an array that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
* Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
* of the provided arrays.
*
* @static
@@ -23,7 +22,7 @@ function xor() {
while (++index < length) {
var array = arguments[index];
if (isArray(array) || isArguments(array)) {
if (isArrayLike(array)) {
var result = result
? baseDifference(result, array).concat(baseDifference(array, result))
: array;

36
array/zipWith.js Normal file
View File

@@ -0,0 +1,36 @@
import restParam from '../function/restParam';
import unzipWith from './unzipWith';
/**
* This method is like `_.zip` except that it accepts an iteratee to specify
* how grouped values should be combined. The `iteratee` is bound to `thisArg`
* and invoked with four arguments: (accumulator, value, index, group).
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to process.
* @param {Function} [iteratee] The function to combine grouped values.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new array of grouped elements.
* @example
*
* _.zipWith([1, 2], [10, 20], [100, 200], _.add);
* // => [111, 222]
*/
var zipWith = restParam(function(arrays) {
var length = arrays.length,
iteratee = length > 2 ? arrays[length - 2] : undefined,
thisArg = length > 1 ? arrays[length - 1] : undefined;
if (length > 2 && typeof iteratee == 'function') {
length -= 2;
} else {
iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
thisArg = undefined;
}
arrays.length = length;
return unzipWith(arrays, iteratee, thisArg);
});
export default zipWith;

View File

@@ -50,30 +50,31 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
* `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
* `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
* `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`,
* `merge`, `mixin`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
* `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
* `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
* `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
* `without`, `wrap`, `xor`, `zip`, and `zipObject`
* `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
* `memoize`, `merge`, `method`, `methodOf`, `mixin`, `negate`, `omit`, `once`,
* `pairs`, `partial`, `partialRight`, `partition`, `pick`, `plant`, `pluck`,
* `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, `rearg`,
* `reject`, `remove`, `rest`, `restParam`, `reverse`, `set`, `shuffle`,
* `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`, `spread`,
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
* `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
* `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `where`, `without`,
* `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
*
* The wrapper methods that are **not** chainable by default are:
* `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
* `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`
* `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`,
* `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `isTypedArray`,
* `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, `noConflict`,
* `noop`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`,
* `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, `shift`, `size`,
* `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`, `startsWith`,
* `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`,
* `uniqueId`, `value`, and `words`
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `get`,
* `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`,
* `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
* `isFinite` `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `lt`, `lte`,
* `max`, `min`, `noConflict`, `noop`, `now`, `pad`, `padLeft`, `padRight`,
* `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`,
* `runInContext`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
* `sortedLastIndex`, `startCase`, `startsWith`, `sum`, `template`, `trim`,
* `trimLeft`, `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
*
* The wrapper method `sample` will return a wrapped value when `n` is provided,
* otherwise an unwrapped value is returned.

View File

@@ -1,9 +1,6 @@
import baseAt from '../internal/baseAt';
import baseFlatten from '../internal/baseFlatten';
import getLength from '../internal/getLength';
import isLength from '../internal/isLength';
import restParam from '../function/restParam';
import toIterable from '../internal/toIterable';
/**
* Creates an array of elements corresponding to the given keys, or indexes,
@@ -26,10 +23,6 @@ import toIterable from '../internal/toIterable';
* // => ['barney', 'pebbles']
*/
var at = restParam(function(collection, props) {
var length = collection ? getLength(collection) : 0;
if (isLength(length)) {
collection = toIterable(collection);
}
return baseAt(collection, baseFlatten(props));
});

View File

@@ -10,13 +10,10 @@ import values from '../object/values';
var nativeMax = Math.max;
/**
* Checks if `value` is in `collection` using `SameValueZero` for equality
* comparisons. If `fromIndex` is negative, it is used as the offset from
* the end of `collection`.
*
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
* Checks if `value` is in `collection` using
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
* from the end of `collection`.
*
* @static
* @memberOf _

View File

@@ -1,12 +1,11 @@
import baseEach from '../internal/baseEach';
import getLength from '../internal/getLength';
import invokePath from '../internal/invokePath';
import isArrayLike from '../internal/isArrayLike';
import isKey from '../internal/isKey';
import isLength from '../internal/isLength';
import restParam from '../function/restParam';
/**
* Invokes the method at `path` on each element in `collection`, returning
* Invokes the method at `path` of each element in `collection`, returning
* an array of the results of each invoked method. Any additional arguments
* are provided to each invoked method. If `methodName` is a function it is
* invoked for, and `this` bound to, each element in `collection`.
@@ -31,11 +30,10 @@ var invoke = restParam(function(collection, path, args) {
var index = -1,
isFunc = typeof path == 'function',
isProp = isKey(path),
length = getLength(collection),
result = isLength(length) ? Array(length) : [];
result = isArrayLike(collection) ? Array(collection.length) : [];
baseEach(collection, function(value) {
var func = isFunc ? path : (isProp && value != null && value[path]);
var func = isFunc ? path : ((isProp && value != null) ? value[path] : null);
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
});
return result;

View File

@@ -19,14 +19,15 @@ import isArray from '../lang/isArray';
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* Many lodash methods are guarded to work as interatees for methods like
* Many lodash methods are guarded to work as iteratees for methods like
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
*
* The guarded methods are:
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
* `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`,
* `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`,
* `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words`
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
* `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
* `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
* `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
* `sum`, `uniq`, and `words`
*
* @static
* @memberOf _

View File

@@ -10,7 +10,7 @@ import createReduce from '../internal/createReduce';
* value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
* (accumulator, value, index|key, collection).
*
* Many lodash methods are guarded to work as interatees for methods like
* Many lodash methods are guarded to work as iteratees for methods like
* `_.reduce`, `_.reduceRight`, and `_.transform`.
*
* The guarded methods are:

View File

@@ -24,6 +24,6 @@ import createReduce from '../internal/createReduce';
* }, []);
* // => [4, 5, 2, 3, 0, 1]
*/
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
export default reduceRight;

View File

@@ -7,17 +7,6 @@ import isArray from '../lang/isArray';
* The opposite of `_.filter`; this method returns the elements of `collection`
* that `predicate` does **not** return truthy for.
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection

View File

@@ -1,6 +1,6 @@
import baseRandom from '../internal/baseRandom';
import isIterateeCall from '../internal/isIterateeCall';
import shuffle from './shuffle';
import toArray from '../lang/toArray';
import toIterable from '../internal/toIterable';
/* Native method references for those with the same name as other `lodash` methods. */
@@ -30,8 +30,20 @@ function sample(collection, n, guard) {
var length = collection.length;
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
}
var result = shuffle(collection);
result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
var index = -1,
result = toArray(collection),
length = result.length,
lastIndex = length - 1;
n = nativeMin(n < 0 ? 0 : (+n || 0), length);
while (++index < n) {
var rand = baseRandom(index, lastIndex),
value = result[rand];
result[rand] = result[index];
result[index] = value;
}
result.length = n;
return result;
}

View File

@@ -1,5 +1,7 @@
import baseRandom from '../internal/baseRandom';
import toIterable from '../internal/toIterable';
import sample from './sample';
/** Used as references for `-Infinity` and `Infinity`. */
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
/**
* Creates an array of shuffled values, using a version of the
@@ -16,20 +18,7 @@ import toIterable from '../internal/toIterable';
* // => [4, 1, 3, 2]
*/
function shuffle(collection) {
collection = toIterable(collection);
var index = -1,
length = collection.length,
result = Array(length);
while (++index < length) {
var rand = baseRandom(0, index);
if (index != rand) {
result[index] = result[rand];
}
result[rand] = collection[index];
}
return result;
return sample(collection, POSITIVE_INFINITY);
}
export default shuffle;

View File

@@ -1,7 +1,7 @@
import isNative from '../lang/isNative';
import getNative from '../internal/getNative';
/* Native method references for those with the same name as other `lodash` methods. */
var nativeNow = isNative(nativeNow = Date.now) && nativeNow;
var nativeNow = getNative(Date, 'now');
/**
* Gets the number of milliseconds that have elapsed since the Unix epoch

View File

@@ -8,12 +8,13 @@ var FUNC_ERROR_TEXT = 'Expected a function';
var nativeMax = Math.max;
/**
* Creates a function that delays invoking `func` until after `wait` milliseconds
* have elapsed since the last time it was invoked. The created function comes
* with a `cancel` method to cancel delayed invocations. Provide an options
* object to indicate that `func` should be invoked on the leading and/or
* trailing edge of the `wait` timeout. Subsequent calls to the debounced
* function return the result of the last `func` invocation.
* Creates a debounced function that delays invoking `func` until after `wait`
* milliseconds have elapsed since the last time the debounced function was
* invoked. The debounced function comes with a `cancel` method to cancel
* delayed invocations. Provide an options object to indicate that `func`
* should be invoked on the leading and/or trailing edge of the `wait` timeout.
* Subsequent calls to the debounced function return the result of the last
* `func` invocation.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
* on the trailing edge of the timeout only if the the debounced function is

View File

@@ -60,14 +60,14 @@ function memoize(func, resolver) {
}
var memoized = function() {
var args = arguments,
cache = memoized.cache,
key = resolver ? resolver.apply(this, args) : args[0];
key = resolver ? resolver.apply(this, args) : args[0],
cache = memoized.cache;
if (cache.has(key)) {
return cache.get(key);
}
var result = func.apply(this, args);
cache.set(key, result);
memoized.cache = cache.set(key, result);
return result;
};
memoized.cache = new memoize.Cache;

View File

@@ -12,12 +12,12 @@ var debounceOptions = {
};
/**
* Creates a function that only invokes `func` at most once per every `wait`
* milliseconds. The created function comes with a `cancel` method to cancel
* delayed invocations. Provide an options object to indicate that `func`
* should be invoked on the leading and/or trailing edge of the `wait` timeout.
* Subsequent calls to the throttled function return the result of the last
* `func` call.
* Creates a throttled function that only invokes `func` at most once per
* every `wait` milliseconds. The throttled function comes with a `cancel`
* method to cancel delayed invocations. Provide an options object to indicate
* that `func` should be invoked on the leading and/or trailing edge of the
* `wait` timeout. Subsequent calls to the throttled function return the
* result of the last `func` call.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
* on the trailing edge of the timeout only if the the throttled function is

View File

@@ -1,12 +1,12 @@
import cachePush from './cachePush';
import isNative from '../lang/isNative';
import getNative from './getNative';
import root from './root';
/** Native method references. */
var Set = isNative(Set = root.Set) && Set;
var Set = getNative(root, 'Set');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate;
var nativeCreate = getNative(Object, 'create');
/**
*

30
internal/arrayExtremum.js Normal file
View File

@@ -0,0 +1,30 @@
/**
* A specialized version of `baseExtremum` for arrays which invokes `iteratee`
* with one argument: (value).
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {Function} comparator The function used to compare values.
* @param {*} exValue The initial extremum value.
* @returns {*} Returns the extremum value.
*/
function arrayExtremum(array, iteratee, comparator, exValue) {
var index = -1,
length = array.length,
computed = exValue,
result = computed;
while (++index < length) {
var value = array[index],
current = +iteratee(value);
if (comparator(current, computed)) {
computed = current;
result = value;
}
}
return result;
}
export default arrayExtremum;

View File

@@ -1,25 +0,0 @@
/** Used as references for `-Infinity` and `Infinity`. */
var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;
/**
* A specialized version of `_.max` for arrays without support for iteratees.
*
* @private
* @param {Array} array The array to iterate over.
* @returns {*} Returns the maximum value.
*/
function arrayMax(array) {
var index = -1,
length = array.length,
result = NEGATIVE_INFINITY;
while (++index < length) {
var value = array[index];
if (value > result) {
result = value;
}
}
return result;
}
export default arrayMax;

View File

@@ -1,25 +0,0 @@
/** Used as references for `-Infinity` and `Infinity`. */
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
/**
* A specialized version of `_.min` for arrays without support for iteratees.
*
* @private
* @param {Array} array The array to iterate over.
* @returns {*} Returns the minimum value.
*/
function arrayMin(array) {
var index = -1,
length = array.length,
result = POSITIVE_INFINITY;
while (++index < length) {
var value = array[index];
if (value < result) {
result = value;
}
}
return result;
}
export default arrayMin;

View File

@@ -1,12 +1,5 @@
import getSymbols from './getSymbols';
import keys from '../object/keys';
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var push = arrayProto.push;
/**
* A specialized version of `_.assign` for customizing assigned values without
* support for argument juggling, multiple sources, and `this` binding `customizer`
@@ -19,10 +12,8 @@ var push = arrayProto.push;
* @returns {Object} Returns `object`.
*/
function assignWith(object, source, customizer) {
var props = keys(source);
push.apply(props, getSymbols(source));
var index = -1,
props = keys(source),
length = props.length;
while (++index < length) {

View File

@@ -1,27 +1,6 @@
import baseCopy from './baseCopy';
import getSymbols from './getSymbols';
import isNative from '../lang/isNative';
import keys from '../object/keys';
/** Native method references. */
var preventExtensions = isNative(Object.preventExtensions = Object.preventExtensions) && preventExtensions;
/** Used as `baseAssign`. */
var nativeAssign = (function() {
// Avoid `Object.assign` in Firefox 34-37 which have an early implementation
// with a now defunct try/catch behavior. See https://bugzilla.mozilla.org/show_bug.cgi?id=1103344
// for more details.
//
// Use `Object.preventExtensions` on a plain object instead of simply using
// `Object('x')` because Chrome and IE fail to throw an error when attempting
// to assign values to readonly indexes of strings in strict mode.
var object = { '1': 0 },
func = preventExtensions && isNative(func = Object.assign) && func;
try { func(preventExtensions(object), 'xo'); } catch(e) {}
return !object[1] && func;
}());
/**
* The base implementation of `_.assign` without support for argument juggling,
* multiple sources, and `customizer` functions.
@@ -31,10 +10,10 @@ var nativeAssign = (function() {
* @param {Object} source The source object.
* @returns {Object} Returns `object`.
*/
var baseAssign = nativeAssign || function(object, source) {
function baseAssign(object, source) {
return source == null
? object
: baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object));
};
: baseCopy(source, keys(source), object);
}
export default baseAssign;

View File

@@ -1,5 +1,5 @@
import isArrayLike from './isArrayLike';
import isIndex from './isIndex';
import isLength from './isLength';
/**
* The base implementation of `_.at` without support for string collections
@@ -12,8 +12,9 @@ import isLength from './isLength';
*/
function baseAt(collection, props) {
var index = -1,
length = collection.length,
isArr = isLength(length),
isNil = collection == null,
isArr = !isNil && isArrayLike(collection),
length = isArr ? collection.length : 0,
propsLength = props.length,
result = Array(propsLength);
@@ -22,7 +23,7 @@ function baseAt(collection, props) {
if (isArr) {
result[index] = isIndex(key, length) ? collection[key] : undefined;
} else {
result[index] = collection[key];
result[index] = isNil ? undefined : collection[key];
}
}
return result;

View File

@@ -3,19 +3,28 @@
* sorts them in ascending order without guaranteeing a stable sort.
*
* @private
* @param {*} value The value to compare to `other`.
* @param {*} other The value to compare to `value`.
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {number} Returns the sort order indicator for `value`.
*/
function baseCompareAscending(value, other) {
if (value !== other) {
var valIsReflexive = value === value,
var valIsNull = value === null,
valIsUndef = value === undefined,
valIsReflexive = value === value;
var othIsNull = other === null,
othIsUndef = other === undefined,
othIsReflexive = other === other;
if (value > other || !valIsReflexive || (value === undefined && othIsReflexive)) {
if ((value > other && !othIsNull) || !valIsReflexive ||
(valIsNull && !othIsUndef && othIsReflexive) ||
(valIsUndef && othIsReflexive)) {
return 1;
}
if (value < other || !othIsReflexive || (other === undefined && valIsReflexive)) {
if ((value < other && !valIsNull) || !othIsReflexive ||
(othIsNull && !valIsUndef && valIsReflexive) ||
(othIsUndef && valIsReflexive)) {
return -1;
}
}

View File

@@ -1,5 +1,4 @@
import isObject from '../lang/isObject';
import root from './root';
/**
* The base implementation of `_.create` without support for assigning
@@ -10,14 +9,14 @@ import root from './root';
* @returns {Object} Returns the new object.
*/
var baseCreate = (function() {
function Object() {}
function object() {}
return function(prototype) {
if (isObject(prototype)) {
Object.prototype = prototype;
var result = new Object;
Object.prototype = null;
object.prototype = prototype;
var result = new object;
object.prototype = null;
}
return result || root.Object();
return result || {};
};
}());

View File

@@ -1,30 +1,24 @@
import baseEach from './baseEach';
/** Used as references for `-Infinity` and `Infinity`. */
var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
POSITIVE_INFINITY = Number.POSITIVE_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|key, collection).
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {boolean} [isMin] Specify returning the minimum, instead of the
* maximum, extremum value.
* @param {Function} comparator The function used to compare values.
* @param {*} exValue The initial extremum value.
* @returns {*} Returns the extremum value.
*/
function extremumBy(collection, iteratee, isMin) {
var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY,
computed = exValue,
function baseExtremum(collection, iteratee, comparator, exValue) {
var computed = exValue,
result = computed;
baseEach(collection, function(value, index, collection) {
var current = iteratee(value, index, collection);
if ((isMin ? (current < computed) : (current > computed)) ||
(current === exValue && current === result)) {
var current = +iteratee(value, index, collection);
if (comparator(current, computed) || (current === exValue && current === result)) {
computed = current;
result = value;
}
@@ -32,4 +26,4 @@ function extremumBy(collection, iteratee, isMin) {
return result;
}
export default extremumBy;
export default baseExtremum;

View File

@@ -1,6 +1,6 @@
import isArguments from '../lang/isArguments';
import isArray from '../lang/isArray';
import isLength from './isLength';
import isArrayLike from './isArrayLike';
import isObjectLike from './isObjectLike';
/**
@@ -9,8 +9,8 @@ import isObjectLike from './isObjectLike';
*
* @private
* @param {Array} array The array to flatten.
* @param {boolean} isDeep Specify a deep flatten.
* @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
* @param {boolean} [isDeep] Specify a deep flatten.
* @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
* @returns {Array} Returns the new flattened array.
*/
function baseFlatten(array, isDeep, isStrict) {
@@ -21,8 +21,8 @@ function baseFlatten(array, isDeep, isStrict) {
while (++index < length) {
var value = array[index];
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
if (isObjectLike(value) && isArrayLike(value) &&
(isStrict || isArray(value) || isArguments(value))) {
if (isDeep) {
// Recursively flatten arrays (susceptible to call stack limits).
value = baseFlatten(value, isDeep, isStrict);
@@ -30,7 +30,6 @@ function baseFlatten(array, isDeep, isStrict) {
var valIndex = -1,
valLength = value.length;
result.length += valLength;
while (++valIndex < valLength) {
result[++resIndex] = value[valIndex];
}

View File

@@ -17,13 +17,13 @@ function baseGet(object, path, pathKey) {
if (pathKey !== undefined && pathKey in toObject(object)) {
path = [pathKey];
}
var index = -1,
var index = 0,
length = path.length;
while (object != null && ++index < length) {
var result = object = object[path[index]];
while (object != null && index < length) {
object = object[path[index++]];
}
return result;
return (index && index == length) ? object : undefined;
}
export default baseGet;

View File

@@ -1,4 +1,6 @@
import baseIsEqualDeep from './baseIsEqualDeep';
import isObject from '../lang/isObject';
import isObjectLike from './isObjectLike';
/**
* The base implementation of `_.isEqual` without support for `this` binding
@@ -14,18 +16,10 @@ import baseIsEqualDeep from './baseIsEqualDeep';
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
// Exit early for identical values.
if (value === other) {
// Treat `+0` vs. `-0` as not equal.
return value !== 0 || (1 / value == 1 / other);
return true;
}
var valType = typeof value,
othType = typeof other;
// Exit early for unlike primitive values.
if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') ||
value == null || other == null) {
// Return `false` unless both values are `NaN`.
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
return value !== value && other !== other;
}
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);

View File

@@ -66,11 +66,11 @@ function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA,
return equalByTag(object, other, objTag);
}
if (!isLoose) {
var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (valWrapped || othWrapped) {
return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
if (objIsWrapped || othIsWrapped) {
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
}
}
if (!isSameTag) {

View File

@@ -1,4 +1,5 @@
import baseIsEqual from './baseIsEqual';
import toObject from './toObject';
/**
* The base implementation of `_.isMatch` without support for callback
@@ -6,41 +7,43 @@ import baseIsEqual from './baseIsEqual';
*
* @private
* @param {Object} object The object to inspect.
* @param {Array} props The source property names to match.
* @param {Array} values The source values to match.
* @param {Array} strictCompareFlags Strict comparison flags for source values.
* @param {Array} matchData The propery names, values, and compare flags to match.
* @param {Function} [customizer] The function to customize comparing objects.
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/
function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
var index = -1,
length = props.length,
function baseIsMatch(object, matchData, customizer) {
var index = matchData.length,
length = index,
noCustomizer = !customizer;
while (++index < length) {
if ((noCustomizer && strictCompareFlags[index])
? values[index] !== object[props[index]]
: !(props[index] in object)
if (object == null) {
return !length;
}
object = toObject(object);
while (index--) {
var data = matchData[index];
if ((noCustomizer && data[2])
? data[1] !== object[data[0]]
: !(data[0] in object)
) {
return false;
}
}
index = -1;
while (++index < length) {
var key = props[index],
data = matchData[index];
var key = data[0],
objValue = object[key],
srcValue = values[index];
srcValue = data[1];
if (noCustomizer && strictCompareFlags[index]) {
var result = objValue !== undefined || (key in object);
} else {
result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (result === undefined) {
result = baseIsEqual(srcValue, objValue, customizer, true);
if (noCustomizer && data[2]) {
if (objValue === undefined && !(key in object)) {
return false;
}
} else {
var result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
return false;
}
}
if (!result) {
return false;
}
}
return true;

View File

@@ -1,6 +1,5 @@
import baseEach from './baseEach';
import getLength from './getLength';
import isLength from './isLength';
import isArrayLike from './isArrayLike';
/**
* The base implementation of `_.map` without support for callback shorthands
@@ -13,8 +12,7 @@ import isLength from './isLength';
*/
function baseMap(collection, iteratee) {
var index = -1,
length = getLength(collection),
result = isLength(length) ? Array(length) : [];
result = isArrayLike(collection) ? Array(collection.length) : [];
baseEach(collection, function(value, key, collection) {
result[++index] = iteratee(value, key, collection);

View File

@@ -1,7 +1,5 @@
import baseIsMatch from './baseIsMatch';
import constant from '../utility/constant';
import isStrictComparable from './isStrictComparable';
import keys from '../object/keys';
import getMatchData from './getMatchData';
import toObject from './toObject';
/**
@@ -12,35 +10,20 @@ import toObject from './toObject';
* @returns {Function} Returns the new function.
*/
function baseMatches(source) {
var props = keys(source),
length = props.length;
var matchData = getMatchData(source);
if (matchData.length == 1 && matchData[0][2]) {
var key = matchData[0][0],
value = matchData[0][1];
if (!length) {
return constant(true);
}
if (length == 1) {
var key = props[0],
value = source[key];
if (isStrictComparable(value)) {
return function(object) {
if (object == null) {
return false;
}
return object[key] === value && (value !== undefined || (key in toObject(object)));
};
}
}
var values = Array(length),
strictCompareFlags = Array(length);
while (length--) {
value = source[props[length]];
values[length] = value;
strictCompareFlags[length] = isStrictComparable(value);
return function(object) {
if (object == null) {
return false;
}
return object[key] === value && (value !== undefined || (key in toObject(object)));
};
}
return function(object) {
return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
return baseIsMatch(object, matchData);
};
}

View File

@@ -9,17 +9,16 @@ import toObject from './toObject';
import toPath from './toPath';
/**
* The base implementation of `_.matchesProperty` which does not which does
* not clone `value`.
* The base implementation of `_.matchesProperty` which does not clone `srcValue`.
*
* @private
* @param {string} path The path of the property to get.
* @param {*} value The value to compare.
* @param {*} srcValue The value to compare.
* @returns {Function} Returns the new function.
*/
function baseMatchesProperty(path, value) {
function baseMatchesProperty(path, srcValue) {
var isArr = isArray(path),
isCommon = isKey(path) && isStrictComparable(value),
isCommon = isKey(path) && isStrictComparable(srcValue),
pathKey = (path + '');
path = toPath(path);
@@ -37,9 +36,9 @@ function baseMatchesProperty(path, value) {
key = last(path);
object = toObject(object);
}
return object[key] === value
? (value !== undefined || (key in object))
: baseIsEqual(value, object[key], null, true);
return object[key] === srcValue
? (srcValue !== undefined || (key in object))
: baseIsEqual(srcValue, object[key], undefined, true);
};
}

View File

@@ -1,19 +1,12 @@
import arrayEach from './arrayEach';
import baseMergeDeep from './baseMergeDeep';
import getSymbols from './getSymbols';
import isArray from '../lang/isArray';
import isLength from './isLength';
import isArrayLike from './isArrayLike';
import isObject from '../lang/isObject';
import isObjectLike from './isObjectLike';
import isTypedArray from '../lang/isTypedArray';
import keys from '../object/keys';
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var push = arrayProto.push;
/**
* The base implementation of `_.merge` without support for argument juggling,
* multiple sources, and `this` binding `customizer` functions.
@@ -30,11 +23,9 @@ function baseMerge(object, source, customizer, stackA, stackB) {
if (!isObject(object)) {
return object;
}
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
if (!isSrcArr) {
var props = keys(source);
push.apply(props, getSymbols(source));
}
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
props = isSrcArr ? null : keys(source);
arrayEach(props || source, function(srcValue, key) {
if (props) {
key = srcValue;
@@ -53,7 +44,7 @@ function baseMerge(object, source, customizer, stackA, stackB) {
if (isCommon) {
result = srcValue;
}
if ((isSrcArr || result !== undefined) &&
if ((result !== undefined || (isSrcArr && !(key in object))) &&
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
}

View File

@@ -1,8 +1,7 @@
import arrayCopy from './arrayCopy';
import getLength from './getLength';
import isArguments from '../lang/isArguments';
import isArray from '../lang/isArray';
import isLength from './isLength';
import isArrayLike from './isArrayLike';
import isPlainObject from '../lang/isPlainObject';
import isTypedArray from '../lang/isTypedArray';
import toPlainObject from '../lang/toPlainObject';
@@ -38,10 +37,10 @@ function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stack
if (isCommon) {
result = srcValue;
if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
result = isArray(value)
? value
: (getLength(value) ? arrayCopy(value) : []);
: (isArrayLike(value) ? arrayCopy(value) : []);
}
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
result = isArguments(value)

View File

@@ -16,9 +16,9 @@ var splice = arrayProto.splice;
* @returns {Array} Returns `array`.
*/
function basePullAt(array, indexes) {
var length = indexes.length;
var length = array ? indexes.length : 0;
while (length--) {
var index = parseFloat(indexes[length]);
var index = indexes[length];
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);

View File

@@ -1,5 +1,5 @@
/**
* Converts `value` to a string if it is not one. An empty string is returned
* Converts `value` to a string if it's not one. An empty string is returned
* for `null` or `undefined` values.
*
* @private

View File

@@ -2,7 +2,7 @@ import binaryIndexBy from './binaryIndexBy';
import identity from '../utility/identity';
/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
var MAX_ARRAY_LENGTH = 4294967295,
HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
/**
@@ -25,7 +25,7 @@ function binaryIndex(array, value, retHighest) {
var mid = (low + high) >>> 1,
computed = array[mid];
if (retHighest ? (computed <= value) : (computed < value)) {
if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
low = mid + 1;
} else {
high = mid;

View File

@@ -5,8 +5,8 @@ var floor = Math.floor;
var nativeMin = Math.min;
/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
var MAX_ARRAY_LENGTH = 4294967295,
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
/**
* This function is like `binaryIndex` except that it invokes `iteratee` for
@@ -27,17 +27,23 @@ function binaryIndexBy(array, value, iteratee, retHighest) {
var low = 0,
high = array ? array.length : 0,
valIsNaN = value !== value,
valIsNull = value === null,
valIsUndef = value === undefined;
while (low < high) {
var mid = floor((low + high) / 2),
computed = iteratee(array[mid]),
isDef = computed !== undefined,
isReflexive = computed === computed;
if (valIsNaN) {
var setLow = isReflexive || retHighest;
} else if (valIsNull) {
setLow = isReflexive && isDef && (retHighest || computed != null);
} else if (valIsUndef) {
setLow = isReflexive && (retHighest || computed !== undefined);
setLow = isReflexive && (retHighest || isDef);
} else if (computed == null) {
setLow = false;
} else {
setLow = retHighest ? (computed <= value) : (computed < value);
}

View File

@@ -1,12 +1,12 @@
import constant from '../utility/constant';
import isNative from '../lang/isNative';
import getNative from './getNative';
import root from './root';
/** Native method references. */
var ArrayBuffer = isNative(ArrayBuffer = root.ArrayBuffer) && ArrayBuffer,
bufferSlice = isNative(bufferSlice = ArrayBuffer && new ArrayBuffer(0).slice) && bufferSlice,
var ArrayBuffer = getNative(root, 'ArrayBuffer'),
bufferSlice = getNative(ArrayBuffer && new ArrayBuffer(0), 'slice'),
floor = Math.floor,
Uint8Array = isNative(Uint8Array = root.Uint8Array) && Uint8Array;
Uint8Array = getNative(root, 'Uint8Array');
/** Used to clone array buffers. */
var Float64Array = (function() {
@@ -14,10 +14,10 @@ var Float64Array = (function() {
// where the array buffer's `byteLength` is not a multiple of the typed
// array's `BYTES_PER_ELEMENT`.
try {
var func = isNative(func = root.Float64Array) && func,
var func = getNative(root, 'Float64Array'),
result = new func(new ArrayBuffer(10), 0, 1) && func;
} catch(e) {}
return result;
return result || null;
}());
/** Used as the size, in bytes, of each `Float64Array` element. */

View File

@@ -1,12 +0,0 @@
/**
* Used by `_.max` and `_.min` as the default callback for string values.
*
* @private
* @param {string} string The string to inspect.
* @returns {number} Returns the code unit of the first character of the string.
*/
function charAtCallback(string) {
return string.charCodeAt(0);
}
export default charAtCallback;

View File

@@ -23,12 +23,12 @@ function composeArgsRight(args, partials, holders) {
while (++argsIndex < argsLength) {
result[argsIndex] = args[argsIndex];
}
var pad = argsIndex;
var offset = argsIndex;
while (++rightIndex < rightLength) {
result[pad + rightIndex] = partials[rightIndex];
result[offset + rightIndex] = partials[rightIndex];
}
while (++holdersIndex < holdersLength) {
result[pad + holders[holdersIndex]] = args[argsIndex++];
result[offset + holders[holdersIndex]] = args[argsIndex++];
}
return result;
}

View File

@@ -16,19 +16,19 @@ function createAssigner(assigner) {
return restParam(function(object, sources) {
var index = -1,
length = object == null ? 0 : sources.length,
customizer = length > 2 && sources[length - 2],
guard = length > 2 && sources[2],
thisArg = length > 1 && sources[length - 1];
customizer = length > 2 ? sources[length - 2] : undefined,
guard = length > 2 ? sources[2] : undefined,
thisArg = length > 1 ? sources[length - 1] : undefined;
if (typeof customizer == 'function') {
customizer = bindCallback(customizer, thisArg, 5);
length -= 2;
} else {
customizer = typeof thisArg == 'function' ? thisArg : null;
customizer = typeof thisArg == 'function' ? thisArg : undefined;
length -= (customizer ? 1 : 0);
}
if (guard && isIterateeCall(sources[0], sources[1], guard)) {
customizer = length < 3 ? null : customizer;
customizer = length < 3 ? undefined : customizer;
length = 1;
}
while (++index < length) {

View File

@@ -1,13 +1,13 @@
import SetCache from './SetCache';
import constant from '../utility/constant';
import isNative from '../lang/isNative';
import getNative from './getNative';
import root from './root';
/** Native method references. */
var Set = isNative(Set = root.Set) && Set;
var Set = getNative(root, 'Set');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate;
var nativeCreate = getNative(Object, 'create');
/**
* Creates a `Set` cache object to optimize linear searches of large arrays.

View File

@@ -11,8 +11,20 @@ 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
// for more details.
var args = arguments;
switch (args.length) {
case 0: return new Ctor;
case 1: return new Ctor(args[0]);
case 2: return new Ctor(args[0], args[1]);
case 3: return new Ctor(args[0], args[1], args[2]);
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
}
var thisBinding = baseCreate(Ctor.prototype),
result = Ctor.apply(thisBinding, arguments);
result = Ctor.apply(thisBinding, args);
// Mimic the constructor's `return` behavior.
// See https://es5.github.io/#x13.2.2 for more details.

View File

@@ -1,37 +1,31 @@
import arrayExtremum from './arrayExtremum';
import baseCallback from './baseCallback';
import charAtCallback from './charAtCallback';
import extremumBy from './extremumBy';
import isArray from '../lang/isArray';
import baseExtremum from './baseExtremum';
import isIterateeCall from './isIterateeCall';
import isString from '../lang/isString';
import toIterable from './toIterable';
/**
* Creates a `_.max` or `_.min` function.
*
* @private
* @param {Function} arrayFunc The function to get the extremum value from an array.
* @param {boolean} [isMin] Specify returning the minimum, instead of the maximum,
* extremum value.
* @param {Function} comparator The function used to compare values.
* @param {*} exValue The initial extremum value.
* @returns {Function} Returns the new extremum function.
*/
function createExtremum(arrayFunc, isMin) {
function createExtremum(comparator, exValue) {
return function(collection, iteratee, thisArg) {
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null;
}
var noIteratee = iteratee == null;
iteratee = noIteratee ? iteratee : baseCallback(iteratee, thisArg, 3);
if (noIteratee) {
var isArr = isArray(collection);
if (!isArr && isString(collection)) {
iteratee = charAtCallback;
} else {
return arrayFunc(isArr ? collection : toIterable(collection));
iteratee = baseCallback(iteratee, thisArg, 3);
if (iteratee.length == 1) {
collection = toIterable(collection);
var result = arrayExtremum(collection, iteratee, comparator, exValue);
if (!(collection.length && result === exValue)) {
return result;
}
}
return extremumBy(collection, iteratee, isMin);
return baseExtremum(collection, iteratee, comparator, exValue);
};
}

View File

@@ -19,7 +19,7 @@ function createFind(eachFunc, fromRight) {
return index > -1 ? collection[index] : undefined;
}
return baseFind(collection, predicate, eachFunc);
}
};
}
export default createFind;

View File

@@ -4,6 +4,12 @@ import getFuncName from './getFuncName';
import isArray from '../lang/isArray';
import isLaziable from './isLaziable';
/** Used to compose bitmasks for wrapper metadata. */
var CURRY_FLAG = 8,
PARTIAL_FLAG = 32,
ARY_FLAG = 128,
REARG_FLAG = 256;
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
@@ -16,11 +22,8 @@ var FUNC_ERROR_TEXT = 'Expected a function';
*/
function createFlow(fromRight) {
return function() {
var length = arguments.length;
if (!length) {
return function() { return arguments[0]; };
}
var wrapper,
length = arguments.length,
index = fromRight ? length : -1,
leftIndex = 0,
funcs = Array(length);
@@ -30,16 +33,18 @@ function createFlow(fromRight) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
var funcName = wrapper ? '' : getFuncName(func);
wrapper = funcName == 'wrapper' ? new LodashWrapper([]) : wrapper;
if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
wrapper = new LodashWrapper([]);
}
}
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])) {
var funcName = getFuncName(func),
data = funcName == 'wrapper' ? getData(func) : null;
if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
} else {
wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
@@ -51,7 +56,7 @@ function createFlow(fromRight) {
return wrapper.plant(args[0]).value();
}
var index = 0,
result = funcs[index].apply(this, args);
result = length ? funcs[index].apply(this, args) : args[0];
while (++index < length) {
result = funcs[index].call(this, result);

View File

@@ -44,10 +44,8 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials
isBindKey = bitmask & BIND_KEY_FLAG,
isCurry = bitmask & CURRY_FLAG,
isCurryBound = bitmask & CURRY_BOUND_FLAG,
isCurryRight = bitmask & CURRY_RIGHT_FLAG;
var Ctor = !isBindKey && createCtorWrapper(func),
key = func;
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
Ctor = isBindKey ? null : createCtorWrapper(func);
function wrapper() {
// Avoid `arguments` object use disqualifying optimizations by
@@ -94,17 +92,18 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials
return result;
}
}
var thisBinding = isBind ? thisArg : this;
if (isBindKey) {
func = thisBinding[key];
}
var thisBinding = isBind ? thisArg : this,
fn = isBindKey ? thisBinding[func] : func;
if (argPos) {
args = reorder(args, argPos);
}
if (isAry && ary < args.length) {
args.length = ary;
}
var fn = (this && this !== root && this instanceof wrapper) ? (Ctor || createCtorWrapper(func)) : func;
if (this && this !== root && this instanceof wrapper) {
fn = Ctor || createCtorWrapper(func);
}
return fn.apply(thisBinding, args);
}
return wrapper;

View File

@@ -0,0 +1,26 @@
import baseCallback from './baseCallback';
import baseForOwn from './baseForOwn';
/**
* Creates a function for `_.mapKeys` or `_.mapValues`.
*
* @private
* @param {boolean} [isMapKeys] Specify mapping keys instead of values.
* @returns {Function} Returns the new map function.
*/
function createObjectMapper(isMapKeys) {
return function(object, iteratee, thisArg) {
var result = {};
iteratee = baseCallback(iteratee, thisArg, 3);
baseForOwn(object, function(value, key, object) {
var mapped = iteratee(value, key, object);
key = isMapKeys ? mapped : key;
value = isMapKeys ? value : mapped;
result[key] = value;
});
return result;
};
}
export default createObjectMapper;

View File

@@ -11,7 +11,7 @@ import createPadding from './createPadding';
function createPadDir(fromRight) {
return function(string, length, chars) {
string = baseToString(string);
return string && ((fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string));
return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
};
}

View File

@@ -1,3 +1,5 @@
import arraySome from './arraySome';
/**
* A specialized version of `baseIsEqualDeep` for arrays with support for
* partial deep comparisons.
@@ -15,40 +17,35 @@
function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
var index = -1,
arrLength = array.length,
othLength = other.length,
result = true;
othLength = other.length;
if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
return false;
}
// Deep compare the contents, ignoring non-numeric properties.
while (result && ++index < arrLength) {
// Ignore non-index properties.
while (++index < arrLength) {
var arrValue = array[index],
othValue = other[index];
othValue = other[index],
result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
result = undefined;
if (customizer) {
result = isLoose
? customizer(othValue, arrValue, index)
: customizer(arrValue, othValue, index);
}
if (result === undefined) {
// Recursively compare arrays (susceptible to call stack limits).
if (isLoose) {
var othIndex = othLength;
while (othIndex--) {
othValue = other[othIndex];
result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
if (result) {
break;
}
}
} else {
result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
if (result !== undefined) {
if (result) {
continue;
}
return false;
}
// Recursively compare arrays (susceptible to call stack limits).
if (isLoose) {
if (!arraySome(other, function(othValue) {
return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
})) {
return false;
}
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
return false;
}
}
return !!result;
return true;
}
export default equalArrays;

View File

@@ -34,8 +34,7 @@ function equalByTag(object, other, tag) {
// Treat `NaN` vs. `NaN` as equal.
return (object != +object)
? other != +other
// But, treat `-0` vs. `+0` as not equal.
: (object == 0 ? ((1 / object) == (1 / other)) : object == +other);
: object == +other;
case regexpTag:
case stringTag:

View File

@@ -29,29 +29,22 @@ function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, sta
if (objLength != othLength && !isLoose) {
return false;
}
var skipCtor = isLoose,
index = -1;
while (++index < objLength) {
var key = objProps[index],
result = isLoose ? key in other : hasOwnProperty.call(other, key);
if (result) {
var objValue = object[key],
othValue = other[key];
result = undefined;
if (customizer) {
result = isLoose
? customizer(othValue, objValue, key)
: customizer(objValue, othValue, key);
}
if (result === undefined) {
// Recursively compare objects (susceptible to call stack limits).
result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB);
}
var index = objLength;
while (index--) {
var key = objProps[index];
if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
return false;
}
if (!result) {
}
var skipCtor = isLoose;
while (++index < objLength) {
key = objProps[index];
var objValue = object[key],
othValue = other[key],
result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
// Recursively compare objects (susceptible to call stack limits).
if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
return false;
}
skipCtor || (skipCtor = key == 'constructor');

View File

@@ -1,7 +1,4 @@
import baseProperty from './baseProperty';
import constant from '../utility/constant';
import realNames from './realNames';
import support from '../support';
/**
* Gets the name of `func`.
@@ -10,28 +7,19 @@ import support from '../support';
* @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;
function getFuncName(func) {
var result = func.name,
array = realNames[result],
length = array ? array.length : 0;
while (length--) {
var data = array[length],
otherFunc = data.func;
if (otherFunc == null || otherFunc == func) {
return data.name;
}
while (length--) {
var data = array[length],
otherFunc = data.func;
if (otherFunc == null || otherFunc == func) {
return data.name;
}
return result;
};
}());
}
return result;
}
export default getFuncName;

View File

@@ -4,7 +4,7 @@ import baseProperty from './baseProperty';
* Gets the "length" property value of `object`.
*
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
* in Safari on iOS 8.1 ARM64.
* that affects Safari on at least iOS 8.1-8.3 ARM64.
*
* @private
* @param {Object} object The object to query.

21
internal/getMatchData.js Normal file
View File

@@ -0,0 +1,21 @@
import isStrictComparable from './isStrictComparable';
import pairs from '../object/pairs';
/**
* Gets the propery names, values, and compare flags of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the match data of `object`.
*/
function getMatchData(object) {
var result = pairs(object),
length = result.length;
while (length--) {
result[length][2] = isStrictComparable(result[length][1]);
}
return result;
}
export default getMatchData;

16
internal/getNative.js Normal file
View File

@@ -0,0 +1,16 @@
import isNative from '../lang/isNative';
/**
* Gets the native function at `key` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the method to get.
* @returns {*} Returns the function if it's native, else `undefined`.
*/
function getNative(object, key) {
var value = object == null ? undefined : object[key];
return isNative(value) ? value : undefined;
}
export default getNative;

View File

@@ -1,19 +0,0 @@
import constant from '../utility/constant';
import isNative from '../lang/isNative';
import toObject from './toObject';
/** Native method references. */
var getOwnPropertySymbols = isNative(getOwnPropertySymbols = Object.getOwnPropertySymbols) && getOwnPropertySymbols;
/**
* Creates an array of the own symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of symbols.
*/
var getSymbols = !getOwnPropertySymbols ? constant([]) : function(object) {
return getOwnPropertySymbols(toObject(object));
};
export default getSymbols;

15
internal/isArrayLike.js Normal file
View File

@@ -0,0 +1,15 @@
import getLength from './getLength';
import isLength from './isLength';
/**
* Checks if `value` is array-like.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
*/
function isArrayLike(value) {
return value != null && isLength(getLength(value));
}
export default isArrayLike;

View File

@@ -2,7 +2,7 @@
* 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;
var MAX_SAFE_INTEGER = 9007199254740991;
/**
* Checks if `value` is a valid array-like index.
@@ -13,7 +13,7 @@ var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
*/
function isIndex(value, length) {
value = +value;
value = typeof value == 'number' ? value : parseFloat(value);
length = length == null ? MAX_SAFE_INTEGER : length;
return value > -1 && value % 1 == 0 && value < length;
}

View File

@@ -1,6 +1,5 @@
import getLength from './getLength';
import isArrayLike from './isArrayLike';
import isIndex from './isIndex';
import isLength from './isLength';
import isObject from '../lang/isObject';
/**
@@ -17,13 +16,9 @@ function isIterateeCall(value, index, object) {
return false;
}
var type = typeof index;
if (type == 'number') {
var length = getLength(object),
prereq = isLength(length) && isIndex(index, length);
} else {
prereq = type == 'string' && index in object;
}
if (prereq) {
if (type == 'number'
? (isArrayLike(object) && isIndex(index, object.length))
: (type == 'string' && index in object)) {
var other = object[index];
return value === value ? (value === other) : (other !== other);
}

View File

@@ -2,7 +2,7 @@ import isArray from '../lang/isArray';
import toObject from './toObject';
/** Used to match property names within property paths. */
var reIsDeepProp = /\.|\[(?:[^[\]]+|(["'])(?:(?!\1)[^\n\\]|\\.)*?)\1\]/,
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
reIsPlainProp = /^\w*$/;
/**

View File

@@ -1,4 +1,5 @@
import LazyWrapper from './LazyWrapper';
import getData from './getData';
import getFuncName from './getFuncName';
import lodash from '../chain/lodash';
@@ -11,7 +12,15 @@ import lodash from '../chain/lodash';
*/
function isLaziable(func) {
var funcName = getFuncName(func);
return !!funcName && func === lodash[funcName] && funcName in LazyWrapper.prototype;
if (!(funcName in LazyWrapper.prototype)) {
return false;
}
var other = lodash[funcName];
if (func === other) {
return true;
}
var data = getData(other);
return !!data && func === data[0];
}
export default isLaziable;

View File

@@ -2,7 +2,7 @@
* 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;
var MAX_SAFE_INTEGER = 9007199254740991;
/**
* Checks if `value` is a valid array-like length.

View File

@@ -9,7 +9,7 @@ import isObject from '../lang/isObject';
* equality comparisons, else `false`.
*/
function isStrictComparable(value) {
return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(value));
return value === value && !isObject(value);
}
export default isStrictComparable;

View File

@@ -1,8 +1,8 @@
import isNative from '../lang/isNative';
import getNative from './getNative';
import root from './root';
/** Native method references. */
var WeakMap = isNative(WeakMap = root.WeakMap) && WeakMap;
var WeakMap = getNative(root, 'WeakMap');
/** Used to store function metadata. */
var metaMap = WeakMap && new WeakMap;

View File

@@ -1,7 +1,7 @@
import toObject from './toObject';
/**
* A specialized version of `_.pick` that picks `object` properties specified
* A specialized version of `_.pick` which picks `object` properties specified
* by `props`.
*
* @private

View File

@@ -1,7 +1,7 @@
import baseForIn from './baseForIn';
/**
* A specialized version of `_.pick` that picks `object` properties `predicate`
* A specialized version of `_.pick` which picks `object` properties `predicate`
* returns truthy for.
*
* @private

View File

@@ -22,7 +22,7 @@ var freeWindow = objectTypes[typeof window] && window && window.Object && window
/**
* Used as a reference to the global object.
*
* The `this` value is used if it is the global object to avoid Greasemonkey's
* The `this` value is used if it's the global object to avoid Greasemonkey's
* restricted `window` object, otherwise the `window` object is used.
*/
var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;

View File

@@ -3,7 +3,6 @@ import isArray from '../lang/isArray';
import isIndex from './isIndex';
import isLength from './isLength';
import keysIn from '../object/keysIn';
import support from '../support';
/** Used for native method references. */
var objectProto = Object.prototype;
@@ -24,8 +23,8 @@ function shimKeys(object) {
propsLength = props.length,
length = propsLength && object.length;
var allowIndexes = length && isLength(length) &&
(isArray(object) || (support.nonEnumArgs && isArguments(object)));
var allowIndexes = !!length && isLength(length) &&
(isArray(object) || isArguments(object));
var index = -1,
result = [];

View File

@@ -1,10 +1,9 @@
import getLength from './getLength';
import isLength from './isLength';
import isArrayLike from './isArrayLike';
import isObject from '../lang/isObject';
import values from '../object/values';
/**
* Converts `value` to an array-like object if it is not one.
* Converts `value` to an array-like object if it's not one.
*
* @private
* @param {*} value The value to process.
@@ -14,7 +13,7 @@ function toIterable(value) {
if (value == null) {
return [];
}
if (!isLength(getLength(value))) {
if (!isArrayLike(value)) {
return values(value);
}
return isObject(value) ? value : Object(value);

View File

@@ -1,7 +1,7 @@
import isObject from '../lang/isObject';
/**
* Converts `value` to an object if it is not one.
* Converts `value` to an object if it's not one.
*
* @private
* @param {*} value The value to process.

View File

@@ -8,7 +8,7 @@ var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?
var reEscapeChar = /\\(\\)?/g;
/**
* Converts `value` to property path array if it is not one.
* Converts `value` to property path array if it's not one.
*
* @private
* @param {*} value The value to process.

10
lang.js
View File

@@ -1,5 +1,8 @@
import clone from './lang/clone';
import cloneDeep from './lang/cloneDeep';
import eq from './lang/eq';
import gt from './lang/gt';
import gte from './lang/gte';
import isArguments from './lang/isArguments';
import isArray from './lang/isArray';
import isBoolean from './lang/isBoolean';
@@ -21,12 +24,17 @@ import isRegExp from './lang/isRegExp';
import isString from './lang/isString';
import isTypedArray from './lang/isTypedArray';
import isUndefined from './lang/isUndefined';
import lt from './lang/lt';
import lte from './lang/lte';
import toArray from './lang/toArray';
import toPlainObject from './lang/toPlainObject';
export default {
'clone': clone,
'cloneDeep': cloneDeep,
'eq': eq,
'gt': gt,
'gte': gte,
'isArguments': isArguments,
'isArray': isArray,
'isBoolean': isBoolean,
@@ -48,6 +56,8 @@ export default {
'isString': isString,
'isTypedArray': isTypedArray,
'isUndefined': isUndefined,
'lt': lt,
'lte': lte,
'toArray': toArray,
'toPlainObject': toPlainObject
};

View File

@@ -62,8 +62,9 @@ function clone(value, isDeep, customizer, thisArg) {
customizer = isDeep;
isDeep = false;
}
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
return baseClone(value, isDeep, customizer);
return typeof customizer == 'function'
? baseClone(value, isDeep, bindCallback(customizer, thisArg, 1))
: baseClone(value, isDeep);
}
export default clone;

View File

@@ -47,8 +47,9 @@ import bindCallback from '../internal/bindCallback';
* // => 20
*/
function cloneDeep(value, customizer, thisArg) {
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
return baseClone(value, true, customizer);
return typeof customizer == 'function'
? baseClone(value, true, bindCallback(customizer, thisArg, 1))
: baseClone(value, true);
}
export default cloneDeep;

2
lang/eq.js Normal file
View File

@@ -0,0 +1,2 @@
import isEqual from './isEqual'
export default isEqual;

25
lang/gt.js Normal file
View File

@@ -0,0 +1,25 @@
/**
* Checks if `value` is greater than `other`.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
* @example
*
* _.gt(3, 1);
* // => true
*
* _.gt(3, 3);
* // => false
*
* _.gt(1, 3);
* // => false
*/
function gt(value, other) {
return value > other;
}
export default gt;

25
lang/gte.js Normal file
View File

@@ -0,0 +1,25 @@
/**
* Checks if `value` is greater than or equal to `other`.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
* @example
*
* _.gte(3, 1);
* // => true
*
* _.gte(3, 3);
* // => true
*
* _.gte(1, 3);
* // => false
*/
function gte(value, other) {
return value >= other;
}
export default gte;

View File

@@ -1,4 +1,4 @@
import isLength from '../internal/isLength';
import isArrayLike from '../internal/isArrayLike';
import isObjectLike from '../internal/isObjectLike';
/** `Object#toString` result references. */
@@ -30,8 +30,7 @@ var objToString = objectProto.toString;
* // => false
*/
function isArguments(value) {
var length = isObjectLike(value) ? value.length : undefined;
return isLength(length) && objToString.call(value) == argsTag;
return isObjectLike(value) && isArrayLike(value) && objToString.call(value) == argsTag;
}
export default isArguments;

View File

@@ -1,5 +1,5 @@
import getNative from '../internal/getNative';
import isLength from '../internal/isLength';
import isNative from './isNative';
import isObjectLike from '../internal/isObjectLike';
/** `Object#toString` result references. */
@@ -15,7 +15,7 @@ var objectProto = Object.prototype;
var objToString = objectProto.toString;
/* Native method references for those with the same name as other `lodash` methods. */
var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray;
var nativeIsArray = getNative(Array, 'isArray');
/**
* Checks if `value` is classified as an `Array` object.

View File

@@ -1,8 +1,7 @@
import getLength from '../internal/getLength';
import isArguments from './isArguments';
import isArray from './isArray';
import isArrayLike from '../internal/isArrayLike';
import isFunction from './isFunction';
import isLength from '../internal/isLength';
import isObjectLike from '../internal/isObjectLike';
import isString from './isString';
import keys from '../object/keys';
@@ -38,10 +37,9 @@ function isEmpty(value) {
if (value == null) {
return true;
}
var length = getLength(value);
if (isLength(length) && (isArray(value) || isString(value) || isArguments(value) ||
if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
(isObjectLike(value) && isFunction(value.splice)))) {
return !length;
return !value.length;
}
return !keys(value).length;
}

View File

@@ -1,6 +1,5 @@
import baseIsEqual from '../internal/baseIsEqual';
import bindCallback from '../internal/bindCallback';
import isStrictComparable from '../internal/isStrictComparable';
/**
* Performs a deep comparison between two values to determine if they are
@@ -17,6 +16,7 @@ import isStrictComparable from '../internal/isStrictComparable';
*
* @static
* @memberOf _
* @alias eq
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
@@ -46,12 +46,9 @@ import isStrictComparable from '../internal/isStrictComparable';
* // => true
*/
function isEqual(value, other, customizer, thisArg) {
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
if (!customizer && isStrictComparable(value) && isStrictComparable(other)) {
return value === other;
}
customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
var result = customizer ? customizer(value, other) : undefined;
return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
}
export default isEqual;

View File

@@ -1,9 +1,9 @@
import isNative from './isNative';
import getNative from '../internal/getNative';
import root from '../internal/root';
/* Native method references for those with the same name as other `lodash` methods. */
var nativeIsFinite = root.isFinite,
nativeNumIsFinite = isNative(nativeNumIsFinite = Number.isFinite) && nativeNumIsFinite;
nativeNumIsFinite = getNative(Number, 'isFinite');
/**
* Checks if `value` is a finite primitive number.

View File

@@ -1,5 +1,5 @@
import baseIsFunction from '../internal/baseIsFunction';
import isNative from './isNative';
import getNative from '../internal/getNative';
import root from '../internal/root';
/** `Object#toString` result references. */
@@ -15,7 +15,7 @@ var objectProto = Object.prototype;
var objToString = objectProto.toString;
/** Native method references. */
var Uint8Array = isNative(Uint8Array = root.Uint8Array) && Uint8Array;
var Uint8Array = getNative(root, 'Uint8Array');
/**
* Checks if `value` is classified as a `Function` object.

View File

@@ -1,8 +1,6 @@
import baseIsMatch from '../internal/baseIsMatch';
import bindCallback from '../internal/bindCallback';
import isStrictComparable from '../internal/isStrictComparable';
import keys from '../object/keys';
import toObject from '../internal/toObject';
import getMatchData from '../internal/getMatchData';
/**
* Performs a deep comparison between `object` and `source` to determine if
@@ -44,33 +42,8 @@ import toObject from '../internal/toObject';
* // => true
*/
function isMatch(object, source, customizer, thisArg) {
var props = keys(source),
length = props.length;
if (!length) {
return true;
}
if (object == null) {
return false;
}
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 3);
object = toObject(object);
if (!customizer && length == 1) {
var key = props[0],
value = source[key];
if (isStrictComparable(value)) {
return value === object[key] && (value !== undefined || (key in object));
}
}
var values = Array(length),
strictCompareFlags = Array(length);
while (length--) {
value = values[length] = source[props[length]];
strictCompareFlags[length] = isStrictComparable(value);
}
return baseIsMatch(object, props, values, strictCompareFlags, customizer);
customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
return baseIsMatch(object, getMatchData(source), customizer);
}
export default isMatch;

Some files were not shown because too many files have changed in this diff Show More