mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Compare commits
2 Commits
3.9.2-npm
...
3.10.0-npm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b97a9a3da0 | ||
|
|
10d5566cf2 |
23
README.md
23
README.md
@@ -1,4 +1,4 @@
|
|||||||
# lodash v3.9.2
|
# lodash v3.10.0
|
||||||
|
|
||||||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules.
|
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules.
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ var array = require('lodash/array');
|
|||||||
var chunk = require('lodash/array/chunk');
|
var chunk = require('lodash/array/chunk');
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [package source](https://github.com/lodash/lodash/tree/3.9.2-npm) for more details.
|
See the [package source](https://github.com/lodash/lodash/tree/3.10.0-npm) for more details.
|
||||||
|
|
||||||
**Note:**<br>
|
**Note:**<br>
|
||||||
Don’t assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br>
|
Don’t assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br>
|
||||||
@@ -39,15 +39,14 @@ Install [n_](https://www.npmjs.com/package/n_) for a REPL that includes lodash b
|
|||||||
lodash is also available in a variety of other builds & module formats.
|
lodash is also available in a variety of other builds & module formats.
|
||||||
|
|
||||||
* npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds
|
* npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds
|
||||||
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.9.2-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.9.2-amd) builds
|
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.10.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.10.0-amd) builds
|
||||||
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.9.2-es) build
|
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.10.0-es) build
|
||||||
|
|
||||||
## Further Reading
|
## Further Reading
|
||||||
|
|
||||||
* [API Documentation](https://lodash.com/docs)
|
* [API Documentation](https://lodash.com/docs)
|
||||||
* [Build Differences](https://github.com/lodash/lodash/wiki/Build-Differences)
|
* [Build Differences](https://github.com/lodash/lodash/wiki/Build-Differences)
|
||||||
* [Changelog](https://github.com/lodash/lodash/wiki/Changelog)
|
* [Changelog](https://github.com/lodash/lodash/wiki/Changelog)
|
||||||
* [Release Notes](https://github.com/lodash/lodash/releases)
|
|
||||||
* [Roadmap](https://github.com/lodash/lodash/wiki/Roadmap)
|
* [Roadmap](https://github.com/lodash/lodash/wiki/Roadmap)
|
||||||
* [More Resources](https://github.com/lodash/lodash/wiki/Resources)
|
* [More Resources](https://github.com/lodash/lodash/wiki/Resources)
|
||||||
|
|
||||||
@@ -56,8 +55,7 @@ lodash is also available in a variety of other builds & module formats.
|
|||||||
* ~100% [code coverage](https://coveralls.io/r/lodash)
|
* ~100% [code coverage](https://coveralls.io/r/lodash)
|
||||||
* Follows [semantic versioning](http://semver.org/) for releases
|
* Follows [semantic versioning](http://semver.org/) for releases
|
||||||
* [Lazily evaluated](http://filimanjaro.com/blog/2014/introducing-lazy-evaluation/) chaining
|
* [Lazily evaluated](http://filimanjaro.com/blog/2014/introducing-lazy-evaluation/) chaining
|
||||||
* [_(…)](https://lodash.com/docs#_) supports intuitive chaining
|
* [_(…)](https://lodash.com/docs#_) supports implicit chaining
|
||||||
* [_.add](https://lodash.com/docs#add) for mathematical composition
|
|
||||||
* [_.ary](https://lodash.com/docs#ary) & [_.rearg](https://lodash.com/docs#rearg) to change function argument limits & order
|
* [_.ary](https://lodash.com/docs#ary) & [_.rearg](https://lodash.com/docs#rearg) to change function argument limits & order
|
||||||
* [_.at](https://lodash.com/docs#at) for cherry-picking collection values
|
* [_.at](https://lodash.com/docs#at) for cherry-picking collection values
|
||||||
* [_.attempt](https://lodash.com/docs#attempt) to execute functions which may error without a try-catch
|
* [_.attempt](https://lodash.com/docs#attempt) to execute functions which may error without a try-catch
|
||||||
@@ -68,6 +66,7 @@ lodash is also available in a variety of other builds & module formats.
|
|||||||
* [_.cloneDeep](https://lodash.com/docs#cloneDeep) for deep cloning arrays & objects
|
* [_.cloneDeep](https://lodash.com/docs#cloneDeep) for deep cloning arrays & objects
|
||||||
* [_.curry](https://lodash.com/docs#curry) & [_.curryRight](https://lodash.com/docs#curryRight) for creating [curried](http://hughfdjackson.com/javascript/why-curry-helps/) functions
|
* [_.curry](https://lodash.com/docs#curry) & [_.curryRight](https://lodash.com/docs#curryRight) for creating [curried](http://hughfdjackson.com/javascript/why-curry-helps/) functions
|
||||||
* [_.debounce](https://lodash.com/docs#debounce) & [_.throttle](https://lodash.com/docs#throttle) are cancelable & accept options for more control
|
* [_.debounce](https://lodash.com/docs#debounce) & [_.throttle](https://lodash.com/docs#throttle) are cancelable & accept options for more control
|
||||||
|
* [_.defaultsDeep](https://lodash.com/docs#defaultsDeep) for recursively assigning default properties
|
||||||
* [_.fill](https://lodash.com/docs#fill) to fill arrays with values
|
* [_.fill](https://lodash.com/docs#fill) to fill arrays with values
|
||||||
* [_.findKey](https://lodash.com/docs#findKey) for finding keys
|
* [_.findKey](https://lodash.com/docs#findKey) for finding keys
|
||||||
* [_.flow](https://lodash.com/docs#flow) to complement [_.flowRight](https://lodash.com/docs#flowRight) (a.k.a `_.compose`)
|
* [_.flow](https://lodash.com/docs#flow) to complement [_.flowRight](https://lodash.com/docs#flowRight) (a.k.a `_.compose`)
|
||||||
@@ -83,8 +82,9 @@ lodash is also available in a variety of other builds & module formats.
|
|||||||
* [_.mapKeys](https://lodash.com/docs#mapKeys) for mapping keys to an object
|
* [_.mapKeys](https://lodash.com/docs#mapKeys) for mapping keys to an object
|
||||||
* [_.matches](https://lodash.com/docs#matches) supports deep object comparisons
|
* [_.matches](https://lodash.com/docs#matches) supports deep object comparisons
|
||||||
* [_.matchesProperty](https://lodash.com/docs#matchesProperty) to complement [_.matches](https://lodash.com/docs#matches) & [_.property](https://lodash.com/docs#property)
|
* [_.matchesProperty](https://lodash.com/docs#matchesProperty) to complement [_.matches](https://lodash.com/docs#matches) & [_.property](https://lodash.com/docs#property)
|
||||||
* [_.method](https://lodash.com/docs#method) & [_.methodOf](https://lodash.com/docs#methodOf) to create functions that invoke methods
|
|
||||||
* [_.merge](https://lodash.com/docs#merge) for a deep [_.extend](https://lodash.com/docs#extend)
|
* [_.merge](https://lodash.com/docs#merge) for a deep [_.extend](https://lodash.com/docs#extend)
|
||||||
|
* [_.method](https://lodash.com/docs#method) & [_.methodOf](https://lodash.com/docs#methodOf) to create functions that invoke methods
|
||||||
|
* [_.modArgs](https://lodash.com/docs#modArgs) for more advanced functional composition
|
||||||
* [_.parseInt](https://lodash.com/docs#parseInt) for consistent cross-environment behavior
|
* [_.parseInt](https://lodash.com/docs#parseInt) for consistent cross-environment behavior
|
||||||
* [_.pull](https://lodash.com/docs#pull), [_.pullAt](https://lodash.com/docs#pullAt), & [_.remove](https://lodash.com/docs#remove) for mutating arrays
|
* [_.pull](https://lodash.com/docs#pull), [_.pullAt](https://lodash.com/docs#pullAt), & [_.remove](https://lodash.com/docs#remove) for mutating arrays
|
||||||
* [_.random](https://lodash.com/docs#random) supports returning floating-point numbers
|
* [_.random](https://lodash.com/docs#random) supports returning floating-point numbers
|
||||||
@@ -92,13 +92,14 @@ lodash is also available in a variety of other builds & module formats.
|
|||||||
* [_.runInContext](https://lodash.com/docs#runInContext) for collisionless mixins & easier mocking
|
* [_.runInContext](https://lodash.com/docs#runInContext) for collisionless mixins & easier mocking
|
||||||
* [_.slice](https://lodash.com/docs#slice) for creating subsets of array-like values
|
* [_.slice](https://lodash.com/docs#slice) for creating subsets of array-like values
|
||||||
* [_.sortByAll](https://lodash.com/docs#sortByAll) & [_.sortByOrder](https://lodash.com/docs#sortByOrder) for sorting by multiple properties & orders
|
* [_.sortByAll](https://lodash.com/docs#sortByAll) & [_.sortByOrder](https://lodash.com/docs#sortByOrder) for sorting by multiple properties & orders
|
||||||
* [_.sum](https://lodash.com/docs#sum) to get the sum of values
|
|
||||||
* [_.support](https://lodash.com/docs#support) for flagging environment features
|
* [_.support](https://lodash.com/docs#support) for flagging environment features
|
||||||
* [_.template](https://lodash.com/docs#template) supports [*“imports”*](https://lodash.com/docs#templateSettings-imports) options & [ES template delimiters](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
|
* [_.template](https://lodash.com/docs#template) supports [*“imports”*](https://lodash.com/docs#templateSettings-imports) options & [ES template delimiters](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
|
||||||
* [_.transform](https://lodash.com/docs#transform) as a powerful alternative to [_.reduce](https://lodash.com/docs#reduce) for transforming objects
|
* [_.transform](https://lodash.com/docs#transform) as a powerful alternative to [_.reduce](https://lodash.com/docs#reduce) for transforming objects
|
||||||
* [_.unzipWith](https://lodash.com/docs#unzipWith) & [_.zipWith](https://lodash.com/docs#zipWith) to specify how grouped values should be combined
|
* [_.unzipWith](https://lodash.com/docs#unzipWith) & [_.zipWith](https://lodash.com/docs#zipWith) to specify how grouped values should be combined
|
||||||
* [_.xor](https://lodash.com/docs#xor) to complement [_.difference](https://lodash.com/docs#difference), [_.intersection](https://lodash.com/docs#intersection), & [_.union](https://lodash.com/docs#union)
|
|
||||||
* [_.valuesIn](https://lodash.com/docs#valuesIn) for getting values of all enumerable properties
|
* [_.valuesIn](https://lodash.com/docs#valuesIn) for getting values of all enumerable properties
|
||||||
|
* [_.xor](https://lodash.com/docs#xor) to complement [_.difference](https://lodash.com/docs#difference), [_.intersection](https://lodash.com/docs#intersection), & [_.union](https://lodash.com/docs#union)
|
||||||
|
* [_.add](https://lodash.com/docs#add), [_.round](https://lodash.com/docs#round), [_.sum](https://lodash.com/docs#sum), &
|
||||||
|
[more](https://lodash.com/docs "_.ceil & _.floor") math methods
|
||||||
* [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), &
|
* [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), &
|
||||||
[more](https://lodash.com/docs "_.bindKey, _.curryRight, _.partialRight") support customizable argument placeholders
|
[more](https://lodash.com/docs "_.bindKey, _.curryRight, _.partialRight") support customizable argument placeholders
|
||||||
* [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), &
|
* [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), &
|
||||||
@@ -116,5 +117,5 @@ lodash is also available in a variety of other builds & module formats.
|
|||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
Tested in Chrome 41-42, Firefox 37-38, IE 6-11, MS Edge, Opera 28-29, Safari 5-8, ChakraNode 0.12.2, io.js 2.0.2, Node.js 0.8.28, 0.10.38, & 0.12.3, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7.6
|
Tested in Chrome 42-43, Firefox 37-38, IE 6-11, MS Edge, Opera 28-29, Safari 5-8, ChakraNode 0.12.2, io.js 2.3.1, Node.js 0.8.28, 0.10.38, & 0.12.5, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7.6.
|
||||||
Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Special thanks to [Sauce Labs](https://saucelabs.com/) for providing automated browser testing.
|
Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Special thanks to [Sauce Labs](https://saucelabs.com/) for providing automated browser testing.
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
var baseSlice = require('../internal/baseSlice'),
|
var baseSlice = require('../internal/baseSlice'),
|
||||||
isIterateeCall = require('../internal/isIterateeCall');
|
isIterateeCall = require('../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,11 +1,12 @@
|
|||||||
var baseDifference = require('../internal/baseDifference'),
|
var baseDifference = require('../internal/baseDifference'),
|
||||||
baseFlatten = require('../internal/baseFlatten'),
|
baseFlatten = require('../internal/baseFlatten'),
|
||||||
isArrayLike = require('../internal/isArrayLike'),
|
isArrayLike = require('../internal/isArrayLike'),
|
||||||
|
isObjectLike = require('../internal/isObjectLike'),
|
||||||
restParam = require('../function/restParam');
|
restParam = require('../function/restParam');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of unique `array` values not included in the other
|
* Creates an array of unique `array` values not included in the other
|
||||||
* provided arrays using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
* provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* for equality comparisons.
|
* for equality comparisons.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
@@ -20,7 +21,7 @@ var baseDifference = require('../internal/baseDifference'),
|
|||||||
* // => [1, 3]
|
* // => [1, 3]
|
||||||
*/
|
*/
|
||||||
var difference = restParam(function(array, values) {
|
var difference = restParam(function(array, values) {
|
||||||
return isArrayLike(array)
|
return (isObjectLike(array) && isArrayLike(array))
|
||||||
? baseDifference(array, baseFlatten(values, false, true))
|
? baseDifference(array, baseFlatten(values, false, true))
|
||||||
: [];
|
: [];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ 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`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
|
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
|
||||||
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
|
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
|
||||||
* performs a faster binary search.
|
* performs a faster binary search.
|
||||||
@@ -40,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;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ var baseIndexOf = require('../internal/baseIndexOf'),
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of unique values that are included in all of the provided
|
* Creates an array of unique values that are included in all of the provided
|
||||||
* arrays using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
* arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* for equality comparisons.
|
* for equality comparisons.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ var splice = arrayProto.splice;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all provided values from `array` using
|
* Removes all provided values from `array` using
|
||||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* for equality comparisons.
|
* for equality comparisons.
|
||||||
*
|
*
|
||||||
* **Note:** Unlike `_.without`, this method mutates `array`.
|
* **Note:** Unlike `_.without`, this method mutates `array`.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ var baseFlatten = require('../internal/baseFlatten'),
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array of unique values, in order, from all of the provided arrays
|
* Creates an array of unique values, in order, from all of the provided arrays
|
||||||
* using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* for equality comparisons.
|
* for equality comparisons.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a duplicate-free version of an array, using
|
* Creates a duplicate-free version of an array, using
|
||||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* for equality comparisons, in which only the first occurence of each element
|
* for equality comparisons, in which only the first occurence of each element
|
||||||
* is kept. Providing `true` for `isSorted` performs a faster search algorithm
|
* is kept. Providing `true` for `isSorted` performs a faster search algorithm
|
||||||
* for sorted arrays. If an iteratee function is provided it is invoked for
|
* for sorted arrays. If an iteratee function is provided it is invoked for
|
||||||
@@ -59,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);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ var baseDifference = require('../internal/baseDifference'),
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array excluding all provided values using
|
* Creates an array excluding all provided values using
|
||||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* for equality comparisons.
|
* for equality comparisons.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
var baseDifference = require('../internal/baseDifference'),
|
var arrayPush = require('../internal/arrayPush'),
|
||||||
|
baseDifference = require('../internal/baseDifference'),
|
||||||
baseUniq = require('../internal/baseUniq'),
|
baseUniq = require('../internal/baseUniq'),
|
||||||
isArrayLike = require('../internal/isArrayLike');
|
isArrayLike = require('../internal/isArrayLike');
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ function xor() {
|
|||||||
var array = arguments[index];
|
var array = arguments[index];
|
||||||
if (isArrayLike(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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
chain.js
1
chain.js
@@ -1,6 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
'chain': require('./chain/chain'),
|
'chain': require('./chain/chain'),
|
||||||
'commit': require('./chain/commit'),
|
'commit': require('./chain/commit'),
|
||||||
|
'concat': require('./chain/concat'),
|
||||||
'lodash': require('./chain/lodash'),
|
'lodash': require('./chain/lodash'),
|
||||||
'plant': require('./chain/plant'),
|
'plant': require('./chain/plant'),
|
||||||
'reverse': require('./chain/reverse'),
|
'reverse': require('./chain/reverse'),
|
||||||
|
|||||||
1
chain/concat.js
Normal file
1
chain/concat.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./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,36 +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`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
|
* `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
|
||||||
* `memoize`, `merge`, `method`, `methodOf`, `mixin`, `negate`, `omit`, `once`,
|
* `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
|
||||||
* `pairs`, `partial`, `partialRight`, `partition`, `pick`, `plant`, `pluck`,
|
* `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
||||||
* `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, `rearg`,
|
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
|
||||||
* `reject`, `remove`, `rest`, `restParam`, `reverse`, `set`, `shuffle`,
|
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
|
||||||
* `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`, `spread`,
|
* `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
|
||||||
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
|
* `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
|
||||||
* `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
|
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
|
||||||
* `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`, `where`, `without`,
|
* `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
|
||||||
* `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
|
* `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`, `get`,
|
* `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
|
||||||
* `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`, `inRange`, `isArguments`,
|
* `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
|
||||||
* `isArray`, `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`, `lt`, `lte`,
|
* `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
|
||||||
* `max`, `min`, `noConflict`, `noop`, `now`, `pad`, `padLeft`, `padRight`,
|
* `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
|
||||||
* `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`,
|
* `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
|
||||||
* `runInContext`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
|
* `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
|
||||||
* `sortedLastIndex`, `startCase`, `startsWith`, `sum`, `template`, `trim`,
|
* `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
|
||||||
* `trimLeft`, `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.
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ var LodashWrapper = require('../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 @@
|
|||||||
|
var arrayConcat = require('../internal/arrayConcat'),
|
||||||
|
baseFlatten = require('../internal/baseFlatten'),
|
||||||
|
isArray = require('../lang/isArray'),
|
||||||
|
restParam = require('../function/restParam'),
|
||||||
|
toObject = require('../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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = wrapperConcat;
|
||||||
@@ -11,17 +11,17 @@ var baseLodash = require('../internal/baseLodash'),
|
|||||||
* @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 @@ var LazyWrapper = require('../internal/LazyWrapper'),
|
|||||||
*/
|
*/
|
||||||
function wrapperReverse() {
|
function wrapperReverse() {
|
||||||
var value = this.__wrapped__;
|
var value = this.__wrapped__;
|
||||||
|
|
||||||
|
var interceptor = function(value) {
|
||||||
|
return (wrapped && wrapped.__dir__ < 0) ? value : value.reverse();
|
||||||
|
};
|
||||||
if (value instanceof LazyWrapper) {
|
if (value instanceof LazyWrapper) {
|
||||||
|
var wrapped = value;
|
||||||
if (this.__actions__.length) {
|
if (this.__actions__.length) {
|
||||||
value = new LazyWrapper(this);
|
wrapped = new LazyWrapper(this);
|
||||||
}
|
}
|
||||||
return new LodashWrapper(value.reverse(), this.__chain__);
|
wrapped = wrapped.reverse();
|
||||||
|
wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
|
||||||
|
return new LodashWrapper(wrapped, this.__chain__);
|
||||||
}
|
}
|
||||||
return this.thru(function(value) {
|
return this.thru(interceptor);
|
||||||
return value.reverse();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = wrapperReverse;
|
module.exports = wrapperReverse;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ var arrayEvery = require('../internal/arrayEvery'),
|
|||||||
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' || thisArg !== undefined) {
|
if (typeof predicate != 'function' || thisArg !== undefined) {
|
||||||
predicate = baseCallback(predicate, thisArg, 3);
|
predicate = baseCallback(predicate, thisArg, 3);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ var nativeMax = Math.max;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is in `collection` using
|
* Checks if `value` is in `collection` using
|
||||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
|
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
|
||||||
* from the end of `collection`.
|
* from the end of `collection`.
|
||||||
*
|
*
|
||||||
@@ -44,17 +44,14 @@ function includes(collection, target, fromIndex, guard) {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = includes;
|
module.exports = includes;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ var invoke = restParam(function(collection, path, args) {
|
|||||||
result = isArrayLike(collection) ? Array(collection.length) : [];
|
result = isArrayLike(collection) ? Array(collection.length) : [];
|
||||||
|
|
||||||
baseEach(collection, function(value) {
|
baseEach(collection, function(value) {
|
||||||
var func = isFunc ? path : ((isProp && value != null) ? value[path] : null);
|
var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
|
||||||
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
|
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ var arrayReduce = require('../internal/arrayReduce'),
|
|||||||
* `_.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 _
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ var arraySome = require('../internal/arraySome'),
|
|||||||
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' || thisArg !== undefined) {
|
if (typeof predicate != 'function' || thisArg !== undefined) {
|
||||||
predicate = baseCallback(predicate, thisArg, 3);
|
predicate = baseCallback(predicate, thisArg, 3);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function sortBy(collection, iteratee, thisArg) {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||||
iteratee = null;
|
iteratee = undefined;
|
||||||
}
|
}
|
||||||
var index = -1;
|
var index = -1;
|
||||||
iteratee = baseCallback(iteratee, thisArg, 3);
|
iteratee = baseCallback(iteratee, thisArg, 3);
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ var baseSortByOrder = require('../internal/baseSortByOrder'),
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 iteratees to sort by. A truthy value in `orders` will
|
* sort orders of the iteratees to sort by. If `orders` is unspecified, all
|
||||||
* sort the corresponding property name in ascending order while a falsey
|
* values are sorted in ascending order. Otherwise, a value is sorted in
|
||||||
* 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`
|
* If a property name is provided for an iteratee the created `_.property`
|
||||||
* style callback returns the property value of the given element.
|
* style callback returns the property value of the given element.
|
||||||
@@ -20,7 +20,7 @@ var baseSortByOrder = require('../internal/baseSortByOrder'),
|
|||||||
* @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[]|Object[]|string[]} iteratees The iteratees to sort by.
|
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
|
||||||
* @param {boolean[]} orders The sort orders of `iteratees`.
|
* @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
|
||||||
@@ -33,7 +33,7 @@ var baseSortByOrder = require('../internal/baseSortByOrder'),
|
|||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* // 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', 34], ['fred', 48], ['fred', 42]]
|
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
||||||
*/
|
*/
|
||||||
function sortByOrder(collection, iteratees, orders, guard) {
|
function sortByOrder(collection, iteratees, orders, guard) {
|
||||||
@@ -41,7 +41,7 @@ function sortByOrder(collection, iteratees, orders, guard) {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
if (guard && isIterateeCall(iteratees, orders, guard)) {
|
if (guard && isIterateeCall(iteratees, orders, guard)) {
|
||||||
orders = null;
|
orders = undefined;
|
||||||
}
|
}
|
||||||
if (!isArray(iteratees)) {
|
if (!isArray(iteratees)) {
|
||||||
iteratees = iteratees == null ? [] : [iteratees];
|
iteratees = iteratees == null ? [] : [iteratees];
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ module.exports = {
|
|||||||
'flow': require('./function/flow'),
|
'flow': require('./function/flow'),
|
||||||
'flowRight': require('./function/flowRight'),
|
'flowRight': require('./function/flowRight'),
|
||||||
'memoize': require('./function/memoize'),
|
'memoize': require('./function/memoize'),
|
||||||
|
'modArgs': require('./function/modArgs'),
|
||||||
'negate': require('./function/negate'),
|
'negate': require('./function/negate'),
|
||||||
'once': require('./function/once'),
|
'once': require('./function/once'),
|
||||||
'partial': require('./function/partial'),
|
'partial': require('./function/partial'),
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ary;
|
module.exports = ary;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function before(n, func) {
|
|||||||
result = func.apply(this, arguments);
|
result = func.apply(this, arguments);
|
||||||
}
|
}
|
||||||
if (n <= 1) {
|
if (n <= 1) {
|
||||||
func = null;
|
func = undefined;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -90,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() {
|
||||||
@@ -102,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() {
|
||||||
@@ -176,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
58
function/modArgs.js
Normal file
58
function/modArgs.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
var arrayEvery = require('../internal/arrayEvery'),
|
||||||
|
baseFlatten = require('../internal/baseFlatten'),
|
||||||
|
baseIsFunction = require('../internal/baseIsFunction'),
|
||||||
|
restParam = require('./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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = modArgs;
|
||||||
@@ -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));
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = rearg;
|
module.exports = rearg;
|
||||||
|
|||||||
@@ -4,13 +4,6 @@ var debounce = require('./debounce'),
|
|||||||
/** 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 throttled function that only invokes `func` at most once per
|
* Creates a throttled function that only invokes `func` at most once per
|
||||||
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = throttle;
|
module.exports = 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], []);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = wrap;
|
module.exports = 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);
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = arrayConcat;
|
||||||
20
internal/arrayPush.js
Normal file
20
internal/arrayPush.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* Appends the elements of `values` to `array`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Array} array The array to modify.
|
||||||
|
* @param {Array} values The values to append.
|
||||||
|
* @returns {Array} Returns `array`.
|
||||||
|
*/
|
||||||
|
function arrayPush(array, values) {
|
||||||
|
var index = -1,
|
||||||
|
length = values.length,
|
||||||
|
offset = array.length;
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
array[offset + index] = values[index];
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,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;
|
||||||
@@ -104,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 = []);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var baseCreate = (function() {
|
|||||||
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 || {};
|
return result || {};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ var baseIndexOf = require('./baseIndexOf'),
|
|||||||
cacheIndexOf = require('./cacheIndexOf'),
|
cacheIndexOf = require('./cacheIndexOf'),
|
||||||
createCache = require('./createCache');
|
createCache = require('./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,4 +1,5 @@
|
|||||||
var isArguments = require('../lang/isArguments'),
|
var arrayPush = require('./arrayPush'),
|
||||||
|
isArguments = require('../lang/isArguments'),
|
||||||
isArray = require('../lang/isArray'),
|
isArray = require('../lang/isArray'),
|
||||||
isArrayLike = require('./isArrayLike'),
|
isArrayLike = require('./isArrayLike'),
|
||||||
isObjectLike = require('./isObjectLike');
|
isObjectLike = require('./isObjectLike');
|
||||||
@@ -11,13 +12,14 @@ var isArguments = require('../lang/isArguments'),
|
|||||||
* @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-like 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];
|
||||||
@@ -25,16 +27,12 @@ function baseFlatten(array, isDeep, isStrict) {
|
|||||||
(isStrict || 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;
|
|
||||||
|
|
||||||
while (++valIndex < valLength) {
|
|
||||||
result[++resIndex] = value[valIndex];
|
|
||||||
}
|
}
|
||||||
} else if (!isStrict) {
|
} else if (!isStrict) {
|
||||||
result[++resIndex] = value;
|
result[result.length] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -16,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;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var arrayEach = require('./arrayEach'),
|
|||||||
* @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 `object`.
|
* @returns {Object} Returns `object`.
|
||||||
@@ -24,7 +24,7 @@ function baseMerge(object, source, customizer, stackA, stackB) {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
|
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
|
||||||
props = isSrcArr ? null : keys(source);
|
props = isSrcArr ? undefined : keys(source);
|
||||||
|
|
||||||
arrayEach(props || source, function(srcValue, key) {
|
arrayEach(props || source, function(srcValue, key) {
|
||||||
if (props) {
|
if (props) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ var arrayCopy = require('./arrayCopy'),
|
|||||||
* @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`.
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
/** Native method references. */
|
|
||||||
var floor = Math.floor;
|
|
||||||
|
|
||||||
/* 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 nativeRandom = Math.random;
|
var nativeFloor = Math.floor,
|
||||||
|
nativeRandom = Math.random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.random` without support for argument juggling
|
* The base implementation of `_.random` without support for argument juggling
|
||||||
@@ -14,7 +12,7 @@ var nativeRandom = Math.random;
|
|||||||
* @returns {number} Returns the random number.
|
* @returns {number} Returns the random number.
|
||||||
*/
|
*/
|
||||||
function baseRandom(min, max) {
|
function baseRandom(min, max) {
|
||||||
return min + floor(nativeRandom() * (max - min + 1));
|
return min + nativeFloor(nativeRandom() * (max - min + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = baseRandom;
|
module.exports = baseRandom;
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
* @returns {string} Returns the string.
|
* @returns {string} Returns the string.
|
||||||
*/
|
*/
|
||||||
function baseToString(value) {
|
function baseToString(value) {
|
||||||
if (typeof value == 'string') {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
return value == null ? '' : (value + '');
|
return value == null ? '' : (value + '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ var baseIndexOf = require('./baseIndexOf'),
|
|||||||
cacheIndexOf = require('./cacheIndexOf'),
|
cacheIndexOf = require('./cacheIndexOf'),
|
||||||
createCache = require('./createCache');
|
createCache = require('./createCache');
|
||||||
|
|
||||||
|
/** Used as the size to enable large array optimizations. */
|
||||||
|
var LARGE_ARRAY_SIZE = 200;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.uniq` without support for callback shorthands
|
* The base implementation of `_.uniq` without support for callback shorthands
|
||||||
* and `this` binding.
|
* and `this` binding.
|
||||||
@@ -16,7 +19,7 @@ function baseUniq(array, iteratee) {
|
|||||||
indexOf = baseIndexOf,
|
indexOf = baseIndexOf,
|
||||||
length = array.length,
|
length = array.length,
|
||||||
isCommon = true,
|
isCommon = true,
|
||||||
isLarge = isCommon && length >= 200,
|
isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
|
||||||
seen = isLarge ? createCache() : null,
|
seen = isLarge ? createCache() : null,
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
var LazyWrapper = require('./LazyWrapper');
|
var LazyWrapper = require('./LazyWrapper'),
|
||||||
|
arrayPush = require('./arrayPush');
|
||||||
/** Used for native method references. */
|
|
||||||
var arrayProto = Array.prototype;
|
|
||||||
|
|
||||||
/** Native method references. */
|
|
||||||
var push = arrayProto.push;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `wrapperValue` which returns the result of
|
* The base implementation of `wrapperValue` which returns the result of
|
||||||
@@ -25,11 +20,8 @@ function baseWrapperValue(value, actions) {
|
|||||||
length = actions.length;
|
length = actions.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var args = [result],
|
var action = actions[index];
|
||||||
action = actions[index];
|
result = action.func.apply(action.thisArg, arrayPush([result], action.args));
|
||||||
|
|
||||||
push.apply(args, action.args);
|
|
||||||
result = action.func.apply(action.thisArg, args);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
/** Native method references. */
|
|
||||||
var floor = Math.floor;
|
|
||||||
|
|
||||||
/* Native method references for those with the same name as other `lodash` methods. */
|
/* Native method references for those with the same name as other `lodash` methods. */
|
||||||
var nativeMin = Math.min;
|
var nativeFloor = Math.floor,
|
||||||
|
nativeMin = Math.min;
|
||||||
|
|
||||||
/** Used as references for the maximum length and index of an array. */
|
/** Used as references for the maximum length and index of an array. */
|
||||||
var MAX_ARRAY_LENGTH = 4294967295,
|
var MAX_ARRAY_LENGTH = 4294967295,
|
||||||
@@ -31,7 +29,7 @@ function binaryIndexBy(array, value, iteratee, retHighest) {
|
|||||||
valIsUndef = value === undefined;
|
valIsUndef = value === undefined;
|
||||||
|
|
||||||
while (low < high) {
|
while (low < high) {
|
||||||
var mid = floor((low + high) / 2),
|
var mid = nativeFloor((low + high) / 2),
|
||||||
computed = iteratee(array[mid]),
|
computed = iteratee(array[mid]),
|
||||||
isDef = computed !== undefined,
|
isDef = computed !== undefined,
|
||||||
isReflexive = computed === computed;
|
isReflexive = computed === computed;
|
||||||
|
|||||||
@@ -1,26 +1,6 @@
|
|||||||
var constant = require('../utility/constant'),
|
|
||||||
getNative = require('./getNative');
|
|
||||||
|
|
||||||
/** Native method references. */
|
/** Native method references. */
|
||||||
var ArrayBuffer = getNative(global, 'ArrayBuffer'),
|
var ArrayBuffer = global.ArrayBuffer,
|
||||||
bufferSlice = getNative(ArrayBuffer && new ArrayBuffer(0), 'slice'),
|
Uint8Array = global.Uint8Array;
|
||||||
floor = Math.floor,
|
|
||||||
Uint8Array = getNative(global, 'Uint8Array');
|
|
||||||
|
|
||||||
/** Used to clone array buffers. */
|
|
||||||
var Float64Array = (function() {
|
|
||||||
// Safari 5 errors when using an array buffer to initialize a typed array
|
|
||||||
// where the array buffer's `byteLength` is not a multiple of the typed
|
|
||||||
// array's `BYTES_PER_ELEMENT`.
|
|
||||||
try {
|
|
||||||
var func = getNative(global, 'Float64Array'),
|
|
||||||
result = new func(new ArrayBuffer(10), 0, 1) && func;
|
|
||||||
} catch(e) {}
|
|
||||||
return result || null;
|
|
||||||
}());
|
|
||||||
|
|
||||||
/** Used as the size, in bytes, of each `Float64Array` element. */
|
|
||||||
var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a clone of the given array buffer.
|
* Creates a clone of the given array buffer.
|
||||||
@@ -30,26 +10,11 @@ var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT :
|
|||||||
* @returns {ArrayBuffer} Returns the cloned array buffer.
|
* @returns {ArrayBuffer} Returns the cloned array buffer.
|
||||||
*/
|
*/
|
||||||
function bufferClone(buffer) {
|
function bufferClone(buffer) {
|
||||||
return bufferSlice.call(buffer, 0);
|
var result = new ArrayBuffer(buffer.byteLength),
|
||||||
}
|
view = new Uint8Array(result);
|
||||||
if (!bufferSlice) {
|
|
||||||
// PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array`.
|
|
||||||
bufferClone = !(ArrayBuffer && Uint8Array) ? constant(null) : function(buffer) {
|
|
||||||
var byteLength = buffer.byteLength,
|
|
||||||
floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0,
|
|
||||||
offset = floatLength * FLOAT64_BYTES_PER_ELEMENT,
|
|
||||||
result = new ArrayBuffer(byteLength);
|
|
||||||
|
|
||||||
if (floatLength) {
|
view.set(new Uint8Array(buffer));
|
||||||
var view = new Float64Array(result, 0, floatLength);
|
return result;
|
||||||
view.set(new Float64Array(buffer, 0, floatLength));
|
|
||||||
}
|
|
||||||
if (byteLength != offset) {
|
|
||||||
view = new Uint8Array(result, offset);
|
|
||||||
view.set(new Uint8Array(buffer, offset));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = bufferClone;
|
module.exports = bufferClone;
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ var baseCompareAscending = require('./baseCompareAscending');
|
|||||||
* sort them in ascending order.
|
* sort them in ascending order.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} object The object to compare to `other`.
|
* @param {Object} object The object to compare.
|
||||||
* @param {Object} other The object to compare to `object`.
|
* @param {Object} other The other object to compare.
|
||||||
* @returns {number} Returns the sort order indicator for `object`.
|
* @returns {number} Returns the sort order indicator for `object`.
|
||||||
*/
|
*/
|
||||||
function compareAscending(object, other) {
|
function compareAscending(object, other) {
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
var baseCompareAscending = require('./baseCompareAscending');
|
var baseCompareAscending = require('./baseCompareAscending');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `_.sortByOrder` to compare multiple properties of each element
|
* Used by `_.sortByOrder` to compare multiple properties of a value to another
|
||||||
* in a collection and stable sort them in the following order:
|
* and stable sort them.
|
||||||
*
|
*
|
||||||
* If `orders` is unspecified, sort in ascending order for all properties.
|
* If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
|
||||||
* Otherwise, for each property, sort in ascending order if its corresponding value in
|
* a value is sorted in ascending order if its corresponding order is "asc", and
|
||||||
* orders is true, and descending order if false.
|
* descending if "desc".
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} object The object to compare to `other`.
|
* @param {Object} object The object to compare.
|
||||||
* @param {Object} other The object to compare to `object`.
|
* @param {Object} other The other object to compare.
|
||||||
* @param {boolean[]} orders The order to sort by for each property.
|
* @param {boolean[]} orders The order to sort by for each property.
|
||||||
* @returns {number} Returns the sort order indicator for `object`.
|
* @returns {number} Returns the sort order indicator for `object`.
|
||||||
*/
|
*/
|
||||||
@@ -27,7 +27,8 @@ function compareMultiple(object, other, orders) {
|
|||||||
if (index >= ordersLength) {
|
if (index >= ordersLength) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return result * (orders[index] ? 1 : -1);
|
var order = orders[index];
|
||||||
|
return result * ((order === 'asc' || order === true) ? 1 : -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ function composeArgs(args, partials, holders) {
|
|||||||
argsLength = nativeMax(args.length - holdersLength, 0),
|
argsLength = nativeMax(args.length - holdersLength, 0),
|
||||||
leftIndex = -1,
|
leftIndex = -1,
|
||||||
leftLength = partials.length,
|
leftLength = partials.length,
|
||||||
result = Array(argsLength + leftLength);
|
result = Array(leftLength + argsLength);
|
||||||
|
|
||||||
while (++leftIndex < leftLength) {
|
while (++leftIndex < leftLength) {
|
||||||
result[leftIndex] = partials[leftIndex];
|
result[leftIndex] = partials[leftIndex];
|
||||||
|
|||||||
@@ -3,12 +3,7 @@ var baseCallback = require('./baseCallback'),
|
|||||||
isArray = require('../lang/isArray');
|
isArray = require('../lang/isArray');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that aggregates a collection, creating an accumulator
|
* Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
|
||||||
* object composed from the results of running each element in the collection
|
|
||||||
* through an iteratee.
|
|
||||||
*
|
|
||||||
* **Note:** This function is used to create `_.countBy`, `_.groupBy`, `_.indexBy`,
|
|
||||||
* and `_.partition`.
|
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Function} setter The function to set keys and values of the accumulator object.
|
* @param {Function} setter The function to set keys and values of the accumulator object.
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ var bindCallback = require('./bindCallback'),
|
|||||||
restParam = require('../function/restParam');
|
restParam = require('../function/restParam');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that assigns properties of source object(s) to a given
|
* Creates a `_.assign`, `_.defaults`, or `_.merge` function.
|
||||||
* destination object.
|
|
||||||
*
|
|
||||||
* **Note:** This function is used to create `_.assign`, `_.defaults`, and `_.merge`.
|
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Function} assigner The function to assign values.
|
* @param {Function} assigner The function to assign values.
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
var SetCache = require('./SetCache'),
|
var SetCache = require('./SetCache'),
|
||||||
constant = require('../utility/constant'),
|
|
||||||
getNative = require('./getNative');
|
getNative = require('./getNative');
|
||||||
|
|
||||||
/** Native method references. */
|
/** Native method references. */
|
||||||
@@ -15,8 +14,8 @@ var nativeCreate = getNative(Object, 'create');
|
|||||||
* @param {Array} [values] The values to cache.
|
* @param {Array} [values] The values to cache.
|
||||||
* @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
|
* @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
|
||||||
*/
|
*/
|
||||||
var createCache = !(nativeCreate && Set) ? constant(null) : function(values) {
|
function createCache(values) {
|
||||||
return new SetCache(values);
|
return (nativeCreate && Set) ? new SetCache(values) : null;
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = createCache;
|
module.exports = createCache;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var baseCreate = require('./baseCreate'),
|
|||||||
function createCtorWrapper(Ctor) {
|
function createCtorWrapper(Ctor) {
|
||||||
return function() {
|
return function() {
|
||||||
// Use a `switch` statement to work with class constructors.
|
// Use a `switch` statement to work with class constructors.
|
||||||
// See https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
// See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
||||||
// for more details.
|
// for more details.
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
@@ -22,6 +22,8 @@ function createCtorWrapper(Ctor) {
|
|||||||
case 3: return new Ctor(args[0], args[1], args[2]);
|
case 3: return new Ctor(args[0], args[1], args[2]);
|
||||||
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
|
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
|
||||||
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
|
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
|
||||||
|
case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
|
||||||
|
case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
|
||||||
}
|
}
|
||||||
var thisBinding = baseCreate(Ctor.prototype),
|
var thisBinding = baseCreate(Ctor.prototype),
|
||||||
result = Ctor.apply(thisBinding, args);
|
result = Ctor.apply(thisBinding, args);
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ var createWrapper = require('./createWrapper'),
|
|||||||
function createCurry(flag) {
|
function createCurry(flag) {
|
||||||
function curryFunc(func, arity, guard) {
|
function curryFunc(func, arity, guard) {
|
||||||
if (guard && isIterateeCall(func, arity, guard)) {
|
if (guard && isIterateeCall(func, arity, guard)) {
|
||||||
arity = null;
|
arity = undefined;
|
||||||
}
|
}
|
||||||
var result = createWrapper(func, flag, null, null, null, null, null, arity);
|
var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
|
||||||
result.placeholder = curryFunc.placeholder;
|
result.placeholder = curryFunc.placeholder;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
22
internal/createDefaults.js
Normal file
22
internal/createDefaults.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
var restParam = require('../function/restParam');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a `_.defaults` or `_.defaultsDeep` function.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Function} assigner The function to assign values.
|
||||||
|
* @param {Function} customizer The function to customize assigned values.
|
||||||
|
* @returns {Function} Returns the new defaults function.
|
||||||
|
*/
|
||||||
|
function createDefaults(assigner, customizer) {
|
||||||
|
return restParam(function(args) {
|
||||||
|
var object = args[0];
|
||||||
|
if (object == null) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
args.push(customizer);
|
||||||
|
return assigner.apply(undefined, args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = createDefaults;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
var arrayExtremum = require('./arrayExtremum'),
|
var arrayExtremum = require('./arrayExtremum'),
|
||||||
baseCallback = require('./baseCallback'),
|
baseCallback = require('./baseCallback'),
|
||||||
baseExtremum = require('./baseExtremum'),
|
baseExtremum = require('./baseExtremum'),
|
||||||
|
isArray = require('../lang/isArray'),
|
||||||
isIterateeCall = require('./isIterateeCall'),
|
isIterateeCall = require('./isIterateeCall'),
|
||||||
toIterable = require('./toIterable');
|
toIterable = require('./toIterable');
|
||||||
|
|
||||||
@@ -15,11 +16,11 @@ var arrayExtremum = require('./arrayExtremum'),
|
|||||||
function createExtremum(comparator, exValue) {
|
function createExtremum(comparator, exValue) {
|
||||||
return function(collection, iteratee, thisArg) {
|
return function(collection, iteratee, thisArg) {
|
||||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||||
iteratee = null;
|
iteratee = undefined;
|
||||||
}
|
}
|
||||||
iteratee = baseCallback(iteratee, thisArg, 3);
|
iteratee = baseCallback(iteratee, thisArg, 3);
|
||||||
if (iteratee.length == 1) {
|
if (iteratee.length == 1) {
|
||||||
collection = toIterable(collection);
|
collection = isArray(collection) ? collection : toIterable(collection);
|
||||||
var result = arrayExtremum(collection, iteratee, comparator, exValue);
|
var result = arrayExtremum(collection, iteratee, comparator, exValue);
|
||||||
if (!(collection.length && result === exValue)) {
|
if (!(collection.length && result === exValue)) {
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ var CURRY_FLAG = 8,
|
|||||||
ARY_FLAG = 128,
|
ARY_FLAG = 128,
|
||||||
REARG_FLAG = 256;
|
REARG_FLAG = 256;
|
||||||
|
|
||||||
|
/** Used as the size to enable large array optimizations. */
|
||||||
|
var LARGE_ARRAY_SIZE = 200;
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
/** Used as the `TypeError` message for "Functions" methods. */
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||||
|
|
||||||
@@ -34,7 +37,7 @@ function createFlow(fromRight) {
|
|||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
|
if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
|
||||||
wrapper = new LodashWrapper([]);
|
wrapper = new LodashWrapper([], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index = wrapper ? -1 : length;
|
index = wrapper ? -1 : length;
|
||||||
@@ -42,7 +45,7 @@ function createFlow(fromRight) {
|
|||||||
func = funcs[index];
|
func = funcs[index];
|
||||||
|
|
||||||
var funcName = getFuncName(func),
|
var funcName = getFuncName(func),
|
||||||
data = funcName == 'wrapper' ? getData(func) : null;
|
data = funcName == 'wrapper' ? getData(func) : undefined;
|
||||||
|
|
||||||
if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
|
if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
|
||||||
wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
|
wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
|
||||||
@@ -51,12 +54,14 @@ function createFlow(fromRight) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return function() {
|
return function() {
|
||||||
var args = arguments;
|
var args = arguments,
|
||||||
if (wrapper && args.length == 1 && isArray(args[0])) {
|
value = args[0];
|
||||||
return wrapper.plant(args[0]).value();
|
|
||||||
|
if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
|
||||||
|
return wrapper.plant(value).value();
|
||||||
}
|
}
|
||||||
var index = 0,
|
var index = 0,
|
||||||
result = length ? funcs[index].apply(this, args) : args[0];
|
result = length ? funcs[index].apply(this, args) : value;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
result = funcs[index].call(this, result);
|
result = funcs[index].call(this, result);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials
|
|||||||
isCurry = bitmask & CURRY_FLAG,
|
isCurry = bitmask & CURRY_FLAG,
|
||||||
isCurryBound = bitmask & CURRY_BOUND_FLAG,
|
isCurryBound = bitmask & CURRY_BOUND_FLAG,
|
||||||
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
|
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
|
||||||
Ctor = isBindKey ? null : createCtorWrapper(func);
|
Ctor = isBindKey ? undefined : createCtorWrapper(func);
|
||||||
|
|
||||||
function wrapper() {
|
function wrapper() {
|
||||||
// Avoid `arguments` object use disqualifying optimizations by
|
// Avoid `arguments` object use disqualifying optimizations by
|
||||||
@@ -68,12 +68,12 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials
|
|||||||
|
|
||||||
length -= argsHolders.length;
|
length -= argsHolders.length;
|
||||||
if (length < arity) {
|
if (length < arity) {
|
||||||
var newArgPos = argPos ? arrayCopy(argPos) : null,
|
var newArgPos = argPos ? arrayCopy(argPos) : undefined,
|
||||||
newArity = nativeMax(arity - length, 0),
|
newArity = nativeMax(arity - length, 0),
|
||||||
newsHolders = isCurry ? argsHolders : null,
|
newsHolders = isCurry ? argsHolders : undefined,
|
||||||
newHoldersRight = isCurry ? null : argsHolders,
|
newHoldersRight = isCurry ? undefined : argsHolders,
|
||||||
newPartials = isCurry ? args : null,
|
newPartials = isCurry ? args : undefined,
|
||||||
newPartialsRight = isCurry ? null : args;
|
newPartialsRight = isCurry ? undefined : args;
|
||||||
|
|
||||||
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
|
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
|
||||||
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
|
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
var repeat = require('../string/repeat');
|
var repeat = require('../string/repeat');
|
||||||
|
|
||||||
/** 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 nativeIsFinite = global.isFinite;
|
var nativeCeil = Math.ceil,
|
||||||
|
nativeIsFinite = global.isFinite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the padding required for `string` based on the given `length`.
|
* Creates the padding required for `string` based on the given `length`.
|
||||||
@@ -25,7 +23,7 @@ function createPadding(string, length, chars) {
|
|||||||
}
|
}
|
||||||
var padLength = length - strLength;
|
var padLength = length - strLength;
|
||||||
chars = chars == null ? ' ' : (chars + '');
|
chars = chars == null ? ' ' : (chars + '');
|
||||||
return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
|
return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = createPadding;
|
module.exports = createPadding;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ var createWrapper = require('./createWrapper'),
|
|||||||
function createPartial(flag) {
|
function createPartial(flag) {
|
||||||
var partialFunc = restParam(function(func, partials) {
|
var partialFunc = restParam(function(func, partials) {
|
||||||
var holders = replaceHolders(partials, partialFunc.placeholder);
|
var holders = replaceHolders(partials, partialFunc.placeholder);
|
||||||
return createWrapper(func, flag, null, partials, holders);
|
return createWrapper(func, flag, undefined, partials, holders);
|
||||||
});
|
});
|
||||||
return partialFunc;
|
return partialFunc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ function createPartialWrapper(func, bitmask, thisArg, partials) {
|
|||||||
argsLength = arguments.length,
|
argsLength = arguments.length,
|
||||||
leftIndex = -1,
|
leftIndex = -1,
|
||||||
leftLength = partials.length,
|
leftLength = partials.length,
|
||||||
args = Array(argsLength + leftLength);
|
args = Array(leftLength + argsLength);
|
||||||
|
|
||||||
while (++leftIndex < leftLength) {
|
while (++leftIndex < leftLength) {
|
||||||
args[leftIndex] = partials[leftIndex];
|
args[leftIndex] = partials[leftIndex];
|
||||||
|
|||||||
23
internal/createRound.js
Normal file
23
internal/createRound.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/** Native method references. */
|
||||||
|
var pow = Math.pow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a `_.ceil`, `_.floor`, or `_.round` function.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} methodName The name of the `Math` method to use when rounding.
|
||||||
|
* @returns {Function} Returns the new round function.
|
||||||
|
*/
|
||||||
|
function createRound(methodName) {
|
||||||
|
var func = Math[methodName];
|
||||||
|
return function(number, precision) {
|
||||||
|
precision = precision === undefined ? 0 : (+precision || 0);
|
||||||
|
if (precision) {
|
||||||
|
precision = pow(10, precision);
|
||||||
|
return func(number * precision) / precision;
|
||||||
|
}
|
||||||
|
return func(number);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = createRound;
|
||||||
@@ -51,16 +51,16 @@ function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, a
|
|||||||
var length = partials ? partials.length : 0;
|
var length = partials ? partials.length : 0;
|
||||||
if (!length) {
|
if (!length) {
|
||||||
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
|
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
|
||||||
partials = holders = null;
|
partials = holders = undefined;
|
||||||
}
|
}
|
||||||
length -= (holders ? holders.length : 0);
|
length -= (holders ? holders.length : 0);
|
||||||
if (bitmask & PARTIAL_RIGHT_FLAG) {
|
if (bitmask & PARTIAL_RIGHT_FLAG) {
|
||||||
var partialsRight = partials,
|
var partialsRight = partials,
|
||||||
holdersRight = holders;
|
holdersRight = holders;
|
||||||
|
|
||||||
partials = holders = null;
|
partials = holders = undefined;
|
||||||
}
|
}
|
||||||
var data = isBindKey ? null : getData(func),
|
var data = isBindKey ? undefined : getData(func),
|
||||||
newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
|
newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var boolTag = '[object Boolean]',
|
|||||||
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} value The object to compare.
|
* @param {Object} object The object to compare.
|
||||||
* @param {Object} other The other object to compare.
|
* @param {Object} other The other object to compare.
|
||||||
* @param {string} tag The `toStringTag` of the objects to compare.
|
* @param {string} tag The `toStringTag` of the objects to compare.
|
||||||
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
||||||
|
|||||||
38
internal/escapeRegExpChar.js
Normal file
38
internal/escapeRegExpChar.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/** Used to escape characters for inclusion in compiled regexes. */
|
||||||
|
var regexpEscapes = {
|
||||||
|
'0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
|
||||||
|
'5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
|
||||||
|
'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
|
||||||
|
'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
|
||||||
|
'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Used to escape characters for inclusion in compiled string literals. */
|
||||||
|
var stringEscapes = {
|
||||||
|
'\\': '\\',
|
||||||
|
"'": "'",
|
||||||
|
'\n': 'n',
|
||||||
|
'\r': 'r',
|
||||||
|
'\u2028': 'u2028',
|
||||||
|
'\u2029': 'u2029'
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} chr The matched character to escape.
|
||||||
|
* @param {string} leadingChar The capture group for a leading character.
|
||||||
|
* @param {string} whitespaceChar The capture group for a whitespace character.
|
||||||
|
* @returns {string} Returns the escaped character.
|
||||||
|
*/
|
||||||
|
function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
|
||||||
|
if (leadingChar) {
|
||||||
|
chr = regexpEscapes[chr];
|
||||||
|
} else if (whitespaceChar) {
|
||||||
|
chr = stringEscapes[chr];
|
||||||
|
}
|
||||||
|
return '\\' + chr;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = escapeRegExpChar;
|
||||||
@@ -9,8 +9,7 @@ var stringEscapes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `_.template` to escape characters for inclusion in compiled
|
* Used by `_.template` to escape characters for inclusion in compiled string literals.
|
||||||
* string literals.
|
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {string} chr The matched character to escape.
|
* @param {string} chr The matched character to escape.
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ var nativeMax = Math.max,
|
|||||||
* @private
|
* @private
|
||||||
* @param {number} start The start of the view.
|
* @param {number} start The start of the view.
|
||||||
* @param {number} end The end of the view.
|
* @param {number} end The end of the view.
|
||||||
* @param {Array} [transforms] The transformations to apply to the view.
|
* @param {Array} transforms The transformations to apply to the view.
|
||||||
* @returns {Object} Returns an object containing the `start` and `end`
|
* @returns {Object} Returns an object containing the `start` and `end`
|
||||||
* positions of the view.
|
* positions of the view.
|
||||||
*/
|
*/
|
||||||
function getView(start, end, transforms) {
|
function getView(start, end, transforms) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = transforms ? transforms.length : 0;
|
length = transforms.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var data = transforms[index],
|
var data = transforms[index],
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
/** Used to detect unsigned integer values. */
|
||||||
|
var reIsUint = /^\d+$/;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
||||||
* of an array-like value.
|
* of an array-like value.
|
||||||
*/
|
*/
|
||||||
var MAX_SAFE_INTEGER = 9007199254740991;
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
||||||
@@ -13,7 +16,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
|
|||||||
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
||||||
*/
|
*/
|
||||||
function isIndex(value, length) {
|
function isIndex(value, length) {
|
||||||
value = typeof value == 'number' ? value : parseFloat(value);
|
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
|
||||||
length = length == null ? MAX_SAFE_INTEGER : length;
|
length = length == null ? MAX_SAFE_INTEGER : length;
|
||||||
return value > -1 && value % 1 == 0 && value < length;
|
return value > -1 && value % 1 == 0 && value < length;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
||||||
* of an array-like value.
|
* of an array-like value.
|
||||||
*/
|
*/
|
||||||
var MAX_SAFE_INTEGER = 9007199254740991;
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
||||||
@@ -7,7 +7,7 @@ var MAX_SAFE_INTEGER = 9007199254740991;
|
|||||||
/**
|
/**
|
||||||
* Checks if `value` is a valid array-like length.
|
* Checks if `value` is a valid array-like length.
|
||||||
*
|
*
|
||||||
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {*} value The value to check.
|
* @param {*} value The value to check.
|
||||||
|
|||||||
@@ -10,17 +10,13 @@ var LazyWrapper = require('./LazyWrapper'),
|
|||||||
* @returns {Object} Returns the cloned `LazyWrapper` object.
|
* @returns {Object} Returns the cloned `LazyWrapper` object.
|
||||||
*/
|
*/
|
||||||
function lazyClone() {
|
function lazyClone() {
|
||||||
var actions = this.__actions__,
|
var result = new LazyWrapper(this.__wrapped__);
|
||||||
iteratees = this.__iteratees__,
|
result.__actions__ = arrayCopy(this.__actions__);
|
||||||
views = this.__views__,
|
|
||||||
result = new LazyWrapper(this.__wrapped__);
|
|
||||||
|
|
||||||
result.__actions__ = actions ? arrayCopy(actions) : null;
|
|
||||||
result.__dir__ = this.__dir__;
|
result.__dir__ = this.__dir__;
|
||||||
result.__filtered__ = this.__filtered__;
|
result.__filtered__ = this.__filtered__;
|
||||||
result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
|
result.__iteratees__ = arrayCopy(this.__iteratees__);
|
||||||
result.__takeCount__ = this.__takeCount__;
|
result.__takeCount__ = this.__takeCount__;
|
||||||
result.__views__ = views ? arrayCopy(views) : null;
|
result.__views__ = arrayCopy(this.__views__);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ var baseWrapperValue = require('./baseWrapperValue'),
|
|||||||
getView = require('./getView'),
|
getView = require('./getView'),
|
||||||
isArray = require('../lang/isArray');
|
isArray = require('../lang/isArray');
|
||||||
|
|
||||||
|
/** Used as the size to enable large array optimizations. */
|
||||||
|
var LARGE_ARRAY_SIZE = 200;
|
||||||
|
|
||||||
/** Used to indicate the type of lazy iteratees. */
|
/** Used to indicate the type of lazy iteratees. */
|
||||||
var LAZY_DROP_WHILE_FLAG = 0,
|
var LAZY_FILTER_FLAG = 1,
|
||||||
LAZY_FILTER_FLAG = 1,
|
|
||||||
LAZY_MAP_FLAG = 2;
|
LAZY_MAP_FLAG = 2;
|
||||||
|
|
||||||
/* 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. */
|
||||||
@@ -19,22 +21,25 @@ var nativeMin = Math.min;
|
|||||||
* @returns {*} Returns the unwrapped value.
|
* @returns {*} Returns the unwrapped value.
|
||||||
*/
|
*/
|
||||||
function lazyValue() {
|
function lazyValue() {
|
||||||
var array = this.__wrapped__.value();
|
var array = this.__wrapped__.value(),
|
||||||
if (!isArray(array)) {
|
dir = this.__dir__,
|
||||||
return baseWrapperValue(array, this.__actions__);
|
isArr = isArray(array),
|
||||||
}
|
|
||||||
var dir = this.__dir__,
|
|
||||||
isRight = dir < 0,
|
isRight = dir < 0,
|
||||||
view = getView(0, array.length, this.__views__),
|
arrLength = isArr ? array.length : 0,
|
||||||
|
view = getView(0, arrLength, this.__views__),
|
||||||
start = view.start,
|
start = view.start,
|
||||||
end = view.end,
|
end = view.end,
|
||||||
length = end - start,
|
length = end - start,
|
||||||
index = isRight ? end : (start - 1),
|
index = isRight ? end : (start - 1),
|
||||||
takeCount = nativeMin(length, this.__takeCount__),
|
|
||||||
iteratees = this.__iteratees__,
|
iteratees = this.__iteratees__,
|
||||||
iterLength = iteratees ? iteratees.length : 0,
|
iterLength = iteratees.length,
|
||||||
resIndex = 0,
|
resIndex = 0,
|
||||||
result = [];
|
takeCount = nativeMin(length, this.__takeCount__);
|
||||||
|
|
||||||
|
if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
|
||||||
|
return baseWrapperValue((isRight && isArr) ? array.reverse() : array, this.__actions__);
|
||||||
|
}
|
||||||
|
var result = [];
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
while (length-- && resIndex < takeCount) {
|
while (length-- && resIndex < takeCount) {
|
||||||
@@ -46,30 +51,16 @@ function lazyValue() {
|
|||||||
while (++iterIndex < iterLength) {
|
while (++iterIndex < iterLength) {
|
||||||
var data = iteratees[iterIndex],
|
var data = iteratees[iterIndex],
|
||||||
iteratee = data.iteratee,
|
iteratee = data.iteratee,
|
||||||
type = data.type;
|
type = data.type,
|
||||||
|
computed = iteratee(value);
|
||||||
|
|
||||||
if (type == LAZY_DROP_WHILE_FLAG) {
|
if (type == LAZY_MAP_FLAG) {
|
||||||
if (data.done && (isRight ? (index > data.index) : (index < data.index))) {
|
value = computed;
|
||||||
data.count = 0;
|
} else if (!computed) {
|
||||||
data.done = false;
|
if (type == LAZY_FILTER_FLAG) {
|
||||||
}
|
continue outer;
|
||||||
data.index = index;
|
} else {
|
||||||
if (!data.done) {
|
break outer;
|
||||||
var limit = data.limit;
|
|
||||||
if (!(data.done = limit > -1 ? (data.count++ >= limit) : !iteratee(value))) {
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var computed = iteratee(value);
|
|
||||||
if (type == LAZY_MAP_FLAG) {
|
|
||||||
value = computed;
|
|
||||||
} else if (!computed) {
|
|
||||||
if (type == LAZY_FILTER_FLAG) {
|
|
||||||
continue outer;
|
|
||||||
} else {
|
|
||||||
break outer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
internal/mergeDefaults.js
Normal file
15
internal/mergeDefaults.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
var merge = require('../object/merge');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by `_.defaultsDeep` to customize its `_.merge` use.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {*} objectValue The destination object property value.
|
||||||
|
* @param {*} sourceValue The source object property value.
|
||||||
|
* @returns {*} Returns the value to assign to the destination object.
|
||||||
|
*/
|
||||||
|
function mergeDefaults(objectValue, sourceValue) {
|
||||||
|
return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = mergeDefaults;
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
var baseForIn = require('./baseForIn'),
|
|
||||||
isObjectLike = require('./isObjectLike');
|
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
|
||||||
var objectTag = '[object Object]';
|
|
||||||
|
|
||||||
/** Used for native method references. */
|
|
||||||
var objectProto = Object.prototype;
|
|
||||||
|
|
||||||
/** Used to check objects for own properties. */
|
|
||||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
|
||||||
* of values.
|
|
||||||
*/
|
|
||||||
var objToString = objectProto.toString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A fallback implementation of `_.isPlainObject` which checks if `value`
|
|
||||||
* is an object created by the `Object` constructor or has a `[[Prototype]]`
|
|
||||||
* of `null`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {*} value The value to check.
|
|
||||||
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
|
|
||||||
*/
|
|
||||||
function shimIsPlainObject(value) {
|
|
||||||
var Ctor;
|
|
||||||
|
|
||||||
// Exit early for non `Object` objects.
|
|
||||||
if (!(isObjectLike(value) && objToString.call(value) == objectTag) ||
|
|
||||||
(!hasOwnProperty.call(value, 'constructor') &&
|
|
||||||
(Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// IE < 9 iterates inherited properties before own properties. If the first
|
|
||||||
// iterated property is an object's own property then there are no inherited
|
|
||||||
// enumerable properties.
|
|
||||||
var result;
|
|
||||||
// In most environments an object's own properties are iterated before
|
|
||||||
// its inherited properties. If the last iterated property is an object's
|
|
||||||
// own property then there are no inherited enumerable properties.
|
|
||||||
baseForIn(value, function(subValue, key) {
|
|
||||||
result = key;
|
|
||||||
});
|
|
||||||
return result === undefined || hasOwnProperty.call(value, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = shimIsPlainObject;
|
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
var isArrayLike = require('../internal/isArrayLike'),
|
var isArrayLike = require('../internal/isArrayLike'),
|
||||||
isObjectLike = require('../internal/isObjectLike');
|
isObjectLike = require('../internal/isObjectLike');
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
|
||||||
var argsTag = '[object Arguments]';
|
|
||||||
|
|
||||||
/** Used for native method references. */
|
/** Used for native method references. */
|
||||||
var objectProto = Object.prototype;
|
var objectProto = Object.prototype;
|
||||||
|
|
||||||
/**
|
/** Used to check objects for own properties. */
|
||||||
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||||
* of values.
|
|
||||||
*/
|
/** Native method references. */
|
||||||
var objToString = objectProto.toString;
|
var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is classified as an `arguments` object.
|
* Checks if `value` is classified as an `arguments` object.
|
||||||
@@ -30,7 +27,8 @@ var objToString = objectProto.toString;
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isArguments(value) {
|
function isArguments(value) {
|
||||||
return isObjectLike(value) && isArrayLike(value) && objToString.call(value) == argsTag;
|
return isObjectLike(value) && isArrayLike(value) &&
|
||||||
|
hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = isArguments;
|
module.exports = isArguments;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ var arrayTag = '[object Array]';
|
|||||||
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;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var boolTag = '[object Boolean]';
|
|||||||
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;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var dateTag = '[object Date]';
|
|||||||
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;
|
||||||
|
|||||||
@@ -1,15 +1,5 @@
|
|||||||
var isObjectLike = require('../internal/isObjectLike'),
|
var isObjectLike = require('../internal/isObjectLike'),
|
||||||
isPlainObject = require('./isPlainObject'),
|
isPlainObject = require('./isPlainObject');
|
||||||
support = require('../support');
|
|
||||||
|
|
||||||
/** Used for native method references. */
|
|
||||||
var objectProto = Object.prototype;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
|
||||||
* of values.
|
|
||||||
*/
|
|
||||||
var objToString = objectProto.toString;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is a DOM element.
|
* Checks if `value` is a DOM element.
|
||||||
@@ -28,14 +18,7 @@ var objToString = objectProto.toString;
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isElement(value) {
|
function isElement(value) {
|
||||||
return !!value && value.nodeType === 1 && isObjectLike(value) &&
|
return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
|
||||||
(objToString.call(value).indexOf('Element') > -1);
|
|
||||||
}
|
|
||||||
// Fallback for environments without DOM support.
|
|
||||||
if (!support.dom) {
|
|
||||||
isElement = function(value) {
|
|
||||||
return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = isElement;
|
module.exports = isElement;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var errorTag = '[object Error]';
|
|||||||
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;
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
var getNative = require('../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 nativeIsFinite = global.isFinite,
|
var nativeIsFinite = global.isFinite;
|
||||||
nativeNumIsFinite = getNative(Number, 'isFinite');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is a finite primitive number.
|
* Checks if `value` is a finite primitive number.
|
||||||
*
|
*
|
||||||
* **Note:** This method is based on [`Number.isFinite`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite).
|
* **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -31,8 +28,8 @@ var nativeIsFinite = global.isFinite,
|
|||||||
* _.isFinite(Infinity);
|
* _.isFinite(Infinity);
|
||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
var isFinite = nativeNumIsFinite || function(value) {
|
function isFinite(value) {
|
||||||
return typeof value == 'number' && nativeIsFinite(value);
|
return typeof value == 'number' && nativeIsFinite(value);
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = isFinite;
|
module.exports = isFinite;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
var baseIsFunction = require('../internal/baseIsFunction'),
|
var isObject = require('./isObject');
|
||||||
getNative = require('../internal/getNative');
|
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
/** `Object#toString` result references. */
|
||||||
var funcTag = '[object Function]';
|
var funcTag = '[object Function]';
|
||||||
@@ -8,14 +7,11 @@ var funcTag = '[object Function]';
|
|||||||
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;
|
||||||
|
|
||||||
/** Native method references. */
|
|
||||||
var Uint8Array = getNative(global, 'Uint8Array');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is classified as a `Function` object.
|
* Checks if `value` is classified as a `Function` object.
|
||||||
*
|
*
|
||||||
@@ -32,11 +28,11 @@ var Uint8Array = getNative(global, 'Uint8Array');
|
|||||||
* _.isFunction(/abc/);
|
* _.isFunction(/abc/);
|
||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
|
function isFunction(value) {
|
||||||
// The use of `Object#toString` avoids issues with the `typeof` operator
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
||||||
// in older versions of Chrome and Safari which return 'function' for regexes
|
// in older versions of Chrome and Safari which return 'function' for regexes
|
||||||
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
||||||
return objToString.call(value) == funcTag;
|
return isObject(value) && objToString.call(value) == funcTag;
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = isFunction;
|
module.exports = isFunction;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
var escapeRegExp = require('../string/escapeRegExp'),
|
var isFunction = require('./isFunction'),
|
||||||
isObjectLike = require('../internal/isObjectLike');
|
isObjectLike = require('../internal/isObjectLike');
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
|
||||||
var funcTag = '[object Function]';
|
|
||||||
|
|
||||||
/** Used to detect host constructors (Safari > 5). */
|
/** Used to detect host constructors (Safari > 5). */
|
||||||
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
||||||
|
|
||||||
@@ -16,15 +13,9 @@ var fnToString = Function.prototype.toString;
|
|||||||
/** Used to check objects for own properties. */
|
/** Used to check objects for own properties. */
|
||||||
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)
|
|
||||||
* of values.
|
|
||||||
*/
|
|
||||||
var objToString = objectProto.toString;
|
|
||||||
|
|
||||||
/** Used to detect if a method is native. */
|
/** Used to detect if a method is native. */
|
||||||
var reIsNative = RegExp('^' +
|
var reIsNative = RegExp('^' +
|
||||||
escapeRegExp(fnToString.call(hasOwnProperty))
|
fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
|
||||||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -48,7 +39,7 @@ function isNative(value) {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (objToString.call(value) == funcTag) {
|
if (isFunction(value)) {
|
||||||
return reIsNative.test(fnToString.call(value));
|
return reIsNative.test(fnToString.call(value));
|
||||||
}
|
}
|
||||||
return isObjectLike(value) && reIsHostCtor.test(value);
|
return isObjectLike(value) && reIsHostCtor.test(value);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var numberTag = '[object Number]';
|
|||||||
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;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var getNative = require('../internal/getNative'),
|
var baseForIn = require('../internal/baseForIn'),
|
||||||
shimIsPlainObject = require('../internal/shimIsPlainObject');
|
isArguments = require('./isArguments'),
|
||||||
|
isObjectLike = require('../internal/isObjectLike');
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
/** `Object#toString` result references. */
|
||||||
var objectTag = '[object Object]';
|
var objectTag = '[object Object]';
|
||||||
@@ -7,15 +8,15 @@ var objectTag = '[object Object]';
|
|||||||
/** Used for native method references. */
|
/** Used for native method references. */
|
||||||
var objectProto = Object.prototype;
|
var objectProto = Object.prototype;
|
||||||
|
|
||||||
|
/** Used to check objects for own properties. */
|
||||||
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
* 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;
|
||||||
|
|
||||||
/** Native method references. */
|
|
||||||
var getPrototypeOf = getNative(Object, 'getPrototypeOf');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is a plain object, that is, an object created by the
|
* Checks if `value` is a plain object, that is, an object created by the
|
||||||
* `Object` constructor or one with a `[[Prototype]]` of `null`.
|
* `Object` constructor or one with a `[[Prototype]]` of `null`.
|
||||||
@@ -46,16 +47,25 @@ var getPrototypeOf = getNative(Object, 'getPrototypeOf');
|
|||||||
* _.isPlainObject(Object.create(null));
|
* _.isPlainObject(Object.create(null));
|
||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
|
function isPlainObject(value) {
|
||||||
if (!(value && objToString.call(value) == objectTag)) {
|
var Ctor;
|
||||||
|
|
||||||
|
// Exit early for non `Object` objects.
|
||||||
|
if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
|
||||||
|
(!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var valueOf = getNative(value, 'valueOf'),
|
// IE < 9 iterates inherited properties before own properties. If the first
|
||||||
objProto = valueOf && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
// iterated property is an object's own property then there are no inherited
|
||||||
|
// enumerable properties.
|
||||||
return objProto
|
var result;
|
||||||
? (value == objProto || getPrototypeOf(value) == objProto)
|
// In most environments an object's own properties are iterated before
|
||||||
: shimIsPlainObject(value);
|
// its inherited properties. If the last iterated property is an object's
|
||||||
};
|
// own property then there are no inherited enumerable properties.
|
||||||
|
baseForIn(value, function(subValue, key) {
|
||||||
|
result = key;
|
||||||
|
});
|
||||||
|
return result === undefined || hasOwnProperty.call(value, result);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = isPlainObject;
|
module.exports = isPlainObject;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var isObjectLike = require('../internal/isObjectLike');
|
var isObject = require('./isObject');
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
/** `Object#toString` result references. */
|
||||||
var regexpTag = '[object RegExp]';
|
var regexpTag = '[object RegExp]';
|
||||||
@@ -7,7 +7,7 @@ var regexpTag = '[object RegExp]';
|
|||||||
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;
|
||||||
@@ -29,7 +29,7 @@ var objToString = objectProto.toString;
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isRegExp(value) {
|
function isRegExp(value) {
|
||||||
return isObjectLike(value) && objToString.call(value) == regexpTag;
|
return isObject(value) && objToString.call(value) == regexpTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = isRegExp;
|
module.exports = isRegExp;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var stringTag = '[object String]';
|
|||||||
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;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ typedArrayTags[stringTag] = typedArrayTags[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;
|
||||||
|
|||||||
3
math.js
3
math.js
@@ -1,6 +1,9 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
'add': require('./math/add'),
|
'add': require('./math/add'),
|
||||||
|
'ceil': require('./math/ceil'),
|
||||||
|
'floor': require('./math/floor'),
|
||||||
'max': require('./math/max'),
|
'max': require('./math/max'),
|
||||||
'min': require('./math/min'),
|
'min': require('./math/min'),
|
||||||
|
'round': require('./math/round'),
|
||||||
'sum': require('./math/sum')
|
'sum': require('./math/sum')
|
||||||
};
|
};
|
||||||
|
|||||||
25
math/ceil.js
Normal file
25
math/ceil.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
var createRound = require('../internal/createRound');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates `n` rounded up to `precision`.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Math
|
||||||
|
* @param {number} n The number to round up.
|
||||||
|
* @param {number} [precision=0] The precision to round up to.
|
||||||
|
* @returns {number} Returns the rounded up number.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _.ceil(4.006);
|
||||||
|
* // => 5
|
||||||
|
*
|
||||||
|
* _.ceil(6.004, 2);
|
||||||
|
* // => 6.01
|
||||||
|
*
|
||||||
|
* _.ceil(6040, -2);
|
||||||
|
* // => 6100
|
||||||
|
*/
|
||||||
|
var ceil = createRound('ceil');
|
||||||
|
|
||||||
|
module.exports = ceil;
|
||||||
25
math/floor.js
Normal file
25
math/floor.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
var createRound = require('../internal/createRound');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates `n` rounded down to `precision`.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Math
|
||||||
|
* @param {number} n The number to round down.
|
||||||
|
* @param {number} [precision=0] The precision to round down to.
|
||||||
|
* @returns {number} Returns the rounded down number.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _.floor(4.006);
|
||||||
|
* // => 4
|
||||||
|
*
|
||||||
|
* _.floor(0.046, 2);
|
||||||
|
* // => 0.04
|
||||||
|
*
|
||||||
|
* _.floor(4060, -2);
|
||||||
|
* // => 4000
|
||||||
|
*/
|
||||||
|
var floor = createRound('floor');
|
||||||
|
|
||||||
|
module.exports = floor;
|
||||||
25
math/round.js
Normal file
25
math/round.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
var createRound = require('../internal/createRound');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates `n` rounded to `precision`.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Math
|
||||||
|
* @param {number} n The number to round.
|
||||||
|
* @param {number} [precision=0] The precision to round to.
|
||||||
|
* @returns {number} Returns the rounded number.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _.round(4.006);
|
||||||
|
* // => 4
|
||||||
|
*
|
||||||
|
* _.round(4.006, 2);
|
||||||
|
* // => 4.01
|
||||||
|
*
|
||||||
|
* _.round(4060, -2);
|
||||||
|
* // => 4100
|
||||||
|
*/
|
||||||
|
var round = createRound('round');
|
||||||
|
|
||||||
|
module.exports = round;
|
||||||
10
math/sum.js
10
math/sum.js
@@ -39,13 +39,11 @@ var arraySum = require('../internal/arraySum'),
|
|||||||
*/
|
*/
|
||||||
function sum(collection, iteratee, thisArg) {
|
function sum(collection, iteratee, thisArg) {
|
||||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||||
iteratee = null;
|
iteratee = undefined;
|
||||||
}
|
}
|
||||||
var noIteratee = iteratee == null;
|
iteratee = baseCallback(iteratee, thisArg, 3);
|
||||||
|
return iteratee.length == 1
|
||||||
iteratee = noIteratee ? iteratee : baseCallback(iteratee, thisArg, 3);
|
? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
|
||||||
return noIteratee
|
|
||||||
? arraySum(isArray(collection) ? collection : toIterable(collection))
|
|
||||||
: baseSum(collection, iteratee);
|
: baseSum(collection, iteratee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ var nativeMax = Math.max,
|
|||||||
*/
|
*/
|
||||||
function inRange(value, start, end) {
|
function inRange(value, start, end) {
|
||||||
start = +start || 0;
|
start = +start || 0;
|
||||||
if (typeof end === 'undefined') {
|
if (end === undefined) {
|
||||||
end = start;
|
end = start;
|
||||||
start = 0;
|
start = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ var nativeMin = Math.min,
|
|||||||
*/
|
*/
|
||||||
function random(min, max, floating) {
|
function random(min, max, floating) {
|
||||||
if (floating && isIterateeCall(min, max, floating)) {
|
if (floating && isIterateeCall(min, max, floating)) {
|
||||||
max = floating = null;
|
max = floating = undefined;
|
||||||
}
|
}
|
||||||
var noMin = min == null,
|
var noMin = min == null,
|
||||||
noMax = max == null;
|
noMax = max == null;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user