mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d77dfa4b7 | ||
|
|
4bd2890bbd | ||
|
|
6ee2b9a7b8 | ||
|
|
3d3907ff27 | ||
|
|
30daf83737 | ||
|
|
d7b2bedafc | ||
|
|
5eb8db31d7 |
@@ -1,4 +1,4 @@
|
|||||||
# lodash-es v3.6.0
|
# lodash-es v3.10.1
|
||||||
|
|
||||||
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.
|
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 ./
|
$ lodash modularize modern exports=es -o ./
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [package source](https://github.com/lodash/lodash/tree/3.6.0-es) for more details.
|
See the [package source](https://github.com/lodash/lodash/tree/3.10.1-es) for more details.
|
||||||
|
|||||||
6
array.js
6
array.js
@@ -34,10 +34,12 @@ import union from './array/union';
|
|||||||
import uniq from './array/uniq';
|
import uniq from './array/uniq';
|
||||||
import unique from './array/unique';
|
import unique from './array/unique';
|
||||||
import unzip from './array/unzip';
|
import unzip from './array/unzip';
|
||||||
|
import unzipWith from './array/unzipWith';
|
||||||
import without from './array/without';
|
import without from './array/without';
|
||||||
import xor from './array/xor';
|
import xor from './array/xor';
|
||||||
import zip from './array/zip';
|
import zip from './array/zip';
|
||||||
import zipObject from './array/zipObject';
|
import zipObject from './array/zipObject';
|
||||||
|
import zipWith from './array/zipWith';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
'chunk': chunk,
|
'chunk': chunk,
|
||||||
@@ -76,8 +78,10 @@ export default {
|
|||||||
'uniq': uniq,
|
'uniq': uniq,
|
||||||
'unique': unique,
|
'unique': unique,
|
||||||
'unzip': unzip,
|
'unzip': unzip,
|
||||||
|
'unzipWith': unzipWith,
|
||||||
'without': without,
|
'without': without,
|
||||||
'xor': xor,
|
'xor': xor,
|
||||||
'zip': zip,
|
'zip': zip,
|
||||||
'zipObject': zipObject
|
'zipObject': zipObject,
|
||||||
|
'zipWith': zipWith
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import baseSlice from '../internal/baseSlice';
|
import baseSlice from '../internal/baseSlice';
|
||||||
import isIterateeCall from '../internal/isIterateeCall';
|
import isIterateeCall from '../internal/isIterateeCall';
|
||||||
|
|
||||||
/** Native method references. */
|
|
||||||
var ceil = Math.ceil;
|
|
||||||
|
|
||||||
/* Native method references for those with the same name as other `lodash` methods. */
|
/* Native method references for those with the same name as other `lodash` methods. */
|
||||||
var nativeMax = Math.max;
|
var nativeCeil = Math.ceil,
|
||||||
|
nativeFloor = Math.floor,
|
||||||
|
nativeMax = Math.max;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of elements split into groups the length of `size`.
|
* Creates an array of elements split into groups the length of `size`.
|
||||||
@@ -31,12 +30,12 @@ function chunk(array, size, guard) {
|
|||||||
if (guard ? isIterateeCall(array, size, guard) : size == null) {
|
if (guard ? isIterateeCall(array, size, guard) : size == null) {
|
||||||
size = 1;
|
size = 1;
|
||||||
} else {
|
} else {
|
||||||
size = nativeMax(+size || 1, 1);
|
size = nativeMax(nativeFloor(size) || 1, 1);
|
||||||
}
|
}
|
||||||
var index = 0,
|
var index = 0,
|
||||||
length = array ? array.length : 0,
|
length = array ? array.length : 0,
|
||||||
resIndex = -1,
|
resIndex = -1,
|
||||||
result = Array(ceil(length / size));
|
result = Array(nativeCeil(length / size));
|
||||||
|
|
||||||
while (index < length) {
|
while (index < length) {
|
||||||
result[++resIndex] = baseSlice(array, index, (index += size));
|
result[++resIndex] = baseSlice(array, index, (index += size));
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
import baseDifference from '../internal/baseDifference';
|
import baseDifference from '../internal/baseDifference';
|
||||||
import baseFlatten from '../internal/baseFlatten';
|
import baseFlatten from '../internal/baseFlatten';
|
||||||
import isArguments from '../lang/isArguments';
|
import isArrayLike from '../internal/isArrayLike';
|
||||||
import isArray from '../lang/isArray';
|
import isObjectLike from '../internal/isObjectLike';
|
||||||
import restParam from '../function/restParam';
|
import restParam from '../function/restParam';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array excluding all values of the provided arrays using
|
* Creates an array of unique `array` values not included in the other
|
||||||
* `SameValueZero` for equality comparisons.
|
* provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#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
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -24,7 +21,7 @@ import restParam from '../function/restParam';
|
|||||||
* // => [1, 3]
|
* // => [1, 3]
|
||||||
*/
|
*/
|
||||||
var difference = restParam(function(array, values) {
|
var difference = restParam(function(array, values) {
|
||||||
return (isArray(array) || isArguments(array))
|
return (isObjectLike(array) && isArrayLike(array))
|
||||||
? baseDifference(array, baseFlatten(values, false, true))
|
? baseDifference(array, baseFlatten(values, false, true))
|
||||||
: [];
|
: [];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import isIterateeCall from '../internal/isIterateeCall';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Flattens a nested array. If `isDeep` is `true` the array is recursively
|
* Flattens a nested array. If `isDeep` is `true` the array is recursively
|
||||||
* flattened, otherwise it is only flattened a single level.
|
* flattened, otherwise it's only flattened a single level.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -6,13 +6,10 @@ var nativeMax = Math.max;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the index at which the first occurrence of `value` is found in `array`
|
* Gets the index at which the first occurrence of `value` is found in `array`
|
||||||
* using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* it is used as the offset from the end of `array`. If `array` is sorted
|
* for equality comparisons. If `fromIndex` is negative, it's used as the offset
|
||||||
* providing `true` for `fromIndex` performs a faster binary search.
|
* 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`.
|
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -43,10 +40,9 @@ function indexOf(array, value, fromIndex) {
|
|||||||
if (typeof fromIndex == 'number') {
|
if (typeof fromIndex == 'number') {
|
||||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
|
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
|
||||||
} else if (fromIndex) {
|
} else if (fromIndex) {
|
||||||
var index = binaryIndex(array, value),
|
var index = binaryIndex(array, value);
|
||||||
other = array[index];
|
if (index < length &&
|
||||||
|
(value === value ? (value === array[index]) : (array[index] !== array[index]))) {
|
||||||
if (value === value ? (value === other) : (other !== other)) {
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
import baseIndexOf from '../internal/baseIndexOf';
|
import baseIndexOf from '../internal/baseIndexOf';
|
||||||
import cacheIndexOf from '../internal/cacheIndexOf';
|
import cacheIndexOf from '../internal/cacheIndexOf';
|
||||||
import createCache from '../internal/createCache';
|
import createCache from '../internal/createCache';
|
||||||
import isArguments from '../lang/isArguments';
|
import isArrayLike from '../internal/isArrayLike';
|
||||||
import isArray from '../lang/isArray';
|
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`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* for equality comparisons.
|
* 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
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Array
|
* @category Array
|
||||||
@@ -21,36 +18,31 @@ import isArray from '../lang/isArray';
|
|||||||
* _.intersection([1, 2], [4, 2], [2, 1]);
|
* _.intersection([1, 2], [4, 2], [2, 1]);
|
||||||
* // => [2]
|
* // => [2]
|
||||||
*/
|
*/
|
||||||
function intersection() {
|
var intersection = restParam(function(arrays) {
|
||||||
var args = [],
|
var othLength = arrays.length,
|
||||||
argsIndex = -1,
|
othIndex = othLength,
|
||||||
argsLength = arguments.length,
|
caches = Array(length),
|
||||||
caches = [],
|
|
||||||
indexOf = baseIndexOf,
|
indexOf = baseIndexOf,
|
||||||
isCommon = true;
|
isCommon = true,
|
||||||
|
result = [];
|
||||||
|
|
||||||
while (++argsIndex < argsLength) {
|
while (othIndex--) {
|
||||||
var value = arguments[argsIndex];
|
var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
|
||||||
if (isArray(value) || isArguments(value)) {
|
caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
|
||||||
args.push(value);
|
|
||||||
caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
argsLength = args.length;
|
var array = arrays[0],
|
||||||
var array = args[0],
|
|
||||||
index = -1,
|
index = -1,
|
||||||
length = array ? array.length : 0,
|
length = array ? array.length : 0,
|
||||||
result = [],
|
|
||||||
seen = caches[0];
|
seen = caches[0];
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
value = array[index];
|
value = array[index];
|
||||||
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
|
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
|
||||||
argsIndex = argsLength;
|
var othIndex = othLength;
|
||||||
while (--argsIndex) {
|
while (--othIndex) {
|
||||||
var cache = caches[argsIndex];
|
var cache = caches[othIndex];
|
||||||
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value, 0)) < 0) {
|
if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,6 +53,6 @@ function intersection() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
});
|
||||||
|
|
||||||
export default intersection;
|
export default intersection;
|
||||||
|
|||||||
@@ -7,14 +7,11 @@ var arrayProto = Array.prototype;
|
|||||||
var splice = arrayProto.splice;
|
var splice = arrayProto.splice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all provided values from `array` using `SameValueZero` for equality
|
* Removes all provided values from `array` using
|
||||||
* comparisons.
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
|
* for equality comparisons.
|
||||||
*
|
*
|
||||||
* **Notes:**
|
* **Note:** Unlike `_.without`, this method mutates `array`.
|
||||||
* - Unlike `_.without`, this method mutates `array`
|
|
||||||
* - [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
|
||||||
* comparisons are like strict equality comparisons, e.g. `===`, except
|
|
||||||
* that `NaN` matches `NaN`
|
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
import baseAt from '../internal/baseAt';
|
import baseAt from '../internal/baseAt';
|
||||||
import baseCompareAscending from '../internal/baseCompareAscending';
|
import baseCompareAscending from '../internal/baseCompareAscending';
|
||||||
import baseFlatten from '../internal/baseFlatten';
|
import baseFlatten from '../internal/baseFlatten';
|
||||||
import isIndex from '../internal/isIndex';
|
import basePullAt from '../internal/basePullAt';
|
||||||
import restParam from '../function/restParam';
|
import restParam from '../function/restParam';
|
||||||
|
|
||||||
/** Used for native method references. */
|
|
||||||
var arrayProto = Array.prototype;
|
|
||||||
|
|
||||||
/** Native method references. */
|
|
||||||
var splice = arrayProto.splice;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes elements from `array` corresponding to the given indexes and returns
|
* Removes elements from `array` corresponding to the given indexes and returns
|
||||||
* an array of the removed elements. Indexes may be specified as an array of
|
* an array of the removed elements. Indexes may be specified as an array of
|
||||||
@@ -36,20 +30,10 @@ var splice = arrayProto.splice;
|
|||||||
* // => [10, 20]
|
* // => [10, 20]
|
||||||
*/
|
*/
|
||||||
var pullAt = restParam(function(array, indexes) {
|
var pullAt = restParam(function(array, indexes) {
|
||||||
array || (array = []);
|
|
||||||
indexes = baseFlatten(indexes);
|
indexes = baseFlatten(indexes);
|
||||||
|
|
||||||
var length = indexes.length,
|
var result = baseAt(array, indexes);
|
||||||
result = baseAt(array, indexes);
|
basePullAt(array, indexes.sort(baseCompareAscending));
|
||||||
|
|
||||||
indexes.sort(baseCompareAscending);
|
|
||||||
while (length--) {
|
|
||||||
var index = parseFloat(indexes[length]);
|
|
||||||
if (index != previous && isIndex(index)) {
|
|
||||||
var previous = index;
|
|
||||||
splice.call(array, index, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import baseCallback from '../internal/baseCallback';
|
import baseCallback from '../internal/baseCallback';
|
||||||
|
import basePullAt from '../internal/basePullAt';
|
||||||
/** Used for native method references. */
|
|
||||||
var arrayProto = Array.prototype;
|
|
||||||
|
|
||||||
/** Native method references. */
|
|
||||||
var splice = arrayProto.splice;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all elements from `array` that `predicate` returns truthy for
|
* Removes all elements from `array` that `predicate` returns truthy for
|
||||||
@@ -46,19 +41,23 @@ var splice = arrayProto.splice;
|
|||||||
* // => [2, 4]
|
* // => [2, 4]
|
||||||
*/
|
*/
|
||||||
function remove(array, predicate, thisArg) {
|
function remove(array, predicate, thisArg) {
|
||||||
|
var result = [];
|
||||||
|
if (!(array && array.length)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = array ? array.length : 0,
|
indexes = [],
|
||||||
result = [];
|
length = array.length;
|
||||||
|
|
||||||
predicate = baseCallback(predicate, thisArg, 3);
|
predicate = baseCallback(predicate, thisArg, 3);
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var value = array[index];
|
var value = array[index];
|
||||||
if (predicate(value, index, array)) {
|
if (predicate(value, index, array)) {
|
||||||
result.push(value);
|
result.push(value);
|
||||||
splice.call(array, index--, 1);
|
indexes.push(index);
|
||||||
length--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
basePullAt(array, indexes);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import isIterateeCall from '../internal/isIterateeCall';
|
|||||||
/**
|
/**
|
||||||
* Creates a slice of `array` from `start` up to, but not including, `end`.
|
* Creates a slice of `array` from `start` up to, but not including, `end`.
|
||||||
*
|
*
|
||||||
* **Note:** This function is used instead of `Array#slice` to support node
|
* **Note:** This method is used instead of `Array#slice` to support node
|
||||||
* lists in IE < 9 and to ensure dense arrays are returned.
|
* lists in IE < 9 and to ensure dense arrays are returned.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import createSortedIndex from '../internal/createSortedIndex';
|
|||||||
/**
|
/**
|
||||||
* Uses a binary search to determine the lowest index at which `value` should
|
* Uses a binary search to determine the lowest index at which `value` should
|
||||||
* be inserted into `array` in order to maintain its sort order. If an iteratee
|
* be inserted into `array` in order to maintain its sort order. If an iteratee
|
||||||
* function is provided it is invoked for `value` and each element of `array`
|
* function is provided it's invoked for `value` and each element of `array`
|
||||||
* to compute their sort ranking. The iteratee is bound to `thisArg` and
|
* to compute their sort ranking. The iteratee is bound to `thisArg` and
|
||||||
* invoked with one argument; (value).
|
* invoked with one argument; (value).
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3,12 +3,9 @@ import baseUniq from '../internal/baseUniq';
|
|||||||
import restParam from '../function/restParam';
|
import restParam from '../function/restParam';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of unique values, in order, of the provided arrays using
|
* Creates an array of unique values, in order, from all of the provided arrays
|
||||||
* `SameValueZero` for equality comparisons.
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#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
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import isIterateeCall from '../internal/isIterateeCall';
|
|||||||
import sortedUniq from '../internal/sortedUniq';
|
import sortedUniq from '../internal/sortedUniq';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a duplicate-value-free version of an array using `SameValueZero`
|
* Creates a duplicate-free version of an array, using
|
||||||
* for equality comparisons. Providing `true` for `isSorted` performs a faster
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* search algorithm for sorted arrays. If an iteratee function is provided it
|
* for equality comparisons, in which only the first occurence of each element
|
||||||
* is invoked for each value in the array to generate the criterion by which
|
* is kept. Providing `true` for `isSorted` performs a faster search algorithm
|
||||||
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
|
* for sorted arrays. If an iteratee function is provided it's invoked for
|
||||||
* with three arguments: (value, index, array).
|
* each element in the array to generate the criterion by which uniqueness
|
||||||
|
* is computed. The `iteratee` is bound to `thisArg` and invoked with three
|
||||||
|
* arguments: (value, index, array).
|
||||||
*
|
*
|
||||||
* If a property name is provided for `iteratee` the created `_.property`
|
* If a property name is provided for `iteratee` the created `_.property`
|
||||||
* style callback returns the property value of the given element.
|
* style callback returns the property value of the given element.
|
||||||
@@ -22,10 +24,6 @@ import sortedUniq from '../internal/sortedUniq';
|
|||||||
* callback returns `true` for elements that have the properties of the given
|
* callback returns `true` for elements that have the properties of the given
|
||||||
* object, else `false`.
|
* 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
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @alias unique
|
* @alias unique
|
||||||
@@ -37,8 +35,8 @@ import sortedUniq from '../internal/sortedUniq';
|
|||||||
* @returns {Array} Returns the new duplicate-value-free array.
|
* @returns {Array} Returns the new duplicate-value-free array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.uniq([1, 2, 1]);
|
* _.uniq([2, 1, 2]);
|
||||||
* // => [1, 2]
|
* // => [2, 1]
|
||||||
*
|
*
|
||||||
* // using `isSorted`
|
* // using `isSorted`
|
||||||
* _.uniq([1, 1, 2], true);
|
* _.uniq([1, 1, 2], true);
|
||||||
@@ -61,7 +59,7 @@ function uniq(array, isSorted, iteratee, thisArg) {
|
|||||||
}
|
}
|
||||||
if (isSorted != null && typeof isSorted != 'boolean') {
|
if (isSorted != null && typeof isSorted != 'boolean') {
|
||||||
thisArg = iteratee;
|
thisArg = iteratee;
|
||||||
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
|
iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
|
||||||
isSorted = false;
|
isSorted = false;
|
||||||
}
|
}
|
||||||
iteratee = iteratee == null ? iteratee : baseCallback(iteratee, thisArg, 3);
|
iteratee = iteratee == null ? iteratee : baseCallback(iteratee, thisArg, 3);
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
|
import arrayFilter from '../internal/arrayFilter';
|
||||||
import arrayMap from '../internal/arrayMap';
|
import arrayMap from '../internal/arrayMap';
|
||||||
import arrayMax from '../internal/arrayMax';
|
|
||||||
import baseProperty from '../internal/baseProperty';
|
import baseProperty from '../internal/baseProperty';
|
||||||
|
import isArrayLike from '../internal/isArrayLike';
|
||||||
|
|
||||||
/** Used to the length of n-tuples for `_.unzip`. */
|
/* Native method references for those with the same name as other `lodash` methods. */
|
||||||
var getLength = baseProperty('length');
|
var nativeMax = Math.max;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is like `_.zip` except that it accepts an array of grouped
|
* 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.
|
* configuration.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
@@ -24,10 +25,19 @@ var getLength = baseProperty('length');
|
|||||||
* // => [['fred', 'barney'], [30, 40], [true, false]]
|
* // => [['fred', 'barney'], [30, 40], [true, false]]
|
||||||
*/
|
*/
|
||||||
function unzip(array) {
|
function unzip(array) {
|
||||||
|
if (!(array && array.length)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0,
|
length = 0;
|
||||||
result = Array(length);
|
|
||||||
|
|
||||||
|
array = arrayFilter(array, function(group) {
|
||||||
|
if (isArrayLike(group)) {
|
||||||
|
length = nativeMax(group.length, length);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var result = Array(length);
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
result[index] = arrayMap(array, baseProperty(index));
|
result[index] = arrayMap(array, baseProperty(index));
|
||||||
}
|
}
|
||||||
|
|||||||
41
array/unzipWith.js
Normal file
41
array/unzipWith.js
Normal 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;
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
import baseDifference from '../internal/baseDifference';
|
import baseDifference from '../internal/baseDifference';
|
||||||
import isArguments from '../lang/isArguments';
|
import isArrayLike from '../internal/isArrayLike';
|
||||||
import isArray from '../lang/isArray';
|
|
||||||
import restParam from '../function/restParam';
|
import restParam from '../function/restParam';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array excluding all provided values using `SameValueZero` for
|
* Creates an array excluding all provided values using
|
||||||
* equality comparisons.
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#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
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -23,7 +19,7 @@ import restParam from '../function/restParam';
|
|||||||
* // => [3]
|
* // => [3]
|
||||||
*/
|
*/
|
||||||
var without = restParam(function(array, values) {
|
var without = restParam(function(array, values) {
|
||||||
return (isArray(array) || isArguments(array))
|
return isArrayLike(array)
|
||||||
? baseDifference(array, values)
|
? baseDifference(array, values)
|
||||||
: [];
|
: [];
|
||||||
});
|
});
|
||||||
|
|||||||
10
array/xor.js
10
array/xor.js
@@ -1,10 +1,10 @@
|
|||||||
|
import arrayPush from '../internal/arrayPush';
|
||||||
import baseDifference from '../internal/baseDifference';
|
import baseDifference from '../internal/baseDifference';
|
||||||
import baseUniq from '../internal/baseUniq';
|
import baseUniq from '../internal/baseUniq';
|
||||||
import isArguments from '../lang/isArguments';
|
import isArrayLike from '../internal/isArrayLike';
|
||||||
import isArray from '../lang/isArray';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
* of the provided arrays.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
@@ -23,9 +23,9 @@ function xor() {
|
|||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var array = arguments[index];
|
var array = arguments[index];
|
||||||
if (isArray(array) || isArguments(array)) {
|
if (isArrayLike(array)) {
|
||||||
var result = result
|
var result = result
|
||||||
? baseDifference(result, array).concat(baseDifference(array, result))
|
? arrayPush(baseDifference(result, array), baseDifference(array, result))
|
||||||
: array;
|
: array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
array/zipWith.js
Normal file
36
array/zipWith.js
Normal 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;
|
||||||
2
chain.js
2
chain.js
@@ -1,5 +1,6 @@
|
|||||||
import chain from './chain/chain';
|
import chain from './chain/chain';
|
||||||
import commit from './chain/commit';
|
import commit from './chain/commit';
|
||||||
|
import concat from './chain/concat';
|
||||||
import lodash from './chain/lodash';
|
import lodash from './chain/lodash';
|
||||||
import plant from './chain/plant';
|
import plant from './chain/plant';
|
||||||
import reverse from './chain/reverse';
|
import reverse from './chain/reverse';
|
||||||
@@ -15,6 +16,7 @@ import wrapperChain from './chain/wrapperChain';
|
|||||||
export default {
|
export default {
|
||||||
'chain': chain,
|
'chain': chain,
|
||||||
'commit': commit,
|
'commit': commit,
|
||||||
|
'concat': concat,
|
||||||
'lodash': lodash,
|
'lodash': lodash,
|
||||||
'plant': plant,
|
'plant': plant,
|
||||||
'reverse': reverse,
|
'reverse': reverse,
|
||||||
|
|||||||
2
chain/concat.js
Normal file
2
chain/concat.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import wrapperConcat from './wrapperConcat'
|
||||||
|
export default wrapperConcat;
|
||||||
@@ -14,15 +14,16 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
|||||||
/**
|
/**
|
||||||
* Creates a `lodash` object which wraps `value` to enable implicit chaining.
|
* Creates a `lodash` object which wraps `value` to enable implicit chaining.
|
||||||
* Methods that operate on and return arrays, collections, and functions can
|
* Methods that operate on and return arrays, collections, and functions can
|
||||||
* be chained together. Methods that return a boolean or single value will
|
* be chained together. Methods that retrieve a single value or may return a
|
||||||
* automatically end the chain returning the unwrapped value. Explicit chaining
|
* primitive value will automatically end the chain returning the unwrapped
|
||||||
* may be enabled using `_.chain`. The execution of chained methods is lazy,
|
* value. Explicit chaining may be enabled using `_.chain`. The execution of
|
||||||
* that is, execution is deferred until `_#value` is implicitly or explicitly
|
* chained methods is lazy, that is, execution is deferred until `_#value`
|
||||||
* called.
|
* is implicitly or explicitly called.
|
||||||
*
|
*
|
||||||
* Lazy evaluation allows several methods to support shortcut fusion. Shortcut
|
* Lazy evaluation allows several methods to support shortcut fusion. Shortcut
|
||||||
* fusion is an optimization that merges iteratees to avoid creating intermediate
|
* fusion is an optimization strategy which merge iteratee calls; this can help
|
||||||
* arrays and reduce the number of iteratee executions.
|
* to avoid the creation of intermediate data structures and greatly reduce the
|
||||||
|
* number of iteratee executions.
|
||||||
*
|
*
|
||||||
* Chaining is supported in custom builds as long as the `_#value` method is
|
* Chaining is supported in custom builds as long as the `_#value` method is
|
||||||
* directly or indirectly included in the build.
|
* directly or indirectly included in the build.
|
||||||
@@ -45,35 +46,37 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
|||||||
* The chainable wrapper methods are:
|
* The chainable wrapper methods are:
|
||||||
* `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
|
* `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
|
||||||
* `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
|
* `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
|
||||||
* `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
|
* `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
|
||||||
* `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
|
* `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
|
||||||
* `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
|
* `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
|
||||||
* `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
|
* `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
|
||||||
* `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
|
* `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
|
||||||
* `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
|
* `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
|
||||||
* `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
* `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
|
||||||
|
* `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
||||||
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
|
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
|
||||||
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
|
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
|
||||||
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
|
* `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
|
||||||
* `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
|
* `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
|
||||||
* `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
|
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
|
||||||
* `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
|
* `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
|
||||||
* `without`, `wrap`, `xor`, `zip`, and `zipObject`
|
* `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
|
||||||
*
|
*
|
||||||
* The wrapper methods that are **not** chainable by default are:
|
* The wrapper methods that are **not** chainable by default are:
|
||||||
* `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
|
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
|
||||||
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
|
* `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
|
||||||
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
|
* `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
|
||||||
* `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
|
* `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
|
||||||
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
|
* `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
|
||||||
* `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
|
* `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
|
||||||
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
|
* `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
|
||||||
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
|
* `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
|
||||||
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
|
* `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
|
||||||
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
|
* `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
|
||||||
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
|
* `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
|
||||||
* `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
|
* `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
|
||||||
* `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
|
* `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,
|
* The wrapper method `sample` will return a wrapped value when `n` is provided,
|
||||||
* otherwise an unwrapped value is returned.
|
* otherwise an unwrapped value is returned.
|
||||||
@@ -88,8 +91,8 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
|||||||
* var wrapped = _([1, 2, 3]);
|
* var wrapped = _([1, 2, 3]);
|
||||||
*
|
*
|
||||||
* // returns an unwrapped value
|
* // returns an unwrapped value
|
||||||
* wrapped.reduce(function(sum, n) {
|
* wrapped.reduce(function(total, n) {
|
||||||
* return sum + n;
|
* return total + n;
|
||||||
* });
|
* });
|
||||||
* // => 6
|
* // => 6
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ import LodashWrapper from '../internal/LodashWrapper';
|
|||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var array = [1, 2];
|
* var array = [1, 2];
|
||||||
* var wrapper = _(array).push(3);
|
* var wrapped = _(array).push(3);
|
||||||
*
|
*
|
||||||
* console.log(array);
|
* console.log(array);
|
||||||
* // => [1, 2]
|
* // => [1, 2]
|
||||||
*
|
*
|
||||||
* wrapper = wrapper.commit();
|
* wrapped = wrapped.commit();
|
||||||
* console.log(array);
|
* console.log(array);
|
||||||
* // => [1, 2, 3]
|
* // => [1, 2, 3]
|
||||||
*
|
*
|
||||||
* wrapper.last();
|
* wrapped.last();
|
||||||
* // => 3
|
* // => 3
|
||||||
*
|
*
|
||||||
* console.log(array);
|
* console.log(array);
|
||||||
|
|||||||
34
chain/wrapperConcat.js
Normal file
34
chain/wrapperConcat.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import arrayConcat from '../internal/arrayConcat';
|
||||||
|
import baseFlatten from '../internal/baseFlatten';
|
||||||
|
import isArray from '../lang/isArray';
|
||||||
|
import restParam from '../function/restParam';
|
||||||
|
import toObject from '../internal/toObject';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new array joining a wrapped array with any additional arrays
|
||||||
|
* and/or values.
|
||||||
|
*
|
||||||
|
* @name concat
|
||||||
|
* @memberOf _
|
||||||
|
* @category Chain
|
||||||
|
* @param {...*} [values] The values to concatenate.
|
||||||
|
* @returns {Array} Returns the new concatenated array.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var array = [1];
|
||||||
|
* var wrapped = _(array).concat(2, [3], [[4]]);
|
||||||
|
*
|
||||||
|
* console.log(wrapped.value());
|
||||||
|
* // => [1, 2, 3, [4]]
|
||||||
|
*
|
||||||
|
* console.log(array);
|
||||||
|
* // => [1]
|
||||||
|
*/
|
||||||
|
var wrapperConcat = restParam(function(values) {
|
||||||
|
values = baseFlatten(values);
|
||||||
|
return this.thru(function(array) {
|
||||||
|
return arrayConcat(isArray(array) ? array : [toObject(array)], values);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default wrapperConcat;
|
||||||
@@ -11,17 +11,17 @@ import wrapperClone from '../internal/wrapperClone';
|
|||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var array = [1, 2];
|
* var array = [1, 2];
|
||||||
* var wrapper = _(array).map(function(value) {
|
* var wrapped = _(array).map(function(value) {
|
||||||
* return Math.pow(value, 2);
|
* return Math.pow(value, 2);
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* var other = [3, 4];
|
* var other = [3, 4];
|
||||||
* var otherWrapper = wrapper.plant(other);
|
* var otherWrapped = wrapped.plant(other);
|
||||||
*
|
*
|
||||||
* otherWrapper.value();
|
* otherWrapped.value();
|
||||||
* // => [9, 16]
|
* // => [9, 16]
|
||||||
*
|
*
|
||||||
* wrapper.value();
|
* wrapped.value();
|
||||||
* // => [1, 4]
|
* // => [1, 4]
|
||||||
*/
|
*/
|
||||||
function wrapperPlant(value) {
|
function wrapperPlant(value) {
|
||||||
|
|||||||
@@ -24,15 +24,20 @@ import thru from './thru';
|
|||||||
*/
|
*/
|
||||||
function wrapperReverse() {
|
function wrapperReverse() {
|
||||||
var value = this.__wrapped__;
|
var value = this.__wrapped__;
|
||||||
if (value instanceof LazyWrapper) {
|
|
||||||
if (this.__actions__.length) {
|
var interceptor = function(value) {
|
||||||
value = new LazyWrapper(this);
|
|
||||||
}
|
|
||||||
return new LodashWrapper(value.reverse(), this.__chain__);
|
|
||||||
}
|
|
||||||
return this.thru(function(value) {
|
|
||||||
return value.reverse();
|
return value.reverse();
|
||||||
});
|
};
|
||||||
|
if (value instanceof LazyWrapper) {
|
||||||
|
var wrapped = value;
|
||||||
|
if (this.__actions__.length) {
|
||||||
|
wrapped = new LazyWrapper(this);
|
||||||
|
}
|
||||||
|
wrapped = wrapped.reverse();
|
||||||
|
wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
|
||||||
|
return new LodashWrapper(wrapped, this.__chain__);
|
||||||
|
}
|
||||||
|
return this.thru(interceptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default wrapperReverse;
|
export default wrapperReverse;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import baseAt from '../internal/baseAt';
|
import baseAt from '../internal/baseAt';
|
||||||
import baseFlatten from '../internal/baseFlatten';
|
import baseFlatten from '../internal/baseFlatten';
|
||||||
import isLength from '../internal/isLength';
|
|
||||||
import restParam from '../function/restParam';
|
import restParam from '../function/restParam';
|
||||||
import toIterable from '../internal/toIterable';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of elements corresponding to the given keys, or indexes,
|
* Creates an array of elements corresponding to the given keys, or indexes,
|
||||||
@@ -25,10 +23,6 @@ import toIterable from '../internal/toIterable';
|
|||||||
* // => ['barney', 'pebbles']
|
* // => ['barney', 'pebbles']
|
||||||
*/
|
*/
|
||||||
var at = restParam(function(collection, props) {
|
var at = restParam(function(collection, props) {
|
||||||
var length = collection ? collection.length : 0;
|
|
||||||
if (isLength(length)) {
|
|
||||||
collection = toIterable(collection);
|
|
||||||
}
|
|
||||||
return baseAt(collection, baseFlatten(props));
|
return baseAt(collection, baseFlatten(props));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ import isIterateeCall from '../internal/isIterateeCall';
|
|||||||
function every(collection, predicate, thisArg) {
|
function every(collection, predicate, thisArg) {
|
||||||
var func = isArray(collection) ? arrayEvery : baseEvery;
|
var func = isArray(collection) ? arrayEvery : baseEvery;
|
||||||
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
|
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
|
||||||
predicate = null;
|
predicate = undefined;
|
||||||
}
|
}
|
||||||
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
|
if (typeof predicate != 'function' || thisArg !== undefined) {
|
||||||
predicate = baseCallback(predicate, thisArg, 3);
|
predicate = baseCallback(predicate, thisArg, 3);
|
||||||
}
|
}
|
||||||
return func(collection, predicate);
|
return func(collection, predicate);
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import createForEach from '../internal/createForEach';
|
|||||||
/**
|
/**
|
||||||
* Iterates over elements of `collection` invoking `iteratee` for each element.
|
* Iterates over elements of `collection` invoking `iteratee` for each element.
|
||||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
||||||
* (value, index|key, collection). Iterator functions may exit iteration early
|
* (value, index|key, collection). Iteratee functions may exit iteration early
|
||||||
* by explicitly returning `false`.
|
* by explicitly returning `false`.
|
||||||
*
|
*
|
||||||
* **Note:** As with other "Collections" methods, objects with a `length` property
|
* **Note:** As with other "Collections" methods, objects with a "length" property
|
||||||
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
|
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
|
||||||
* may be used for object iteration.
|
* may be used for object iteration.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import baseIndexOf from '../internal/baseIndexOf';
|
import baseIndexOf from '../internal/baseIndexOf';
|
||||||
|
import getLength from '../internal/getLength';
|
||||||
import isArray from '../lang/isArray';
|
import isArray from '../lang/isArray';
|
||||||
import isIterateeCall from '../internal/isIterateeCall';
|
import isIterateeCall from '../internal/isIterateeCall';
|
||||||
import isLength from '../internal/isLength';
|
import isLength from '../internal/isLength';
|
||||||
@@ -9,13 +10,10 @@ import values from '../object/values';
|
|||||||
var nativeMax = Math.max;
|
var nativeMax = Math.max;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is in `collection` using `SameValueZero` for equality
|
* Checks if `target` is in `collection` using
|
||||||
* comparisons. If `fromIndex` is negative, it is used as the offset from
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* the end of `collection`.
|
* for equality comparisons. If `fromIndex` is negative, it's 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`.
|
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -41,22 +39,19 @@ var nativeMax = Math.max;
|
|||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
function includes(collection, target, fromIndex, guard) {
|
function includes(collection, target, fromIndex, guard) {
|
||||||
var length = collection ? collection.length : 0;
|
var length = collection ? getLength(collection) : 0;
|
||||||
if (!isLength(length)) {
|
if (!isLength(length)) {
|
||||||
collection = values(collection);
|
collection = values(collection);
|
||||||
length = collection.length;
|
length = collection.length;
|
||||||
}
|
}
|
||||||
if (!length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
|
if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
|
||||||
fromIndex = 0;
|
fromIndex = 0;
|
||||||
} else {
|
} else {
|
||||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
||||||
}
|
}
|
||||||
return (typeof collection == 'string' || !isArray(collection) && isString(collection))
|
return (typeof collection == 'string' || !isArray(collection) && isString(collection))
|
||||||
? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)
|
? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
|
||||||
: (baseIndexOf(collection, target, fromIndex) > -1);
|
: (!!length && baseIndexOf(collection, target, fromIndex) > -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default includes;
|
export default includes;
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
import baseEach from '../internal/baseEach';
|
import baseEach from '../internal/baseEach';
|
||||||
import isLength from '../internal/isLength';
|
import invokePath from '../internal/invokePath';
|
||||||
|
import isArrayLike from '../internal/isArrayLike';
|
||||||
|
import isKey from '../internal/isKey';
|
||||||
import restParam from '../function/restParam';
|
import restParam from '../function/restParam';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes the method named by `methodName` on each element in `collection`,
|
* Invokes the method at `path` of each element in `collection`, returning
|
||||||
* returning an array of the results of each invoked method. Any additional
|
* an array of the results of each invoked method. Any additional arguments
|
||||||
* arguments are provided to each invoked method. If `methodName` is a function
|
* are provided to each invoked method. If `methodName` is a function it's
|
||||||
* it is invoked for, and `this` bound to, each element in `collection`.
|
* invoked for, and `this` bound to, each element in `collection`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Collection
|
* @category Collection
|
||||||
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Array|Object|string} collection The collection to iterate over.
|
||||||
* @param {Function|string} methodName The name of the method to invoke or
|
* @param {Array|Function|string} path The path of the method to invoke or
|
||||||
* the function invoked per iteration.
|
* the function invoked per iteration.
|
||||||
* @param {...*} [args] The arguments to invoke the method with.
|
* @param {...*} [args] The arguments to invoke the method with.
|
||||||
* @returns {Array} Returns the array of results.
|
* @returns {Array} Returns the array of results.
|
||||||
@@ -24,15 +26,15 @@ import restParam from '../function/restParam';
|
|||||||
* _.invoke([123, 456], String.prototype.split, '');
|
* _.invoke([123, 456], String.prototype.split, '');
|
||||||
* // => [['1', '2', '3'], ['4', '5', '6']]
|
* // => [['1', '2', '3'], ['4', '5', '6']]
|
||||||
*/
|
*/
|
||||||
var invoke = restParam(function(collection, methodName, args) {
|
var invoke = restParam(function(collection, path, args) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
isFunc = typeof methodName == 'function',
|
isFunc = typeof path == 'function',
|
||||||
length = collection ? collection.length : 0,
|
isProp = isKey(path),
|
||||||
result = isLength(length) ? Array(length) : [];
|
result = isArrayLike(collection) ? Array(collection.length) : [];
|
||||||
|
|
||||||
baseEach(collection, function(value) {
|
baseEach(collection, function(value) {
|
||||||
var func = isFunc ? methodName : (value != null && value[methodName]);
|
var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
|
||||||
result[++index] = func ? func.apply(value, args) : undefined;
|
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,14 +19,15 @@ import isArray from '../lang/isArray';
|
|||||||
* callback returns `true` for elements that have the properties of the given
|
* callback returns `true` for elements that have the properties of the given
|
||||||
* object, else `false`.
|
* 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`.
|
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
||||||
*
|
*
|
||||||
* The guarded methods are:
|
* The guarded methods are:
|
||||||
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
|
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
|
||||||
* `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`,
|
* `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
|
||||||
* `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`,
|
* `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
|
||||||
* `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words`
|
* `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
|
||||||
|
* `sum`, `uniq`, and `words`
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -35,7 +36,6 @@ import isArray from '../lang/isArray';
|
|||||||
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Array|Object|string} collection The collection to iterate over.
|
||||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||||
* per iteration.
|
* per iteration.
|
||||||
* create a `_.property` or `_.matches` style callback respectively.
|
|
||||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||||
* @returns {Array} Returns the new mapped array.
|
* @returns {Array} Returns the new mapped array.
|
||||||
* @example
|
* @example
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import baseProperty from '../internal/baseProperty';
|
|
||||||
import map from './map';
|
import map from './map';
|
||||||
|
import property from '../utility/property';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of `key` from all elements in `collection`.
|
* Gets the property value of `path` from all elements in `collection`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Collection
|
* @category Collection
|
||||||
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Array|Object|string} collection The collection to iterate over.
|
||||||
* @param {string} key The key of the property to pluck.
|
* @param {Array|string} path The path of the property to pluck.
|
||||||
* @returns {Array} Returns the property values.
|
* @returns {Array} Returns the property values.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -24,8 +24,8 @@ import map from './map';
|
|||||||
* _.pluck(userIndex, 'age');
|
* _.pluck(userIndex, 'age');
|
||||||
* // => [36, 40] (iteration order is not guaranteed)
|
* // => [36, 40] (iteration order is not guaranteed)
|
||||||
*/
|
*/
|
||||||
function pluck(collection, key) {
|
function pluck(collection, path) {
|
||||||
return map(collection, baseProperty(key));
|
return map(collection, property(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
export default pluck;
|
export default pluck;
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ import createReduce from '../internal/createReduce';
|
|||||||
* value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
|
* value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
|
||||||
* (accumulator, value, index|key, collection).
|
* (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`.
|
* `_.reduce`, `_.reduceRight`, and `_.transform`.
|
||||||
*
|
*
|
||||||
* The guarded methods are:
|
* The guarded methods are:
|
||||||
* `assign`, `defaults`, `includes`, `merge`, `sortByAll`, and `sortByOrder`
|
* `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
|
||||||
|
* and `sortByOrder`
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -27,8 +28,8 @@ import createReduce from '../internal/createReduce';
|
|||||||
* @returns {*} Returns the accumulated value.
|
* @returns {*} Returns the accumulated value.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.reduce([1, 2], function(sum, n) {
|
* _.reduce([1, 2], function(total, n) {
|
||||||
* return sum + n;
|
* return total + n;
|
||||||
* });
|
* });
|
||||||
* // => 3
|
* // => 3
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -24,6 +24,6 @@ import createReduce from '../internal/createReduce';
|
|||||||
* }, []);
|
* }, []);
|
||||||
* // => [4, 5, 2, 3, 0, 1]
|
* // => [4, 5, 2, 3, 0, 1]
|
||||||
*/
|
*/
|
||||||
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
|
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
|
||||||
|
|
||||||
export default reduceRight;
|
export default reduceRight;
|
||||||
|
|||||||
@@ -7,17 +7,6 @@ import isArray from '../lang/isArray';
|
|||||||
* The opposite of `_.filter`; this method returns the elements of `collection`
|
* The opposite of `_.filter`; this method returns the elements of `collection`
|
||||||
* that `predicate` does **not** return truthy for.
|
* 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
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Collection
|
* @category Collection
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import baseRandom from '../internal/baseRandom';
|
import baseRandom from '../internal/baseRandom';
|
||||||
import isIterateeCall from '../internal/isIterateeCall';
|
import isIterateeCall from '../internal/isIterateeCall';
|
||||||
import shuffle from './shuffle';
|
import toArray from '../lang/toArray';
|
||||||
import toIterable from '../internal/toIterable';
|
import toIterable from '../internal/toIterable';
|
||||||
|
|
||||||
/* Native method references for those with the same name as other `lodash` methods. */
|
/* 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;
|
var length = collection.length;
|
||||||
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
|
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
|
||||||
}
|
}
|
||||||
var result = shuffle(collection);
|
var index = -1,
|
||||||
result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import baseRandom from '../internal/baseRandom';
|
import sample from './sample';
|
||||||
import toIterable from '../internal/toIterable';
|
|
||||||
|
/** Used as references for `-Infinity` and `Infinity`. */
|
||||||
|
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of shuffled values, using a version of the
|
* Creates an array of shuffled values, using a version of the
|
||||||
@@ -16,20 +18,7 @@ import toIterable from '../internal/toIterable';
|
|||||||
* // => [4, 1, 3, 2]
|
* // => [4, 1, 3, 2]
|
||||||
*/
|
*/
|
||||||
function shuffle(collection) {
|
function shuffle(collection) {
|
||||||
collection = toIterable(collection);
|
return sample(collection, POSITIVE_INFINITY);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default shuffle;
|
export default shuffle;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import getLength from '../internal/getLength';
|
||||||
import isLength from '../internal/isLength';
|
import isLength from '../internal/isLength';
|
||||||
import keys from '../object/keys';
|
import keys from '../object/keys';
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ import keys from '../object/keys';
|
|||||||
* // => 7
|
* // => 7
|
||||||
*/
|
*/
|
||||||
function size(collection) {
|
function size(collection) {
|
||||||
var length = collection ? collection.length : 0;
|
var length = collection ? getLength(collection) : 0;
|
||||||
return isLength(length) ? length : keys(collection).length;
|
return isLength(length) ? length : keys(collection).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,9 +56,9 @@ import isIterateeCall from '../internal/isIterateeCall';
|
|||||||
function some(collection, predicate, thisArg) {
|
function some(collection, predicate, thisArg) {
|
||||||
var func = isArray(collection) ? arraySome : baseSome;
|
var func = isArray(collection) ? arraySome : baseSome;
|
||||||
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
|
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
|
||||||
predicate = null;
|
predicate = undefined;
|
||||||
}
|
}
|
||||||
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
|
if (typeof predicate != 'function' || thisArg !== undefined) {
|
||||||
predicate = baseCallback(predicate, thisArg, 3);
|
predicate = baseCallback(predicate, thisArg, 3);
|
||||||
}
|
}
|
||||||
return func(collection, predicate);
|
return func(collection, predicate);
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import baseCallback from '../internal/baseCallback';
|
import baseCallback from '../internal/baseCallback';
|
||||||
import baseEach from '../internal/baseEach';
|
import baseMap from '../internal/baseMap';
|
||||||
import baseSortBy from '../internal/baseSortBy';
|
import baseSortBy from '../internal/baseSortBy';
|
||||||
import compareAscending from '../internal/compareAscending';
|
import compareAscending from '../internal/compareAscending';
|
||||||
import isIterateeCall from '../internal/isIterateeCall';
|
import isIterateeCall from '../internal/isIterateeCall';
|
||||||
import isLength from '../internal/isLength';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of elements, sorted in ascending order by the results of
|
* Creates an array of elements, sorted in ascending order by the results of
|
||||||
@@ -27,9 +26,8 @@ import isLength from '../internal/isLength';
|
|||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Collection
|
* @category Collection
|
||||||
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Array|Object|string} collection The collection to iterate over.
|
||||||
* @param {Array|Function|Object|string} [iteratee=_.identity] The function
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||||
* invoked per iteration. If a property name or an object is provided it is
|
* per iteration.
|
||||||
* used to create a `_.property` or `_.matches` style callback respectively.
|
|
||||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||||
* @returns {Array} Returns the new sorted array.
|
* @returns {Array} Returns the new sorted array.
|
||||||
* @example
|
* @example
|
||||||
@@ -58,16 +56,14 @@ function sortBy(collection, iteratee, thisArg) {
|
|||||||
if (collection == null) {
|
if (collection == null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
var index = -1,
|
|
||||||
length = collection.length,
|
|
||||||
result = isLength(length) ? Array(length) : [];
|
|
||||||
|
|
||||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||||
iteratee = null;
|
iteratee = undefined;
|
||||||
}
|
}
|
||||||
|
var index = -1;
|
||||||
iteratee = baseCallback(iteratee, thisArg, 3);
|
iteratee = baseCallback(iteratee, thisArg, 3);
|
||||||
baseEach(collection, function(value, key, collection) {
|
|
||||||
result[++index] = { 'criteria': iteratee(value, key, collection), 'index': index, 'value': value };
|
var result = baseMap(collection, function(value, key, collection) {
|
||||||
|
return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
|
||||||
});
|
});
|
||||||
return baseSortBy(result, compareAscending);
|
return baseSortBy(result, compareAscending);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +1,52 @@
|
|||||||
import baseFlatten from '../internal/baseFlatten';
|
import baseFlatten from '../internal/baseFlatten';
|
||||||
import baseSortByOrder from '../internal/baseSortByOrder';
|
import baseSortByOrder from '../internal/baseSortByOrder';
|
||||||
import isIterateeCall from '../internal/isIterateeCall';
|
import isIterateeCall from '../internal/isIterateeCall';
|
||||||
|
import restParam from '../function/restParam';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is like `_.sortBy` except that it sorts by property names
|
* This method is like `_.sortBy` except that it can sort by multiple iteratees
|
||||||
* instead of an iteratee function.
|
* or property names.
|
||||||
|
*
|
||||||
|
* If a property name is provided for an iteratee the created `_.property`
|
||||||
|
* style callback returns the property value of the given element.
|
||||||
|
*
|
||||||
|
* If an object is provided for an iteratee the created `_.matches` style
|
||||||
|
* callback returns `true` for elements that have the properties of the given
|
||||||
|
* object, else `false`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Collection
|
* @category Collection
|
||||||
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Array|Object|string} collection The collection to iterate over.
|
||||||
* @param {...(string|string[])} props The property names to sort by,
|
* @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
|
||||||
* specified as individual property names or arrays of property names.
|
* The iteratees to sort by, specified as individual values or arrays of values.
|
||||||
* @returns {Array} Returns the new sorted array.
|
* @returns {Array} Returns the new sorted array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
|
* { 'user': 'fred', 'age': 48 },
|
||||||
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'barney', 'age': 36 },
|
||||||
* { 'user': 'fred', 'age': 40 },
|
* { 'user': 'fred', 'age': 42 },
|
||||||
* { 'user': 'barney', 'age': 26 },
|
* { 'user': 'barney', 'age': 34 }
|
||||||
* { 'user': 'fred', 'age': 30 }
|
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* _.map(_.sortByAll(users, ['user', 'age']), _.values);
|
* _.map(_.sortByAll(users, ['user', 'age']), _.values);
|
||||||
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
|
* // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
|
||||||
|
*
|
||||||
|
* _.map(_.sortByAll(users, 'user', function(chr) {
|
||||||
|
* return Math.floor(chr.age / 10);
|
||||||
|
* }), _.values);
|
||||||
|
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
||||||
*/
|
*/
|
||||||
function sortByAll() {
|
var sortByAll = restParam(function(collection, iteratees) {
|
||||||
var args = arguments,
|
|
||||||
collection = args[0],
|
|
||||||
guard = args[3],
|
|
||||||
index = 0,
|
|
||||||
length = args.length - 1;
|
|
||||||
|
|
||||||
if (collection == null) {
|
if (collection == null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
var props = Array(length);
|
var guard = iteratees[2];
|
||||||
while (index < length) {
|
if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
|
||||||
props[index] = args[++index];
|
iteratees.length = 1;
|
||||||
}
|
}
|
||||||
if (guard && isIterateeCall(args[1], args[2], guard)) {
|
return baseSortByOrder(collection, baseFlatten(iteratees), []);
|
||||||
props = args[1];
|
});
|
||||||
}
|
|
||||||
return baseSortByOrder(collection, baseFlatten(props), []);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default sortByAll;
|
export default sortByAll;
|
||||||
|
|||||||
@@ -4,45 +4,52 @@ import isIterateeCall from '../internal/isIterateeCall';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is like `_.sortByAll` except that it allows specifying the
|
* This method is like `_.sortByAll` except that it allows specifying the
|
||||||
* sort orders of the property names to sort by. A truthy value in `orders`
|
* sort orders of the iteratees to sort by. If `orders` is unspecified, all
|
||||||
* will sort the corresponding property name in ascending order while a
|
* values are sorted in ascending order. Otherwise, a value is sorted in
|
||||||
* falsey value will sort it in descending order.
|
* ascending order if its corresponding order is "asc", and descending if "desc".
|
||||||
|
*
|
||||||
|
* If a property name is provided for an iteratee the created `_.property`
|
||||||
|
* style callback returns the property value of the given element.
|
||||||
|
*
|
||||||
|
* If an object is provided for an iteratee the created `_.matches` style
|
||||||
|
* callback returns `true` for elements that have the properties of the given
|
||||||
|
* object, else `false`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Collection
|
* @category Collection
|
||||||
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Array|Object|string} collection The collection to iterate over.
|
||||||
* @param {string[]} props The property names to sort by.
|
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
|
||||||
* @param {boolean[]} orders The sort orders of `props`.
|
* @param {boolean[]} [orders] The sort orders of `iteratees`.
|
||||||
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
|
||||||
* @returns {Array} Returns the new sorted array.
|
* @returns {Array} Returns the new sorted array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
* { 'user': 'barney', 'age': 26 },
|
* { 'user': 'fred', 'age': 48 },
|
||||||
* { 'user': 'fred', 'age': 40 },
|
* { 'user': 'barney', 'age': 34 },
|
||||||
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'fred', 'age': 42 },
|
||||||
* { 'user': 'fred', 'age': 30 }
|
* { 'user': 'barney', 'age': 36 }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* // sort by `user` in ascending order and by `age` in descending order
|
* // sort by `user` in ascending order and by `age` in descending order
|
||||||
* _.map(_.sortByOrder(users, ['user', 'age'], [true, false]), _.values);
|
* _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
|
||||||
* // => [['barney', 36], ['barney', 26], ['fred', 40], ['fred', 30]]
|
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
||||||
*/
|
*/
|
||||||
function sortByOrder(collection, props, orders, guard) {
|
function sortByOrder(collection, iteratees, orders, guard) {
|
||||||
if (collection == null) {
|
if (collection == null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
if (guard && isIterateeCall(props, orders, guard)) {
|
if (guard && isIterateeCall(iteratees, orders, guard)) {
|
||||||
orders = null;
|
orders = undefined;
|
||||||
}
|
}
|
||||||
if (!isArray(props)) {
|
if (!isArray(iteratees)) {
|
||||||
props = props == null ? [] : [props];
|
iteratees = iteratees == null ? [] : [iteratees];
|
||||||
}
|
}
|
||||||
if (!isArray(orders)) {
|
if (!isArray(orders)) {
|
||||||
orders = orders == null ? [] : [orders];
|
orders = orders == null ? [] : [orders];
|
||||||
}
|
}
|
||||||
return baseSortByOrder(collection, props, orders);
|
return baseSortByOrder(collection, iteratees, orders);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default sortByOrder;
|
export default sortByOrder;
|
||||||
|
|||||||
@@ -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. */
|
/* 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
|
* Gets the number of milliseconds that have elapsed since the Unix epoch
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import delay from './function/delay';
|
|||||||
import flow from './function/flow';
|
import flow from './function/flow';
|
||||||
import flowRight from './function/flowRight';
|
import flowRight from './function/flowRight';
|
||||||
import memoize from './function/memoize';
|
import memoize from './function/memoize';
|
||||||
|
import modArgs from './function/modArgs';
|
||||||
import negate from './function/negate';
|
import negate from './function/negate';
|
||||||
import once from './function/once';
|
import once from './function/once';
|
||||||
import partial from './function/partial';
|
import partial from './function/partial';
|
||||||
@@ -41,6 +42,7 @@ export default {
|
|||||||
'flow': flow,
|
'flow': flow,
|
||||||
'flowRight': flowRight,
|
'flowRight': flowRight,
|
||||||
'memoize': memoize,
|
'memoize': memoize,
|
||||||
|
'modArgs': modArgs,
|
||||||
'negate': negate,
|
'negate': negate,
|
||||||
'once': once,
|
'once': once,
|
||||||
'partial': partial,
|
'partial': partial,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ var nativeIsFinite = root.isFinite;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The opposite of `_.before`; this method creates a function that invokes
|
* The opposite of `_.before`; this method creates a function that invokes
|
||||||
* `func` once it is called `n` or more times.
|
* `func` once it's called `n` or more times.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ var nativeMax = Math.max;
|
|||||||
*/
|
*/
|
||||||
function ary(func, n, guard) {
|
function ary(func, n, guard) {
|
||||||
if (guard && isIterateeCall(func, n, guard)) {
|
if (guard && isIterateeCall(func, n, guard)) {
|
||||||
n = null;
|
n = undefined;
|
||||||
}
|
}
|
||||||
n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
|
n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
|
||||||
return createWrapper(func, ARY_FLAG, null, null, null, null, n);
|
return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ary;
|
export default ary;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that invokes `func`, with the `this` binding and arguments
|
* Creates a function that invokes `func`, with the `this` binding and arguments
|
||||||
* of the created function, while it is called less than `n` times. Subsequent
|
* of the created function, while it's called less than `n` times. Subsequent
|
||||||
* calls to the created function return the result of the last `func` invocation.
|
* calls to the created function return the result of the last `func` invocation.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
@@ -31,8 +31,9 @@ function before(n, func) {
|
|||||||
return function() {
|
return function() {
|
||||||
if (--n > 0) {
|
if (--n > 0) {
|
||||||
result = func.apply(this, arguments);
|
result = func.apply(this, arguments);
|
||||||
} else {
|
}
|
||||||
func = null;
|
if (n <= 1) {
|
||||||
|
func = undefined;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var BIND_FLAG = 1,
|
|||||||
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
|
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
|
||||||
* may be used as a placeholder for partially applied arguments.
|
* may be used as a placeholder for partially applied arguments.
|
||||||
*
|
*
|
||||||
* **Note:** Unlike native `Function#bind` this method does not set the `length`
|
* **Note:** Unlike native `Function#bind` this method does not set the "length"
|
||||||
* property of bound functions.
|
* property of bound functions.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var BIND_FLAG = 1;
|
|||||||
* of method names. If no method names are provided all enumerable function
|
* of method names. If no method names are provided all enumerable function
|
||||||
* properties, own and inherited, of `object` are bound.
|
* properties, own and inherited, of `object` are bound.
|
||||||
*
|
*
|
||||||
* **Note:** This method does not set the `length` property of bound functions.
|
* **Note:** This method does not set the "length" property of bound functions.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ var BIND_FLAG = 1,
|
|||||||
*
|
*
|
||||||
* This method differs from `_.bind` by allowing bound functions to reference
|
* This method differs from `_.bind` by allowing bound functions to reference
|
||||||
* methods that may be redefined or don't yet exist.
|
* methods that may be redefined or don't yet exist.
|
||||||
* See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern)
|
* See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
|
* The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ var CURRY_FLAG = 8;
|
|||||||
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
|
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
|
||||||
* may be used as a placeholder for provided arguments.
|
* may be used as a placeholder for provided arguments.
|
||||||
*
|
*
|
||||||
* **Note:** This method does not set the `length` property of curried functions.
|
* **Note:** This method does not set the "length" property of curried functions.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ var CURRY_RIGHT_FLAG = 16;
|
|||||||
* The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
|
* The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
|
||||||
* builds, may be used as a placeholder for provided arguments.
|
* builds, may be used as a placeholder for provided arguments.
|
||||||
*
|
*
|
||||||
* **Note:** This method does not set the `length` property of curried functions.
|
* **Note:** This method does not set the "length" property of curried functions.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
|||||||
var nativeMax = Math.max;
|
var nativeMax = Math.max;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that delays invoking `func` until after `wait` milliseconds
|
* Creates a debounced function that delays invoking `func` until after `wait`
|
||||||
* have elapsed since the last time it was invoked. The created function comes
|
* milliseconds have elapsed since the last time the debounced function was
|
||||||
* with a `cancel` method to cancel delayed invocations. Provide an options
|
* invoked. The debounced function comes with a `cancel` method to cancel
|
||||||
* object to indicate that `func` should be invoked on the leading and/or
|
* delayed invocations. Provide an options object to indicate that `func`
|
||||||
* trailing edge of the `wait` timeout. Subsequent calls to the debounced
|
* should be invoked on the leading and/or trailing edge of the `wait` timeout.
|
||||||
* function return the result of the last `func` invocation.
|
* 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
|
* **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
|
* on the trailing edge of the timeout only if the the debounced function is
|
||||||
@@ -31,7 +32,7 @@ var nativeMax = Math.max;
|
|||||||
* @param {boolean} [options.leading=false] Specify invoking on the leading
|
* @param {boolean} [options.leading=false] Specify invoking on the leading
|
||||||
* edge of the timeout.
|
* edge of the timeout.
|
||||||
* @param {number} [options.maxWait] The maximum time `func` is allowed to be
|
* @param {number} [options.maxWait] The maximum time `func` is allowed to be
|
||||||
* delayed before it is invoked.
|
* delayed before it's invoked.
|
||||||
* @param {boolean} [options.trailing=true] Specify invoking on the trailing
|
* @param {boolean} [options.trailing=true] Specify invoking on the trailing
|
||||||
* edge of the timeout.
|
* edge of the timeout.
|
||||||
* @returns {Function} Returns the new debounced function.
|
* @returns {Function} Returns the new debounced function.
|
||||||
@@ -89,9 +90,9 @@ function debounce(func, wait, options) {
|
|||||||
var leading = true;
|
var leading = true;
|
||||||
trailing = false;
|
trailing = false;
|
||||||
} else if (isObject(options)) {
|
} else if (isObject(options)) {
|
||||||
leading = options.leading;
|
leading = !!options.leading;
|
||||||
maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
|
maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
|
||||||
trailing = 'trailing' in options ? options.trailing : trailing;
|
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancel() {
|
function cancel() {
|
||||||
@@ -101,41 +102,35 @@ function debounce(func, wait, options) {
|
|||||||
if (maxTimeoutId) {
|
if (maxTimeoutId) {
|
||||||
clearTimeout(maxTimeoutId);
|
clearTimeout(maxTimeoutId);
|
||||||
}
|
}
|
||||||
|
lastCalled = 0;
|
||||||
maxTimeoutId = timeoutId = trailingCall = undefined;
|
maxTimeoutId = timeoutId = trailingCall = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function complete(isCalled, id) {
|
||||||
|
if (id) {
|
||||||
|
clearTimeout(id);
|
||||||
|
}
|
||||||
|
maxTimeoutId = timeoutId = trailingCall = undefined;
|
||||||
|
if (isCalled) {
|
||||||
|
lastCalled = now();
|
||||||
|
result = func.apply(thisArg, args);
|
||||||
|
if (!timeoutId && !maxTimeoutId) {
|
||||||
|
args = thisArg = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function delayed() {
|
function delayed() {
|
||||||
var remaining = wait - (now() - stamp);
|
var remaining = wait - (now() - stamp);
|
||||||
if (remaining <= 0 || remaining > wait) {
|
if (remaining <= 0 || remaining > wait) {
|
||||||
if (maxTimeoutId) {
|
complete(trailingCall, maxTimeoutId);
|
||||||
clearTimeout(maxTimeoutId);
|
|
||||||
}
|
|
||||||
var isCalled = trailingCall;
|
|
||||||
maxTimeoutId = timeoutId = trailingCall = undefined;
|
|
||||||
if (isCalled) {
|
|
||||||
lastCalled = now();
|
|
||||||
result = func.apply(thisArg, args);
|
|
||||||
if (!timeoutId && !maxTimeoutId) {
|
|
||||||
args = thisArg = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
timeoutId = setTimeout(delayed, remaining);
|
timeoutId = setTimeout(delayed, remaining);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function maxDelayed() {
|
function maxDelayed() {
|
||||||
if (timeoutId) {
|
complete(trailing, timeoutId);
|
||||||
clearTimeout(timeoutId);
|
|
||||||
}
|
|
||||||
maxTimeoutId = timeoutId = trailingCall = undefined;
|
|
||||||
if (trailing || (maxWait !== wait)) {
|
|
||||||
lastCalled = now();
|
|
||||||
result = func.apply(thisArg, args);
|
|
||||||
if (!timeoutId && !maxTimeoutId) {
|
|
||||||
args = thisArg = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function debounced() {
|
function debounced() {
|
||||||
@@ -175,7 +170,7 @@ function debounce(func, wait, options) {
|
|||||||
result = func.apply(thisArg, args);
|
result = func.apply(thisArg, args);
|
||||||
}
|
}
|
||||||
if (isCalled && !timeoutId && !maxTimeoutId) {
|
if (isCalled && !timeoutId && !maxTimeoutId) {
|
||||||
args = thisArg = null;
|
args = thisArg = undefined;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import restParam from './restParam';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Defers invoking the `func` until the current call stack has cleared. Any
|
* Defers invoking the `func` until the current call stack has cleared. Any
|
||||||
* additional arguments are provided to `func` when it is invoked.
|
* additional arguments are provided to `func` when it's invoked.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import restParam from './restParam';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes `func` after `wait` milliseconds. Any additional arguments are
|
* Invokes `func` after `wait` milliseconds. Any additional arguments are
|
||||||
* provided to `func` when it is invoked.
|
* provided to `func` when it's invoked.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
|||||||
*
|
*
|
||||||
* **Note:** The cache is exposed as the `cache` property on the memoized
|
* **Note:** The cache is exposed as the `cache` property on the memoized
|
||||||
* function. Its creation may be customized by replacing the `_.memoize.Cache`
|
* function. Its creation may be customized by replacing the `_.memoize.Cache`
|
||||||
* constructor with one whose instances implement the [`Map`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
|
* constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
|
||||||
* method interface of `get`, `has`, and `set`.
|
* method interface of `get`, `has`, and `set`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
@@ -60,14 +60,14 @@ function memoize(func, resolver) {
|
|||||||
}
|
}
|
||||||
var memoized = function() {
|
var memoized = function() {
|
||||||
var args = arguments,
|
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)) {
|
if (cache.has(key)) {
|
||||||
return cache.get(key);
|
return cache.get(key);
|
||||||
}
|
}
|
||||||
var result = func.apply(this, args);
|
var result = func.apply(this, args);
|
||||||
cache.set(key, result);
|
memoized.cache = cache.set(key, result);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
memoized.cache = new memoize.Cache;
|
memoized.cache = new memoize.Cache;
|
||||||
|
|||||||
58
function/modArgs.js
Normal file
58
function/modArgs.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import arrayEvery from '../internal/arrayEvery';
|
||||||
|
import baseFlatten from '../internal/baseFlatten';
|
||||||
|
import baseIsFunction from '../internal/baseIsFunction';
|
||||||
|
import restParam from './restParam';
|
||||||
|
|
||||||
|
/** Used as the `TypeError` message for "Functions" methods. */
|
||||||
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
|
/* Native method references for those with the same name as other `lodash` methods. */
|
||||||
|
var nativeMin = Math.min;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function that runs each argument through a corresponding
|
||||||
|
* transform function.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Function
|
||||||
|
* @param {Function} func The function to wrap.
|
||||||
|
* @param {...(Function|Function[])} [transforms] The functions to transform
|
||||||
|
* arguments, specified as individual functions or arrays of functions.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* function doubled(n) {
|
||||||
|
* return n * 2;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* function square(n) {
|
||||||
|
* return n * n;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* var modded = _.modArgs(function(x, y) {
|
||||||
|
* return [x, y];
|
||||||
|
* }, square, doubled);
|
||||||
|
*
|
||||||
|
* modded(1, 2);
|
||||||
|
* // => [1, 4]
|
||||||
|
*
|
||||||
|
* modded(5, 10);
|
||||||
|
* // => [25, 20]
|
||||||
|
*/
|
||||||
|
var modArgs = restParam(function(func, transforms) {
|
||||||
|
transforms = baseFlatten(transforms);
|
||||||
|
if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
|
||||||
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
|
}
|
||||||
|
var length = transforms.length;
|
||||||
|
return restParam(function(args) {
|
||||||
|
var index = nativeMin(args.length, length);
|
||||||
|
while (index--) {
|
||||||
|
args[index] = transforms[index](args[index]);
|
||||||
|
}
|
||||||
|
return func.apply(this, args);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default modArgs;
|
||||||
@@ -18,7 +18,7 @@ import before from './before';
|
|||||||
* // `initialize` invokes `createApplication` once
|
* // `initialize` invokes `createApplication` once
|
||||||
*/
|
*/
|
||||||
function once(func) {
|
function once(func) {
|
||||||
return before(func, 2);
|
return before(2, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default once;
|
export default once;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ var PARTIAL_FLAG = 32;
|
|||||||
* The `_.partial.placeholder` value, which defaults to `_` in monolithic
|
* The `_.partial.placeholder` value, which defaults to `_` in monolithic
|
||||||
* builds, may be used as a placeholder for partially applied arguments.
|
* builds, may be used as a placeholder for partially applied arguments.
|
||||||
*
|
*
|
||||||
* **Note:** This method does not set the `length` property of partially
|
* **Note:** This method does not set the "length" property of partially
|
||||||
* applied functions.
|
* applied functions.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ var PARTIAL_RIGHT_FLAG = 64;
|
|||||||
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
|
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
|
||||||
* builds, may be used as a placeholder for partially applied arguments.
|
* builds, may be used as a placeholder for partially applied arguments.
|
||||||
*
|
*
|
||||||
* **Note:** This method does not set the `length` property of partially
|
* **Note:** This method does not set the "length" property of partially
|
||||||
* applied functions.
|
* applied functions.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ var REARG_FLAG = 256;
|
|||||||
* // => [3, 6, 9]
|
* // => [3, 6, 9]
|
||||||
*/
|
*/
|
||||||
var rearg = restParam(function(func, indexes) {
|
var rearg = restParam(function(func, indexes) {
|
||||||
return createWrapper(func, REARG_FLAG, null, null, null, baseFlatten(indexes));
|
return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
|
||||||
});
|
});
|
||||||
|
|
||||||
export default rearg;
|
export default rearg;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ var nativeMax = Math.max;
|
|||||||
* Creates a function that invokes `func` with the `this` binding of the
|
* Creates a function that invokes `func` with the `this` binding of the
|
||||||
* created function and arguments from `start` and beyond provided as an array.
|
* created function and arguments from `start` and beyond provided as an array.
|
||||||
*
|
*
|
||||||
* **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
|
* **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters).
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -30,7 +30,7 @@ function restParam(func, start) {
|
|||||||
if (typeof func != 'function') {
|
if (typeof func != 'function') {
|
||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
start = nativeMax(typeof start == 'undefined' ? (func.length - 1) : (+start || 0), 0);
|
start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
|
||||||
return function() {
|
return function() {
|
||||||
var args = arguments,
|
var args = arguments,
|
||||||
index = -1,
|
index = -1,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
|||||||
* Creates a function that invokes `func` with the `this` binding of the created
|
* Creates a function that invokes `func` with the `this` binding of the created
|
||||||
* function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
|
* function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
|
||||||
*
|
*
|
||||||
* **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
|
* **Note:** This method is based on the [spread operator](https://developer.mozilla.org/Web/JavaScript/Reference/Operators/Spread_operator).
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -4,20 +4,13 @@ import isObject from '../lang/isObject';
|
|||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Used as the `TypeError` message for "Functions" methods. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
/** Used as an internal `_.debounce` options object by `_.throttle`. */
|
|
||||||
var debounceOptions = {
|
|
||||||
'leading': false,
|
|
||||||
'maxWait': 0,
|
|
||||||
'trailing': false
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that only invokes `func` at most once per every `wait`
|
* Creates a throttled function that only invokes `func` at most once per
|
||||||
* milliseconds. The created function comes with a `cancel` method to cancel
|
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
||||||
* delayed invocations. Provide an options object to indicate that `func`
|
* method to cancel delayed invocations. Provide an options object to indicate
|
||||||
* should be invoked on the leading and/or trailing edge of the `wait` timeout.
|
* that `func` should be invoked on the leading and/or trailing edge of the
|
||||||
* Subsequent calls to the throttled function return the result of the last
|
* `wait` timeout. Subsequent calls to the throttled function return the
|
||||||
* `func` call.
|
* result of the last `func` call.
|
||||||
*
|
*
|
||||||
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
|
* **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
|
* on the trailing edge of the timeout only if the the throttled function is
|
||||||
@@ -63,10 +56,7 @@ function throttle(func, wait, options) {
|
|||||||
leading = 'leading' in options ? !!options.leading : leading;
|
leading = 'leading' in options ? !!options.leading : leading;
|
||||||
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
||||||
}
|
}
|
||||||
debounceOptions.leading = leading;
|
return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
|
||||||
debounceOptions.maxWait = +wait;
|
|
||||||
debounceOptions.trailing = trailing;
|
|
||||||
return debounce(func, wait, debounceOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default throttle;
|
export default throttle;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var PARTIAL_FLAG = 32;
|
|||||||
*/
|
*/
|
||||||
function wrap(value, wrapper) {
|
function wrap(value, wrapper) {
|
||||||
wrapper = wrapper == null ? identity : wrapper;
|
wrapper = wrapper == null ? identity : wrapper;
|
||||||
return createWrapper(wrapper, PARTIAL_FLAG, null, [value], []);
|
return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default wrap;
|
export default wrap;
|
||||||
|
|||||||
@@ -12,13 +12,12 @@ var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
|||||||
*/
|
*/
|
||||||
function LazyWrapper(value) {
|
function LazyWrapper(value) {
|
||||||
this.__wrapped__ = value;
|
this.__wrapped__ = value;
|
||||||
this.__actions__ = null;
|
this.__actions__ = [];
|
||||||
this.__dir__ = 1;
|
this.__dir__ = 1;
|
||||||
this.__dropCount__ = 0;
|
|
||||||
this.__filtered__ = false;
|
this.__filtered__ = false;
|
||||||
this.__iteratees__ = null;
|
this.__iteratees__ = [];
|
||||||
this.__takeCount__ = POSITIVE_INFINITY;
|
this.__takeCount__ = POSITIVE_INFINITY;
|
||||||
this.__views__ = null;
|
this.__views__ = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import cachePush from './cachePush';
|
import cachePush from './cachePush';
|
||||||
import isNative from '../lang/isNative';
|
import getNative from './getNative';
|
||||||
import root from './root';
|
import root from './root';
|
||||||
|
|
||||||
/** Native method references. */
|
/** 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. */
|
/* 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');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
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;
|
||||||
30
internal/arrayExtremum.js
Normal file
30
internal/arrayExtremum.js
Normal 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;
|
||||||
@@ -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;
|
|
||||||
@@ -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;
|
|
||||||
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
|
* @private
|
||||||
* @param {Array} array The array to iterate over.
|
* @param {Array} array The array to iterate over.
|
||||||
|
* @param {Function} iteratee The function invoked per iteration.
|
||||||
* @returns {number} Returns the sum.
|
* @returns {number} Returns the sum.
|
||||||
*/
|
*/
|
||||||
function arraySum(array) {
|
function arraySum(array, iteratee) {
|
||||||
var length = array.length,
|
var length = array.length,
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
while (length--) {
|
while (length--) {
|
||||||
result += +array[length] || 0;
|
result += +iteratee(array[length]) || 0;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
* @returns {*} Returns the value to assign to the destination object.
|
* @returns {*} Returns the value to assign to the destination object.
|
||||||
*/
|
*/
|
||||||
function assignDefaults(objectValue, sourceValue) {
|
function assignDefaults(objectValue, sourceValue) {
|
||||||
return typeof objectValue == 'undefined' ? sourceValue : objectValue;
|
return objectValue === undefined ? sourceValue : objectValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default assignDefaults;
|
export default assignDefaults;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
|||||||
/**
|
/**
|
||||||
* Used by `_.template` to customize its `_.assign` use.
|
* Used by `_.template` to customize its `_.assign` use.
|
||||||
*
|
*
|
||||||
* **Note:** This method is like `assignDefaults` except that it ignores
|
* **Note:** This function is like `assignDefaults` except that it ignores
|
||||||
* inherited property values when checking if a property is `undefined`.
|
* inherited property values when checking if a property is `undefined`.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
@@ -18,7 +18,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
|||||||
* @returns {*} Returns the value to assign to the destination object.
|
* @returns {*} Returns the value to assign to the destination object.
|
||||||
*/
|
*/
|
||||||
function assignOwnDefaults(objectValue, sourceValue, key, object) {
|
function assignOwnDefaults(objectValue, sourceValue, key, object) {
|
||||||
return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key))
|
return (objectValue === undefined || !hasOwnProperty.call(object, key))
|
||||||
? sourceValue
|
? sourceValue
|
||||||
: objectValue;
|
: objectValue;
|
||||||
}
|
}
|
||||||
|
|||||||
32
internal/assignWith.js
Normal file
32
internal/assignWith.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import keys from '../object/keys';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A specialized version of `_.assign` for customizing assigned values without
|
||||||
|
* support for argument juggling, multiple sources, and `this` binding `customizer`
|
||||||
|
* functions.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} object The destination object.
|
||||||
|
* @param {Object} source The source object.
|
||||||
|
* @param {Function} customizer The function to customize assigned values.
|
||||||
|
* @returns {Object} Returns `object`.
|
||||||
|
*/
|
||||||
|
function assignWith(object, source, customizer) {
|
||||||
|
var index = -1,
|
||||||
|
props = keys(source),
|
||||||
|
length = props.length;
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
var key = props[index],
|
||||||
|
value = object[key],
|
||||||
|
result = customizer(value, source[key], key, object, source);
|
||||||
|
|
||||||
|
if ((result === result ? (result !== value) : (value === value)) ||
|
||||||
|
(value === undefined && !(key in object))) {
|
||||||
|
object[key] = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default assignWith;
|
||||||
@@ -3,33 +3,17 @@ import keys from '../object/keys';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.assign` without support for argument juggling,
|
* The base implementation of `_.assign` without support for argument juggling,
|
||||||
* multiple sources, and `this` binding `customizer` functions.
|
* multiple sources, and `customizer` functions.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} object The destination object.
|
* @param {Object} object The destination object.
|
||||||
* @param {Object} source The source object.
|
* @param {Object} source The source object.
|
||||||
* @param {Function} [customizer] The function to customize assigning values.
|
* @returns {Object} Returns `object`.
|
||||||
* @returns {Object} Returns the destination object.
|
|
||||||
*/
|
*/
|
||||||
function baseAssign(object, source, customizer) {
|
function baseAssign(object, source) {
|
||||||
var props = keys(source);
|
return source == null
|
||||||
if (!customizer) {
|
? object
|
||||||
return baseCopy(source, object, props);
|
: baseCopy(source, keys(source), object);
|
||||||
}
|
|
||||||
var index = -1,
|
|
||||||
length = props.length;
|
|
||||||
|
|
||||||
while (++index < length) {
|
|
||||||
var key = props[index],
|
|
||||||
value = object[key],
|
|
||||||
result = customizer(value, source[key], key, object, source);
|
|
||||||
|
|
||||||
if ((result === result ? (result !== value) : (value === value)) ||
|
|
||||||
(typeof value == 'undefined' && !(key in object))) {
|
|
||||||
object[key] = result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return object;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default baseAssign;
|
export default baseAssign;
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
|
import isArrayLike from './isArrayLike';
|
||||||
import isIndex from './isIndex';
|
import isIndex from './isIndex';
|
||||||
import isLength from './isLength';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.at` without support for strings and individual
|
* The base implementation of `_.at` without support for string collections
|
||||||
* key arguments.
|
* and individual key arguments.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
* @param {Array|Object} collection The collection to iterate over.
|
||||||
* @param {number[]|string[]} [props] The property names or indexes of elements to pick.
|
* @param {number[]|string[]} props The property names or indexes of elements to pick.
|
||||||
* @returns {Array} Returns the new array of picked elements.
|
* @returns {Array} Returns the new array of picked elements.
|
||||||
*/
|
*/
|
||||||
function baseAt(collection, props) {
|
function baseAt(collection, props) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = collection.length,
|
isNil = collection == null,
|
||||||
isArr = isLength(length),
|
isArr = !isNil && isArrayLike(collection),
|
||||||
|
length = isArr ? collection.length : 0,
|
||||||
propsLength = props.length,
|
propsLength = props.length,
|
||||||
result = Array(propsLength);
|
result = Array(propsLength);
|
||||||
|
|
||||||
while(++index < propsLength) {
|
while(++index < propsLength) {
|
||||||
var key = props[index];
|
var key = props[index];
|
||||||
if (isArr) {
|
if (isArr) {
|
||||||
key = parseFloat(key);
|
|
||||||
result[index] = isIndex(key, length) ? collection[key] : undefined;
|
result[index] = isIndex(key, length) ? collection[key] : undefined;
|
||||||
} else {
|
} else {
|
||||||
result[index] = collection[key];
|
result[index] = isNil ? undefined : collection[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import baseMatches from './baseMatches';
|
import baseMatches from './baseMatches';
|
||||||
import baseMatchesProperty from './baseMatchesProperty';
|
import baseMatchesProperty from './baseMatchesProperty';
|
||||||
import baseProperty from './baseProperty';
|
|
||||||
import bindCallback from './bindCallback';
|
import bindCallback from './bindCallback';
|
||||||
import identity from '../utility/identity';
|
import identity from '../utility/identity';
|
||||||
|
import property from '../utility/property';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.callback` which supports specifying the
|
* The base implementation of `_.callback` which supports specifying the
|
||||||
@@ -17,7 +17,7 @@ import identity from '../utility/identity';
|
|||||||
function baseCallback(func, thisArg, argCount) {
|
function baseCallback(func, thisArg, argCount) {
|
||||||
var type = typeof func;
|
var type = typeof func;
|
||||||
if (type == 'function') {
|
if (type == 'function') {
|
||||||
return typeof thisArg == 'undefined'
|
return thisArg === undefined
|
||||||
? func
|
? func
|
||||||
: bindCallback(func, thisArg, argCount);
|
: bindCallback(func, thisArg, argCount);
|
||||||
}
|
}
|
||||||
@@ -27,9 +27,9 @@ function baseCallback(func, thisArg, argCount) {
|
|||||||
if (type == 'object') {
|
if (type == 'object') {
|
||||||
return baseMatches(func);
|
return baseMatches(func);
|
||||||
}
|
}
|
||||||
return typeof thisArg == 'undefined'
|
return thisArg === undefined
|
||||||
? baseProperty(func + '')
|
? property(func)
|
||||||
: baseMatchesProperty(func + '', thisArg);
|
: baseMatchesProperty(func, thisArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default baseCallback;
|
export default baseCallback;
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import arrayCopy from './arrayCopy';
|
import arrayCopy from './arrayCopy';
|
||||||
import arrayEach from './arrayEach';
|
import arrayEach from './arrayEach';
|
||||||
import baseCopy from './baseCopy';
|
import baseAssign from './baseAssign';
|
||||||
import baseForOwn from './baseForOwn';
|
import baseForOwn from './baseForOwn';
|
||||||
import initCloneArray from './initCloneArray';
|
import initCloneArray from './initCloneArray';
|
||||||
import initCloneByTag from './initCloneByTag';
|
import initCloneByTag from './initCloneByTag';
|
||||||
import initCloneObject from './initCloneObject';
|
import initCloneObject from './initCloneObject';
|
||||||
import isArray from '../lang/isArray';
|
import isArray from '../lang/isArray';
|
||||||
import isObject from '../lang/isObject';
|
import isObject from '../lang/isObject';
|
||||||
import keys from '../object/keys';
|
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
/** `Object#toString` result references. */
|
||||||
var argsTag = '[object Arguments]',
|
var argsTag = '[object Arguments]',
|
||||||
@@ -54,7 +53,7 @@ cloneableTags[weakMapTag] = false;
|
|||||||
var objectProto = Object.prototype;
|
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.
|
* of values.
|
||||||
*/
|
*/
|
||||||
var objToString = objectProto.toString;
|
var objToString = objectProto.toString;
|
||||||
@@ -78,7 +77,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
|
|||||||
if (customizer) {
|
if (customizer) {
|
||||||
result = object ? customizer(value, key, object) : customizer(value);
|
result = object ? customizer(value, key, object) : customizer(value);
|
||||||
}
|
}
|
||||||
if (typeof result != 'undefined') {
|
if (result !== undefined) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (!isObject(value)) {
|
if (!isObject(value)) {
|
||||||
@@ -97,7 +96,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
|
|||||||
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
||||||
result = initCloneObject(isFunc ? {} : value);
|
result = initCloneObject(isFunc ? {} : value);
|
||||||
if (!isDeep) {
|
if (!isDeep) {
|
||||||
return baseCopy(value, result, keys(value));
|
return baseAssign(result, value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return cloneableTags[tag]
|
return cloneableTags[tag]
|
||||||
@@ -105,7 +104,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
|
|||||||
: (object ? value : {});
|
: (object ? value : {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for circular references and return corresponding clone.
|
// Check for circular references and return its corresponding clone.
|
||||||
stackA || (stackA = []);
|
stackA || (stackA = []);
|
||||||
stackB || (stackB = []);
|
stackB || (stackB = []);
|
||||||
|
|
||||||
|
|||||||
@@ -3,19 +3,28 @@
|
|||||||
* sorts them in ascending order without guaranteeing a stable sort.
|
* sorts them in ascending order without guaranteeing a stable sort.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {*} value The value to compare to `other`.
|
* @param {*} value The value to compare.
|
||||||
* @param {*} other The value to compare to `value`.
|
* @param {*} other The other value to compare.
|
||||||
* @returns {number} Returns the sort order indicator for `value`.
|
* @returns {number} Returns the sort order indicator for `value`.
|
||||||
*/
|
*/
|
||||||
function baseCompareAscending(value, other) {
|
function baseCompareAscending(value, other) {
|
||||||
if (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;
|
othIsReflexive = other === other;
|
||||||
|
|
||||||
if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) {
|
if ((value > other && !othIsNull) || !valIsReflexive ||
|
||||||
|
(valIsNull && !othIsUndef && othIsReflexive) ||
|
||||||
|
(valIsUndef && othIsReflexive)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) {
|
if ((value < other && !valIsNull) || !othIsReflexive ||
|
||||||
|
(othIsNull && !valIsUndef && valIsReflexive) ||
|
||||||
|
(othIsUndef && valIsReflexive)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Copies the properties of `source` to `object`.
|
* Copies properties of `source` to `object`.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} source The object to copy properties from.
|
* @param {Object} source The object to copy properties from.
|
||||||
* @param {Object} [object={}] The object to copy properties to.
|
|
||||||
* @param {Array} props The property names to copy.
|
* @param {Array} props The property names to copy.
|
||||||
|
* @param {Object} [object={}] The object to copy properties to.
|
||||||
* @returns {Object} Returns `object`.
|
* @returns {Object} Returns `object`.
|
||||||
*/
|
*/
|
||||||
function baseCopy(source, object, props) {
|
function baseCopy(source, props, object) {
|
||||||
if (!props) {
|
object || (object = {});
|
||||||
props = object;
|
|
||||||
object = {};
|
|
||||||
}
|
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = props.length;
|
length = props.length;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import isObject from '../lang/isObject';
|
import isObject from '../lang/isObject';
|
||||||
import root from './root';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.create` without support for assigning
|
* The base implementation of `_.create` without support for assigning
|
||||||
@@ -10,14 +9,14 @@ import root from './root';
|
|||||||
* @returns {Object} Returns the new object.
|
* @returns {Object} Returns the new object.
|
||||||
*/
|
*/
|
||||||
var baseCreate = (function() {
|
var baseCreate = (function() {
|
||||||
function Object() {}
|
function object() {}
|
||||||
return function(prototype) {
|
return function(prototype) {
|
||||||
if (isObject(prototype)) {
|
if (isObject(prototype)) {
|
||||||
Object.prototype = prototype;
|
object.prototype = prototype;
|
||||||
var result = new Object;
|
var result = new object;
|
||||||
Object.prototype = null;
|
object.prototype = undefined;
|
||||||
}
|
}
|
||||||
return result || root.Object();
|
return result || {};
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import baseIndexOf from './baseIndexOf';
|
|||||||
import cacheIndexOf from './cacheIndexOf';
|
import cacheIndexOf from './cacheIndexOf';
|
||||||
import createCache from './createCache';
|
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
|
* The base implementation of `_.difference` which accepts a single array
|
||||||
* of values to exclude.
|
* of values to exclude.
|
||||||
@@ -21,7 +24,7 @@ function baseDifference(array, values) {
|
|||||||
var index = -1,
|
var index = -1,
|
||||||
indexOf = baseIndexOf,
|
indexOf = baseIndexOf,
|
||||||
isCommon = true,
|
isCommon = true,
|
||||||
cache = (isCommon && values.length >= 200) ? createCache(values) : null,
|
cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
|
||||||
valuesLength = values.length;
|
valuesLength = values.length;
|
||||||
|
|
||||||
if (cache) {
|
if (cache) {
|
||||||
|
|||||||
@@ -1,30 +1,24 @@
|
|||||||
import baseEach from './baseEach';
|
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
|
* Gets the extremum value of `collection` invoking `iteratee` for each value
|
||||||
* in `collection` to generate the criterion by which the value is ranked.
|
* 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
|
* @private
|
||||||
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Array|Object|string} collection The collection to iterate over.
|
||||||
* @param {Function} iteratee The function invoked per iteration.
|
* @param {Function} iteratee The function invoked per iteration.
|
||||||
* @param {boolean} [isMin] Specify returning the minimum, instead of the
|
* @param {Function} comparator The function used to compare values.
|
||||||
* maximum, extremum value.
|
* @param {*} exValue The initial extremum value.
|
||||||
* @returns {*} Returns the extremum value.
|
* @returns {*} Returns the extremum value.
|
||||||
*/
|
*/
|
||||||
function extremumBy(collection, iteratee, isMin) {
|
function baseExtremum(collection, iteratee, comparator, exValue) {
|
||||||
var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY,
|
var computed = exValue,
|
||||||
computed = exValue,
|
|
||||||
result = computed;
|
result = computed;
|
||||||
|
|
||||||
baseEach(collection, function(value, index, collection) {
|
baseEach(collection, function(value, index, collection) {
|
||||||
var current = iteratee(value, index, collection);
|
var current = +iteratee(value, index, collection);
|
||||||
if ((isMin ? (current < computed) : (current > computed)) ||
|
if (comparator(current, computed) || (current === exValue && current === result)) {
|
||||||
(current === exValue && current === result)) {
|
|
||||||
computed = current;
|
computed = current;
|
||||||
result = value;
|
result = value;
|
||||||
}
|
}
|
||||||
@@ -32,4 +26,4 @@ function extremumBy(collection, iteratee, isMin) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default extremumBy;
|
export default baseExtremum;
|
||||||
@@ -15,7 +15,7 @@ function baseFill(array, value, start, end) {
|
|||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
start = -start > length ? 0 : (length + start);
|
start = -start > length ? 0 : (length + start);
|
||||||
}
|
}
|
||||||
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
|
end = (end === undefined || end > length) ? length : (+end || 0);
|
||||||
if (end < 0) {
|
if (end < 0) {
|
||||||
end += length;
|
end += length;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import arrayPush from './arrayPush';
|
||||||
import isArguments from '../lang/isArguments';
|
import isArguments from '../lang/isArguments';
|
||||||
import isArray from '../lang/isArray';
|
import isArray from '../lang/isArray';
|
||||||
import isLength from './isLength';
|
import isArrayLike from './isArrayLike';
|
||||||
import isObjectLike from './isObjectLike';
|
import isObjectLike from './isObjectLike';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,33 +10,29 @@ import isObjectLike from './isObjectLike';
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Array} array The array to flatten.
|
* @param {Array} array The array to flatten.
|
||||||
* @param {boolean} isDeep Specify a deep flatten.
|
* @param {boolean} [isDeep] Specify a deep flatten.
|
||||||
* @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
|
* @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
|
||||||
|
* @param {Array} [result=[]] The initial result value.
|
||||||
* @returns {Array} Returns the new flattened array.
|
* @returns {Array} Returns the new flattened array.
|
||||||
*/
|
*/
|
||||||
function baseFlatten(array, isDeep, isStrict) {
|
function baseFlatten(array, isDeep, isStrict, result) {
|
||||||
|
result || (result = []);
|
||||||
|
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = array.length,
|
length = array.length;
|
||||||
resIndex = -1,
|
|
||||||
result = [];
|
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var value = array[index];
|
var value = array[index];
|
||||||
|
if (isObjectLike(value) && isArrayLike(value) &&
|
||||||
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
|
(isStrict || isArray(value) || isArguments(value))) {
|
||||||
if (isDeep) {
|
if (isDeep) {
|
||||||
// Recursively flatten arrays (susceptible to call stack limits).
|
// Recursively flatten arrays (susceptible to call stack limits).
|
||||||
value = baseFlatten(value, isDeep, isStrict);
|
baseFlatten(value, isDeep, isStrict, result);
|
||||||
}
|
} else {
|
||||||
var valIndex = -1,
|
arrayPush(result, value);
|
||||||
valLength = value.length;
|
|
||||||
|
|
||||||
result.length += valLength;
|
|
||||||
while (++valIndex < valLength) {
|
|
||||||
result[++resIndex] = value[valIndex];
|
|
||||||
}
|
}
|
||||||
} else if (!isStrict) {
|
} else if (!isStrict) {
|
||||||
result[++resIndex] = value;
|
result[result.length] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import createBaseFor from './createBaseFor';
|
|||||||
/**
|
/**
|
||||||
* The base implementation of `baseForIn` and `baseForOwn` which iterates
|
* The base implementation of `baseForIn` and `baseForOwn` which iterates
|
||||||
* over `object` properties returned by `keysFunc` invoking `iteratee` for
|
* over `object` properties returned by `keysFunc` invoking `iteratee` for
|
||||||
* each property. Iterator functions may exit iteration early by explicitly
|
* each property. Iteratee functions may exit iteration early by explicitly
|
||||||
* returning `false`.
|
* returning `false`.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
29
internal/baseGet.js
Normal file
29
internal/baseGet.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import toObject from './toObject';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base implementation of `get` without support for string paths
|
||||||
|
* and default values.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} object The object to query.
|
||||||
|
* @param {Array} path The path of the property to get.
|
||||||
|
* @param {string} [pathKey] The key representation of path.
|
||||||
|
* @returns {*} Returns the resolved value.
|
||||||
|
*/
|
||||||
|
function baseGet(object, path, pathKey) {
|
||||||
|
if (object == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pathKey !== undefined && pathKey in toObject(object)) {
|
||||||
|
path = [pathKey];
|
||||||
|
}
|
||||||
|
var index = 0,
|
||||||
|
length = path.length;
|
||||||
|
|
||||||
|
while (object != null && index < length) {
|
||||||
|
object = object[path[index++]];
|
||||||
|
}
|
||||||
|
return (index && index == length) ? object : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default baseGet;
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import baseIsEqualDeep from './baseIsEqualDeep';
|
import baseIsEqualDeep from './baseIsEqualDeep';
|
||||||
|
import isObject from '../lang/isObject';
|
||||||
|
import isObjectLike from './isObjectLike';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.isEqual` without support for `this` binding
|
* 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`.
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
||||||
*/
|
*/
|
||||||
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
|
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
|
||||||
// Exit early for identical values.
|
|
||||||
if (value === other) {
|
if (value === other) {
|
||||||
// Treat `+0` vs. `-0` as not equal.
|
return true;
|
||||||
return value !== 0 || (1 / value == 1 / other);
|
|
||||||
}
|
}
|
||||||
var valType = typeof value,
|
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
|
||||||
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`.
|
|
||||||
return value !== value && other !== other;
|
return value !== value && other !== other;
|
||||||
}
|
}
|
||||||
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
|
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import isTypedArray from '../lang/isTypedArray';
|
|||||||
/** `Object#toString` result references. */
|
/** `Object#toString` result references. */
|
||||||
var argsTag = '[object Arguments]',
|
var argsTag = '[object Arguments]',
|
||||||
arrayTag = '[object Array]',
|
arrayTag = '[object Array]',
|
||||||
funcTag = '[object Function]',
|
|
||||||
objectTag = '[object Object]';
|
objectTag = '[object Object]';
|
||||||
|
|
||||||
/** Used for native method references. */
|
/** Used for native method references. */
|
||||||
@@ -17,7 +16,7 @@ var objectProto = Object.prototype;
|
|||||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
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.
|
* of values.
|
||||||
*/
|
*/
|
||||||
var objToString = objectProto.toString;
|
var objToString = objectProto.toString;
|
||||||
@@ -59,28 +58,24 @@ function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA,
|
|||||||
othIsArr = isTypedArray(other);
|
othIsArr = isTypedArray(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)),
|
var objIsObj = objTag == objectTag,
|
||||||
othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)),
|
othIsObj = othTag == objectTag,
|
||||||
isSameTag = objTag == othTag;
|
isSameTag = objTag == othTag;
|
||||||
|
|
||||||
if (isSameTag && !(objIsArr || objIsObj)) {
|
if (isSameTag && !(objIsArr || objIsObj)) {
|
||||||
return equalByTag(object, other, objTag);
|
return equalByTag(object, other, objTag);
|
||||||
}
|
}
|
||||||
if (isLoose) {
|
if (!isLoose) {
|
||||||
if (!isSameTag && !(objIsObj && othIsObj)) {
|
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
||||||
return false;
|
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
|
||||||
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
|
||||||
|
|
||||||
if (valWrapped || othWrapped) {
|
if (objIsWrapped || othIsWrapped) {
|
||||||
return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
|
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
|
||||||
}
|
|
||||||
if (!isSameTag) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!isSameTag) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Assume cyclic values are equal.
|
// Assume cyclic values are equal.
|
||||||
// For more information on detecting circular references see https://es5.github.io/#JO.
|
// For more information on detecting circular references see https://es5.github.io/#JO.
|
||||||
stackA || (stackA = []);
|
stackA || (stackA = []);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import baseIsEqual from './baseIsEqual';
|
import baseIsEqual from './baseIsEqual';
|
||||||
|
import toObject from './toObject';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.isMatch` without support for callback
|
* The base implementation of `_.isMatch` without support for callback
|
||||||
@@ -6,41 +7,43 @@ import baseIsEqual from './baseIsEqual';
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} object The object to inspect.
|
* @param {Object} object The object to inspect.
|
||||||
* @param {Array} props The source property names to match.
|
* @param {Array} matchData The propery names, values, and compare flags to match.
|
||||||
* @param {Array} values The source values to match.
|
|
||||||
* @param {Array} strictCompareFlags Strict comparison flags for source values.
|
|
||||||
* @param {Function} [customizer] The function to customize comparing objects.
|
* @param {Function} [customizer] The function to customize comparing objects.
|
||||||
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
||||||
*/
|
*/
|
||||||
function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
|
function baseIsMatch(object, matchData, customizer) {
|
||||||
var index = -1,
|
var index = matchData.length,
|
||||||
length = props.length,
|
length = index,
|
||||||
noCustomizer = !customizer;
|
noCustomizer = !customizer;
|
||||||
|
|
||||||
while (++index < length) {
|
if (object == null) {
|
||||||
if ((noCustomizer && strictCompareFlags[index])
|
return !length;
|
||||||
? values[index] !== object[props[index]]
|
}
|
||||||
: !(props[index] in object)
|
object = toObject(object);
|
||||||
|
while (index--) {
|
||||||
|
var data = matchData[index];
|
||||||
|
if ((noCustomizer && data[2])
|
||||||
|
? data[1] !== object[data[0]]
|
||||||
|
: !(data[0] in object)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index = -1;
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var key = props[index],
|
data = matchData[index];
|
||||||
|
var key = data[0],
|
||||||
objValue = object[key],
|
objValue = object[key],
|
||||||
srcValue = values[index];
|
srcValue = data[1];
|
||||||
|
|
||||||
if (noCustomizer && strictCompareFlags[index]) {
|
if (noCustomizer && data[2]) {
|
||||||
var result = typeof objValue != 'undefined' || (key in object);
|
if (objValue === undefined && !(key in object)) {
|
||||||
} else {
|
return false;
|
||||||
result = customizer ? customizer(objValue, srcValue, key) : undefined;
|
}
|
||||||
if (typeof result == 'undefined') {
|
} else {
|
||||||
result = baseIsEqual(srcValue, objValue, customizer, true);
|
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;
|
return true;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import baseEach from './baseEach';
|
import baseEach from './baseEach';
|
||||||
|
import isArrayLike from './isArrayLike';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.map` without support for callback shorthands
|
* The base implementation of `_.map` without support for callback shorthands
|
||||||
@@ -10,9 +11,11 @@ import baseEach from './baseEach';
|
|||||||
* @returns {Array} Returns the new mapped array.
|
* @returns {Array} Returns the new mapped array.
|
||||||
*/
|
*/
|
||||||
function baseMap(collection, iteratee) {
|
function baseMap(collection, iteratee) {
|
||||||
var result = [];
|
var index = -1,
|
||||||
|
result = isArrayLike(collection) ? Array(collection.length) : [];
|
||||||
|
|
||||||
baseEach(collection, function(value, key, collection) {
|
baseEach(collection, function(value, key, collection) {
|
||||||
result.push(iteratee(value, key, collection));
|
result[++index] = iteratee(value, key, collection);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import baseIsMatch from './baseIsMatch';
|
import baseIsMatch from './baseIsMatch';
|
||||||
import constant from '../utility/constant';
|
import getMatchData from './getMatchData';
|
||||||
import isStrictComparable from './isStrictComparable';
|
|
||||||
import keys from '../object/keys';
|
|
||||||
import toObject from './toObject';
|
import toObject from './toObject';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,33 +10,20 @@ import toObject from './toObject';
|
|||||||
* @returns {Function} Returns the new function.
|
* @returns {Function} Returns the new function.
|
||||||
*/
|
*/
|
||||||
function baseMatches(source) {
|
function baseMatches(source) {
|
||||||
var props = keys(source),
|
var matchData = getMatchData(source);
|
||||||
length = props.length;
|
if (matchData.length == 1 && matchData[0][2]) {
|
||||||
|
var key = matchData[0][0],
|
||||||
|
value = matchData[0][1];
|
||||||
|
|
||||||
if (!length) {
|
return function(object) {
|
||||||
return constant(true);
|
if (object == null) {
|
||||||
}
|
return false;
|
||||||
if (length == 1) {
|
}
|
||||||
var key = props[0],
|
return object[key] === value && (value !== undefined || (key in toObject(object)));
|
||||||
value = source[key];
|
};
|
||||||
|
|
||||||
if (isStrictComparable(value)) {
|
|
||||||
return function(object) {
|
|
||||||
return object != null && object[key] === value &&
|
|
||||||
(typeof 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) {
|
return function(object) {
|
||||||
return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
|
return baseIsMatch(object, matchData);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,44 @@
|
|||||||
|
import baseGet from './baseGet';
|
||||||
import baseIsEqual from './baseIsEqual';
|
import baseIsEqual from './baseIsEqual';
|
||||||
|
import baseSlice from './baseSlice';
|
||||||
|
import isArray from '../lang/isArray';
|
||||||
|
import isKey from './isKey';
|
||||||
import isStrictComparable from './isStrictComparable';
|
import isStrictComparable from './isStrictComparable';
|
||||||
|
import last from '../array/last';
|
||||||
import toObject from './toObject';
|
import toObject from './toObject';
|
||||||
|
import toPath from './toPath';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.matchesProperty` which does not coerce `key`
|
* The base implementation of `_.matchesProperty` which does not clone `srcValue`.
|
||||||
* to a string.
|
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {string} key The key of the property to get.
|
* @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.
|
* @returns {Function} Returns the new function.
|
||||||
*/
|
*/
|
||||||
function baseMatchesProperty(key, value) {
|
function baseMatchesProperty(path, srcValue) {
|
||||||
if (isStrictComparable(value)) {
|
var isArr = isArray(path),
|
||||||
return function(object) {
|
isCommon = isKey(path) && isStrictComparable(srcValue),
|
||||||
return object != null && object[key] === value &&
|
pathKey = (path + '');
|
||||||
(typeof value != 'undefined' || (key in toObject(object)));
|
|
||||||
};
|
path = toPath(path);
|
||||||
}
|
|
||||||
return function(object) {
|
return function(object) {
|
||||||
return object != null && baseIsEqual(value, object[key], null, true);
|
if (object == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var key = pathKey;
|
||||||
|
object = toObject(object);
|
||||||
|
if ((isArr || !isCommon) && !(key in object)) {
|
||||||
|
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
||||||
|
if (object == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
key = last(path);
|
||||||
|
object = toObject(object);
|
||||||
|
}
|
||||||
|
return object[key] === srcValue
|
||||||
|
? (srcValue !== undefined || (key in object))
|
||||||
|
: baseIsEqual(srcValue, object[key], undefined, true);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import arrayEach from './arrayEach';
|
import arrayEach from './arrayEach';
|
||||||
import baseForOwn from './baseForOwn';
|
|
||||||
import baseMergeDeep from './baseMergeDeep';
|
import baseMergeDeep from './baseMergeDeep';
|
||||||
import isArray from '../lang/isArray';
|
import isArray from '../lang/isArray';
|
||||||
import isLength from './isLength';
|
import isArrayLike from './isArrayLike';
|
||||||
import isObject from '../lang/isObject';
|
import isObject from '../lang/isObject';
|
||||||
import isObjectLike from './isObjectLike';
|
import isObjectLike from './isObjectLike';
|
||||||
import isTypedArray from '../lang/isTypedArray';
|
import isTypedArray from '../lang/isTypedArray';
|
||||||
|
import keys from '../object/keys';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.merge` without support for argument juggling,
|
* The base implementation of `_.merge` without support for argument juggling,
|
||||||
@@ -14,32 +14,40 @@ import isTypedArray from '../lang/isTypedArray';
|
|||||||
* @private
|
* @private
|
||||||
* @param {Object} object The destination object.
|
* @param {Object} object The destination object.
|
||||||
* @param {Object} source The source object.
|
* @param {Object} source The source object.
|
||||||
* @param {Function} [customizer] The function to customize merging properties.
|
* @param {Function} [customizer] The function to customize merged values.
|
||||||
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
||||||
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
||||||
* @returns {Object} Returns the destination object.
|
* @returns {Object} Returns `object`.
|
||||||
*/
|
*/
|
||||||
function baseMerge(object, source, customizer, stackA, stackB) {
|
function baseMerge(object, source, customizer, stackA, stackB) {
|
||||||
if (!isObject(object)) {
|
if (!isObject(object)) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
|
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
|
||||||
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
|
props = isSrcArr ? undefined : keys(source);
|
||||||
|
|
||||||
|
arrayEach(props || source, function(srcValue, key) {
|
||||||
|
if (props) {
|
||||||
|
key = srcValue;
|
||||||
|
srcValue = source[key];
|
||||||
|
}
|
||||||
if (isObjectLike(srcValue)) {
|
if (isObjectLike(srcValue)) {
|
||||||
stackA || (stackA = []);
|
stackA || (stackA = []);
|
||||||
stackB || (stackB = []);
|
stackB || (stackB = []);
|
||||||
return baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
|
baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
|
||||||
}
|
}
|
||||||
var value = object[key],
|
else {
|
||||||
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
|
var value = object[key],
|
||||||
isCommon = typeof result == 'undefined';
|
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
|
||||||
|
isCommon = result === undefined;
|
||||||
|
|
||||||
if (isCommon) {
|
if (isCommon) {
|
||||||
result = srcValue;
|
result = srcValue;
|
||||||
}
|
}
|
||||||
if ((isSrcArr || typeof result != 'undefined') &&
|
if ((result !== undefined || (isSrcArr && !(key in object))) &&
|
||||||
(isCommon || (result === result ? (result !== value) : (value === value)))) {
|
(isCommon || (result === result ? (result !== value) : (value === value)))) {
|
||||||
object[key] = result;
|
object[key] = result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return object;
|
return object;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import arrayCopy from './arrayCopy';
|
import arrayCopy from './arrayCopy';
|
||||||
import isArguments from '../lang/isArguments';
|
import isArguments from '../lang/isArguments';
|
||||||
import isArray from '../lang/isArray';
|
import isArray from '../lang/isArray';
|
||||||
import isLength from './isLength';
|
import isArrayLike from './isArrayLike';
|
||||||
import isPlainObject from '../lang/isPlainObject';
|
import isPlainObject from '../lang/isPlainObject';
|
||||||
import isTypedArray from '../lang/isTypedArray';
|
import isTypedArray from '../lang/isTypedArray';
|
||||||
import toPlainObject from '../lang/toPlainObject';
|
import toPlainObject from '../lang/toPlainObject';
|
||||||
@@ -16,7 +16,7 @@ import toPlainObject from '../lang/toPlainObject';
|
|||||||
* @param {Object} source The source object.
|
* @param {Object} source The source object.
|
||||||
* @param {string} key The key of the value to merge.
|
* @param {string} key The key of the value to merge.
|
||||||
* @param {Function} mergeFunc The function to merge values.
|
* @param {Function} mergeFunc The function to merge values.
|
||||||
* @param {Function} [customizer] The function to customize merging properties.
|
* @param {Function} [customizer] The function to customize merged values.
|
||||||
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
||||||
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
||||||
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
||||||
@@ -33,14 +33,14 @@ function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stack
|
|||||||
}
|
}
|
||||||
var value = object[key],
|
var value = object[key],
|
||||||
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
|
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
|
||||||
isCommon = typeof result == 'undefined';
|
isCommon = result === undefined;
|
||||||
|
|
||||||
if (isCommon) {
|
if (isCommon) {
|
||||||
result = srcValue;
|
result = srcValue;
|
||||||
if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
|
if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
|
||||||
result = isArray(value)
|
result = isArray(value)
|
||||||
? value
|
? value
|
||||||
: ((value && value.length) ? arrayCopy(value) : []);
|
: (isArrayLike(value) ? arrayCopy(value) : []);
|
||||||
}
|
}
|
||||||
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
||||||
result = isArguments(value)
|
result = isArguments(value)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* The base implementation of `_.property` which does not coerce `key` to a string.
|
* The base implementation of `_.property` without support for deep paths.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {string} key The key of the property to get.
|
* @param {string} key The key of the property to get.
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user