mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 14:37:49 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53c14e5b9b | ||
|
|
863bb301bb | ||
|
|
d58549ce0b |
27
README.md
27
README.md
@@ -1,4 +1,4 @@
|
||||
# lodash v3.5.0
|
||||
# lodash v3.8.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.
|
||||
|
||||
@@ -28,7 +28,7 @@ var array = require('lodash/array');
|
||||
var chunk = require('lodash/array/chunk');
|
||||
```
|
||||
|
||||
See the [package source](https://github.com/lodash/lodash/tree/3.5.0-npm) for more details.
|
||||
See the [package source](https://github.com/lodash/lodash/tree/3.8.0-npm) for more details.
|
||||
|
||||
**Note:**<br>
|
||||
Don’t assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br>
|
||||
@@ -39,8 +39,8 @@ 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.
|
||||
|
||||
* 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.5.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.5.0-amd) builds
|
||||
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.5.0-es) build
|
||||
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.8.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.8.0-amd) builds
|
||||
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.8.0-es) build
|
||||
|
||||
## Further Reading
|
||||
|
||||
@@ -51,7 +51,7 @@ lodash is also available in a variety of other builds & module formats.
|
||||
* [Roadmap](https://github.com/lodash/lodash/wiki/Roadmap)
|
||||
* [More Resources](https://github.com/lodash/lodash/wiki/Resources)
|
||||
|
||||
## Features *not* in Underscore
|
||||
## Features
|
||||
|
||||
* ~100% [code coverage](https://coveralls.io/r/lodash)
|
||||
* Follows [semantic versioning](http://semver.org/) for releases
|
||||
@@ -66,7 +66,6 @@ lodash is also available in a variety of other builds & module formats.
|
||||
* [_.chunk](https://lodash.com/docs#chunk) for splitting an array into chunks of a given size
|
||||
* [_.clone](https://lodash.com/docs#clone) supports shallow cloning of `Date` & `RegExp` objects
|
||||
* [_.cloneDeep](https://lodash.com/docs#cloneDeep) for deep cloning arrays & objects
|
||||
* [_.create](https://lodash.com/docs#create) for easier object inheritance
|
||||
* [_.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
|
||||
* [_.fill](https://lodash.com/docs#fill) to fill arrays with values
|
||||
@@ -75,24 +74,28 @@ lodash is also available in a variety of other builds & module formats.
|
||||
* [_.forEach](https://lodash.com/docs#forEach) supports exiting early
|
||||
* [_.forIn](https://lodash.com/docs#forIn) for iterating all enumerable properties
|
||||
* [_.forOwn](https://lodash.com/docs#forOwn) for iterating own properties
|
||||
* [_.get](https://lodash.com/docs#get) & [_.set](https://lodash.com/docs#set) for deep property getting & setting
|
||||
* [_.inRange](https://lodash.com/docs#inRange) for checking whether a number is within a given range
|
||||
* [_.isNative](https://lodash.com/docs#isNative) to check for native functions
|
||||
* [_.isPlainObject](https://lodash.com/docs#isPlainObject) & [_.toPlainObject](https://lodash.com/docs#toPlainObject) to check for & convert to `Object` objects
|
||||
* [_.isTypedArray](https://lodash.com/docs#isTypedArray) to check for typed arrays
|
||||
* [_.mapKeys](https://lodash.com/docs#mapKeys) for mapping keys to an object
|
||||
* [_.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)
|
||||
* [_.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)
|
||||
* [_.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
|
||||
* [_.random](https://lodash.com/docs#random) supports returning floating-point numbers
|
||||
* [_.restParam](https://lodash.com/docs#restParam) & [_.spread](https://lodash.com/docs#spread) for applying rest parameters & spreading arguments to functions
|
||||
* [_.runInContext](https://lodash.com/docs#runInContext) for collisionless mixins & easier mocking
|
||||
* [_.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
|
||||
* [_.spread](https://lodash.com/docs#spread) for creating a function to spread an array of arguments to another
|
||||
* [_.sum](https://lodash.com/docs#sum) to get the sum of values
|
||||
* [_.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)
|
||||
* [_.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
|
||||
* [_.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
|
||||
* [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), &
|
||||
@@ -100,17 +103,17 @@ lodash is also available in a variety of other builds & module formats.
|
||||
* [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), &
|
||||
[more](https://lodash.com/docs "_.camelCase, _.deburr, _.endsWith, _.escapeRegExp, _.kebabCase, _.pad, _.padLeft, _.padRight, _.repeat, _.snakeCase, _.startCase, _.startsWith, _.trimLeft, _.trimRight, _.trunc, _.words") string methods
|
||||
* [_.clone](https://lodash.com/docs#clone), [_.isEqual](https://lodash.com/docs#isEqual), &
|
||||
[more](https://lodash.com/docs "_.assign, _.cloneDeep, _.merge") accept callbacks
|
||||
[more](https://lodash.com/docs "_.assign, _.cloneDeep, _.merge") accept customizer callbacks
|
||||
* [_.dropWhile](https://lodash.com/docs#dropWhile), [_.takeWhile](https://lodash.com/docs#takeWhile), &
|
||||
[more](https://lodash.com/docs "_.drop, _.dropRightWhile, _.take, _.takeRightWhile") to complement [_.first](https://lodash.com/docs#first), [_.initial](https://lodash.com/docs#initial), [_.last](https://lodash.com/docs#last), & [_.rest](https://lodash.com/docs#rest)
|
||||
[more](https://lodash.com/docs "_.drop, _.dropRight, _.dropRightWhile, _.take, _.takeRight, _.takeRightWhile") to complement [_.first](https://lodash.com/docs#first), [_.initial](https://lodash.com/docs#initial), [_.last](https://lodash.com/docs#last), & [_.rest](https://lodash.com/docs#rest)
|
||||
* [_.findLast](https://lodash.com/docs#findLast), [_.findLastKey](https://lodash.com/docs#findLastKey), &
|
||||
[more](https://lodash.com/docs "_.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.partialRight") right-associative methods
|
||||
[more](https://lodash.com/docs "_.curryRight, _.dropRight, _.dropRightWhile, _.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.padRight, partialRight, _.takeRight, _.trimRight, _.takeRightWhile") right-associative methods
|
||||
* [_.includes](https://lodash.com/docs#includes), [_.toArray](https://lodash.com/docs#toArray), &
|
||||
[more](https://lodash.com/docs "_.at, _.countBy, _.every, _.filter, _.find, _.findLast, _.forEach, _.forEachRight, _.groupBy, _.indexBy, _.invoke, _.map, _.max, _.min, _.partition, _.pluck, _.reduce, _.reduceRight, _.reject, _.shuffle, _.size, _.some, _.sortBy") accept strings
|
||||
[more](https://lodash.com/docs "_.at, _.countBy, _.every, _.filter, _.find, _.findLast, _.findWhere, _.forEach, _.forEachRight, _.groupBy, _.indexBy, _.invoke, _.map, _.max, _.min, _.partition, _.pluck, _.reduce, _.reduceRight, _.reject, _.shuffle, _.size, _.some, _.sortBy, _.sortByAll, _.sortByOrder, _.sum, _.where") accept strings
|
||||
* [_#commit](https://lodash.com/docs#prototype-commit) & [_#plant](https://lodash.com/docs#prototype-plant) for working with chain sequences
|
||||
* [_#thru](https://lodash.com/docs#thru) to pass values thru a chain sequence
|
||||
|
||||
## Support
|
||||
|
||||
Tested in Chrome 40-41, Firefox 35-36, IE 6-11, Opera 26-27, Safari 5-8, io.js 1.5.0, Node.js 0.8.28, 0.10.36, & 0.12.0, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5.
|
||||
Tested in Chrome 41-42, Firefox 36-37, IE 6-11, MS Edge, Opera 27-28, Safari 5-8, io.js 1.8.1, Node.js 0.8.28, 0.10.38, & 0.12.2, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5.
|
||||
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.
|
||||
|
||||
4
array.js
4
array.js
@@ -35,8 +35,10 @@ module.exports = {
|
||||
'uniq': require('./array/uniq'),
|
||||
'unique': require('./array/unique'),
|
||||
'unzip': require('./array/unzip'),
|
||||
'unzipWith': require('./array/unzipWith'),
|
||||
'without': require('./array/without'),
|
||||
'xor': require('./array/xor'),
|
||||
'zip': require('./array/zip'),
|
||||
'zipObject': require('./array/zipObject')
|
||||
'zipObject': require('./array/zipObject'),
|
||||
'zipWith': require('./array/zipWith')
|
||||
};
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
var baseDifference = require('../internal/baseDifference'),
|
||||
baseFlatten = require('../internal/baseFlatten'),
|
||||
isArguments = require('../lang/isArguments'),
|
||||
isArray = require('../lang/isArray');
|
||||
isArrayLike = require('../internal/isArrayLike'),
|
||||
restParam = require('../function/restParam');
|
||||
|
||||
/**
|
||||
* Creates an array excluding all values of the provided arrays using
|
||||
* `SameValueZero` for equality comparisons.
|
||||
*
|
||||
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
|
||||
* e.g. `===`, except that `NaN` matches `NaN`. See the
|
||||
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for more details.
|
||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for equality comparisons.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -23,18 +19,10 @@ var baseDifference = require('../internal/baseDifference'),
|
||||
* _.difference([1, 2, 3], [4, 2]);
|
||||
* // => [1, 3]
|
||||
*/
|
||||
function difference() {
|
||||
var args = arguments,
|
||||
index = -1,
|
||||
length = args.length;
|
||||
|
||||
while (++index < length) {
|
||||
var value = args[index];
|
||||
if (isArray(value) || isArguments(value)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return baseDifference(value, baseFlatten(args, false, true, ++index));
|
||||
}
|
||||
var difference = restParam(function(array, values) {
|
||||
return isArrayLike(array)
|
||||
? baseDifference(array, baseFlatten(values, false, true))
|
||||
: [];
|
||||
});
|
||||
|
||||
module.exports = difference;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
baseSlice = require('../internal/baseSlice');
|
||||
baseWhile = require('../internal/baseWhile');
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` excluding elements dropped from the end.
|
||||
* Elements are dropped until `predicate` returns falsey. The predicate is
|
||||
* bound to `thisArg` and invoked with three arguments; (value, index, array).
|
||||
* bound to `thisArg` and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
@@ -51,13 +51,9 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* // => ['barney', 'fred', 'pebbles']
|
||||
*/
|
||||
function dropRightWhile(array, predicate, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
while (length-- && predicate(array[length], length, array)) {}
|
||||
return baseSlice(array, 0, length + 1);
|
||||
return (array && array.length)
|
||||
? baseWhile(array, baseCallback(predicate, thisArg, 3), true, true)
|
||||
: [];
|
||||
}
|
||||
|
||||
module.exports = dropRightWhile;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
baseSlice = require('../internal/baseSlice');
|
||||
baseWhile = require('../internal/baseWhile');
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` excluding elements dropped from the beginning.
|
||||
* Elements are dropped until `predicate` returns falsey. The predicate is
|
||||
* bound to `thisArg` and invoked with three arguments; (value, index, array).
|
||||
* bound to `thisArg` and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
@@ -51,14 +51,9 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* // => ['barney', 'fred', 'pebbles']
|
||||
*/
|
||||
function dropWhile(array, predicate, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
var index = -1;
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
while (++index < length && predicate(array[index], index, array)) {}
|
||||
return baseSlice(array, index);
|
||||
return (array && array.length)
|
||||
? baseWhile(array, baseCallback(predicate, thisArg, 3), true)
|
||||
: [];
|
||||
}
|
||||
|
||||
module.exports = dropWhile;
|
||||
|
||||
@@ -15,6 +15,19 @@ var baseFill = require('../internal/baseFill'),
|
||||
* @param {number} [start=0] The start position.
|
||||
* @param {number} [end=array.length] The end position.
|
||||
* @returns {Array} Returns `array`.
|
||||
* @example
|
||||
*
|
||||
* var array = [1, 2, 3];
|
||||
*
|
||||
* _.fill(array, 'a');
|
||||
* console.log(array);
|
||||
* // => ['a', 'a', 'a']
|
||||
*
|
||||
* _.fill(Array(3), 2);
|
||||
* // => [2, 2, 2]
|
||||
*
|
||||
* _.fill([4, 6, 8], '*', 1, 2);
|
||||
* // => [4, '*', 8]
|
||||
*/
|
||||
function fill(array, value, start, end) {
|
||||
var length = array ? array.length : 0;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var baseCallback = require('../internal/baseCallback');
|
||||
var createFindIndex = require('../internal/createFindIndex');
|
||||
|
||||
/**
|
||||
* This method is like `_.find` except that it returns the index of the first
|
||||
* element `predicate` returns truthy for, instead of the element itself.
|
||||
* element `predicate` returns truthy for instead of the element itself.
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
@@ -48,17 +48,6 @@ var baseCallback = require('../internal/baseCallback');
|
||||
* _.findIndex(users, 'active');
|
||||
* // => 2
|
||||
*/
|
||||
function findIndex(array, predicate, thisArg) {
|
||||
var index = -1,
|
||||
length = array ? array.length : 0;
|
||||
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
while (++index < length) {
|
||||
if (predicate(array[index], index, array)) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
var findIndex = createFindIndex();
|
||||
|
||||
module.exports = findIndex;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var baseCallback = require('../internal/baseCallback');
|
||||
var createFindIndex = require('../internal/createFindIndex');
|
||||
|
||||
/**
|
||||
* This method is like `_.findIndex` except that it iterates over elements
|
||||
@@ -48,15 +48,6 @@ var baseCallback = require('../internal/baseCallback');
|
||||
* _.findLastIndex(users, 'active');
|
||||
* // => 0
|
||||
*/
|
||||
function findLastIndex(array, predicate, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
while (length--) {
|
||||
if (predicate(array[length], length, array)) {
|
||||
return length;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
var findLastIndex = createFindIndex(true);
|
||||
|
||||
module.exports = findLastIndex;
|
||||
|
||||
@@ -15,18 +15,18 @@ var baseFlatten = require('../internal/baseFlatten'),
|
||||
* @example
|
||||
*
|
||||
* _.flatten([1, [2, 3, [4]]]);
|
||||
* // => [1, 2, 3, [4]];
|
||||
* // => [1, 2, 3, [4]]
|
||||
*
|
||||
* // using `isDeep`
|
||||
* _.flatten([1, [2, 3, [4]]], true);
|
||||
* // => [1, 2, 3, 4];
|
||||
* // => [1, 2, 3, 4]
|
||||
*/
|
||||
function flatten(array, isDeep, guard) {
|
||||
var length = array ? array.length : 0;
|
||||
if (guard && isIterateeCall(array, isDeep, guard)) {
|
||||
isDeep = false;
|
||||
}
|
||||
return length ? baseFlatten(array, isDeep, false, 0) : [];
|
||||
return length ? baseFlatten(array, isDeep) : [];
|
||||
}
|
||||
|
||||
module.exports = flatten;
|
||||
|
||||
@@ -11,11 +11,11 @@ var baseFlatten = require('../internal/baseFlatten');
|
||||
* @example
|
||||
*
|
||||
* _.flattenDeep([1, [2, 3, [4]]]);
|
||||
* // => [1, 2, 3, 4];
|
||||
* // => [1, 2, 3, 4]
|
||||
*/
|
||||
function flattenDeep(array) {
|
||||
var length = array ? array.length : 0;
|
||||
return length ? baseFlatten(array, true, false, 0) : [];
|
||||
return length ? baseFlatten(array, true) : [];
|
||||
}
|
||||
|
||||
module.exports = flattenDeep;
|
||||
|
||||
@@ -6,14 +6,10 @@ var nativeMax = Math.max;
|
||||
|
||||
/**
|
||||
* Gets the index at which the first occurrence of `value` is found in `array`
|
||||
* using `SameValueZero` for equality comparisons. If `fromIndex` is negative,
|
||||
* it is used as the offset from the end of `array`. If `array` is sorted
|
||||
* providing `true` for `fromIndex` performs a faster binary search.
|
||||
*
|
||||
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
|
||||
* e.g. `===`, except that `NaN` matches `NaN`. See the
|
||||
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for more details.
|
||||
* using [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
|
||||
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
|
||||
* performs a faster binary search.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
var baseIndexOf = require('../internal/baseIndexOf'),
|
||||
cacheIndexOf = require('../internal/cacheIndexOf'),
|
||||
createCache = require('../internal/createCache'),
|
||||
isArguments = require('../lang/isArguments'),
|
||||
isArray = require('../lang/isArray');
|
||||
isArrayLike = require('../internal/isArrayLike');
|
||||
|
||||
/**
|
||||
* Creates an array of unique values in all provided arrays using `SameValueZero`
|
||||
* Creates an array of unique values in all provided arrays using
|
||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for equality comparisons.
|
||||
*
|
||||
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
|
||||
* e.g. `===`, except that `NaN` matches `NaN`. See the
|
||||
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for more details.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Array
|
||||
@@ -28,20 +23,23 @@ function intersection() {
|
||||
argsLength = arguments.length,
|
||||
caches = [],
|
||||
indexOf = baseIndexOf,
|
||||
isCommon = true;
|
||||
isCommon = true,
|
||||
result = [];
|
||||
|
||||
while (++argsIndex < argsLength) {
|
||||
var value = arguments[argsIndex];
|
||||
if (isArray(value) || isArguments(value)) {
|
||||
if (isArrayLike(value)) {
|
||||
args.push(value);
|
||||
caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null);
|
||||
}
|
||||
}
|
||||
argsLength = args.length;
|
||||
if (argsLength < 2) {
|
||||
return result;
|
||||
}
|
||||
var array = args[0],
|
||||
index = -1,
|
||||
length = array ? array.length : 0,
|
||||
result = [],
|
||||
seen = caches[0];
|
||||
|
||||
outer:
|
||||
|
||||
@@ -7,14 +7,11 @@ var arrayProto = Array.prototype;
|
||||
var splice = arrayProto.splice;
|
||||
|
||||
/**
|
||||
* Removes all provided values from `array` using `SameValueZero` for equality
|
||||
* comparisons.
|
||||
* Removes all provided values from `array` using
|
||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for equality comparisons.
|
||||
*
|
||||
* **Notes:**
|
||||
* - Unlike `_.without`, this method mutates `array`.
|
||||
* - `SameValueZero` comparisons are like strict equality comparisons, e.g. `===`,
|
||||
* except that `NaN` matches `NaN`. See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for more details.
|
||||
* **Note:** Unlike `_.without`, this method mutates `array`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
var baseFlatten = require('../internal/baseFlatten'),
|
||||
basePullAt = require('../internal/basePullAt');
|
||||
var baseAt = require('../internal/baseAt'),
|
||||
baseCompareAscending = require('../internal/baseCompareAscending'),
|
||||
baseFlatten = require('../internal/baseFlatten'),
|
||||
basePullAt = require('../internal/basePullAt'),
|
||||
restParam = require('../function/restParam');
|
||||
|
||||
/**
|
||||
* Removes elements from `array` corresponding to the given indexes and returns
|
||||
@@ -26,8 +29,12 @@ var baseFlatten = require('../internal/baseFlatten'),
|
||||
* console.log(evens);
|
||||
* // => [10, 20]
|
||||
*/
|
||||
function pullAt(array) {
|
||||
return basePullAt(array || [], baseFlatten(arguments, false, false, 1));
|
||||
}
|
||||
var pullAt = restParam(function(array, indexes) {
|
||||
indexes = baseFlatten(indexes);
|
||||
|
||||
var result = baseAt(array, indexes);
|
||||
basePullAt(array, indexes.sort(baseCompareAscending));
|
||||
return result;
|
||||
});
|
||||
|
||||
module.exports = pullAt;
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
var baseCallback = require('../internal/baseCallback');
|
||||
|
||||
/** Used for native method references. */
|
||||
var arrayProto = Array.prototype;
|
||||
|
||||
/** Native method references. */
|
||||
var splice = arrayProto.splice;
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
basePullAt = require('../internal/basePullAt');
|
||||
|
||||
/**
|
||||
* Removes all elements from `array` that `predicate` returns truthy for
|
||||
* and returns an array of the removed elements. The predicate is bound to
|
||||
* `thisArg` and invoked with three arguments; (value, index, array).
|
||||
* `thisArg` and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
@@ -46,19 +41,23 @@ var splice = arrayProto.splice;
|
||||
* // => [2, 4]
|
||||
*/
|
||||
function remove(array, predicate, thisArg) {
|
||||
var result = [];
|
||||
if (!(array && array.length)) {
|
||||
return result;
|
||||
}
|
||||
var index = -1,
|
||||
length = array ? array.length : 0,
|
||||
result = [];
|
||||
indexes = [],
|
||||
length = array.length;
|
||||
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
while (++index < length) {
|
||||
var value = array[index];
|
||||
if (predicate(value, index, array)) {
|
||||
result.push(value);
|
||||
splice.call(array, index--, 1);
|
||||
length--;
|
||||
indexes.push(index);
|
||||
}
|
||||
}
|
||||
basePullAt(array, indexes);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ var baseSlice = require('../internal/baseSlice'),
|
||||
/**
|
||||
* Creates a slice of `array` from `start` up to, but not including, `end`.
|
||||
*
|
||||
* **Note:** This function is used instead of `Array#slice` to support node
|
||||
* **Note:** This method is used instead of `Array#slice` to support node
|
||||
* lists in IE < 9 and to ensure dense arrays are returned.
|
||||
*
|
||||
* @static
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
binaryIndex = require('../internal/binaryIndex'),
|
||||
binaryIndexBy = require('../internal/binaryIndexBy');
|
||||
var createSortedIndex = require('../internal/createSortedIndex');
|
||||
|
||||
/**
|
||||
* Uses a binary search to determine the lowest index at which `value` should
|
||||
@@ -9,14 +7,14 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* to compute their sort ranking. The iteratee is bound to `thisArg` and
|
||||
* invoked with one argument; (value).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* If a property name is provided for `iteratee` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
||||
* style callback returns `true` for elements that have a matching property
|
||||
* value, else `false`.
|
||||
*
|
||||
* If an object is provided for `predicate` the created `_.matches` style
|
||||
* If an object is provided for `iteratee` the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
@@ -50,10 +48,6 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
|
||||
* // => 1
|
||||
*/
|
||||
function sortedIndex(array, value, iteratee, thisArg) {
|
||||
return iteratee == null
|
||||
? binaryIndex(array, value)
|
||||
: binaryIndexBy(array, value, baseCallback(iteratee, thisArg, 1));
|
||||
}
|
||||
var sortedIndex = createSortedIndex();
|
||||
|
||||
module.exports = sortedIndex;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
binaryIndex = require('../internal/binaryIndex'),
|
||||
binaryIndexBy = require('../internal/binaryIndexBy');
|
||||
var createSortedIndex = require('../internal/createSortedIndex');
|
||||
|
||||
/**
|
||||
* This method is like `_.sortedIndex` except that it returns the highest
|
||||
@@ -22,10 +20,6 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* _.sortedLastIndex([4, 4, 5, 5], 5);
|
||||
* // => 4
|
||||
*/
|
||||
function sortedLastIndex(array, value, iteratee, thisArg) {
|
||||
return iteratee == null
|
||||
? binaryIndex(array, value, true)
|
||||
: binaryIndexBy(array, value, baseCallback(iteratee, thisArg, 1), true);
|
||||
}
|
||||
var sortedLastIndex = createSortedIndex(true);
|
||||
|
||||
module.exports = sortedLastIndex;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
baseSlice = require('../internal/baseSlice');
|
||||
baseWhile = require('../internal/baseWhile');
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` with elements taken from the end. Elements are
|
||||
* taken until `predicate` returns falsey. The predicate is bound to `thisArg`
|
||||
* and invoked with three arguments; (value, index, array).
|
||||
* and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
@@ -51,13 +51,9 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* // => []
|
||||
*/
|
||||
function takeRightWhile(array, predicate, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
while (length-- && predicate(array[length], length, array)) {}
|
||||
return baseSlice(array, length + 1);
|
||||
return (array && array.length)
|
||||
? baseWhile(array, baseCallback(predicate, thisArg, 3), false, true)
|
||||
: [];
|
||||
}
|
||||
|
||||
module.exports = takeRightWhile;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
baseSlice = require('../internal/baseSlice');
|
||||
baseWhile = require('../internal/baseWhile');
|
||||
|
||||
/**
|
||||
* Creates a slice of `array` with elements taken from the beginning. Elements
|
||||
* are taken until `predicate` returns falsey. The predicate is bound to
|
||||
* `thisArg` and invoked with three arguments; (value, index, array).
|
||||
* `thisArg` and invoked with three arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
@@ -51,14 +51,9 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* // => []
|
||||
*/
|
||||
function takeWhile(array, predicate, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
var index = -1;
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
while (++index < length && predicate(array[index], index, array)) {}
|
||||
return baseSlice(array, 0, index);
|
||||
return (array && array.length)
|
||||
? baseWhile(array, baseCallback(predicate, thisArg, 3))
|
||||
: [];
|
||||
}
|
||||
|
||||
module.exports = takeWhile;
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
var baseFlatten = require('../internal/baseFlatten'),
|
||||
baseUniq = require('../internal/baseUniq');
|
||||
baseUniq = require('../internal/baseUniq'),
|
||||
restParam = require('../function/restParam');
|
||||
|
||||
/**
|
||||
* Creates an array of unique values, in order, of the provided arrays using
|
||||
* `SameValueZero` for equality comparisons.
|
||||
*
|
||||
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
|
||||
* e.g. `===`, except that `NaN` matches `NaN`. See the
|
||||
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for more details.
|
||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for equality comparisons.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -20,8 +17,8 @@ var baseFlatten = require('../internal/baseFlatten'),
|
||||
* _.union([1, 2], [4, 2], [2, 1]);
|
||||
* // => [1, 2, 4]
|
||||
*/
|
||||
function union() {
|
||||
return baseUniq(baseFlatten(arguments, false, true, 0));
|
||||
}
|
||||
var union = restParam(function(arrays) {
|
||||
return baseUniq(baseFlatten(arrays, false, true));
|
||||
});
|
||||
|
||||
module.exports = union;
|
||||
|
||||
@@ -4,29 +4,26 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
sortedUniq = require('../internal/sortedUniq');
|
||||
|
||||
/**
|
||||
* Creates a duplicate-value-free version of an array using `SameValueZero`
|
||||
* for equality comparisons. Providing `true` for `isSorted` performs a faster
|
||||
* search algorithm for sorted arrays. If an iteratee function is provided it
|
||||
* is invoked for each value in the array to generate the criterion by which
|
||||
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
|
||||
* with three arguments; (value, index, array).
|
||||
* Creates a duplicate-free version of an array, using
|
||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for equality comparisons, in which only the first occurence of each element
|
||||
* is kept. Providing `true` for `isSorted` performs a faster search algorithm
|
||||
* for sorted arrays. If an iteratee function is provided it is invoked for
|
||||
* each element in the array to generate the criterion by which uniqueness
|
||||
* is computed. The `iteratee` is bound to `thisArg` and invoked with three
|
||||
* arguments: (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* If a property name is provided for `iteratee` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
||||
* style callback returns `true` for elements that have a matching property
|
||||
* value, else `false`.
|
||||
*
|
||||
* If an object is provided for `predicate` the created `_.matches` style
|
||||
* If an object is provided for `iteratee` the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
|
||||
* e.g. `===`, except that `NaN` matches `NaN`. See the
|
||||
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for more details.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @alias unique
|
||||
@@ -38,8 +35,8 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* @returns {Array} Returns the new duplicate-value-free array.
|
||||
* @example
|
||||
*
|
||||
* _.uniq([1, 2, 1]);
|
||||
* // => [1, 2]
|
||||
* _.uniq([2, 1, 2]);
|
||||
* // => [2, 1]
|
||||
*
|
||||
* // using `isSorted`
|
||||
* _.uniq([1, 1, 2], true);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
var arrayMap = require('../internal/arrayMap'),
|
||||
arrayMax = require('../internal/arrayMax'),
|
||||
baseProperty = require('../internal/baseProperty');
|
||||
var arrayFilter = require('../internal/arrayFilter'),
|
||||
arrayMap = require('../internal/arrayMap'),
|
||||
baseProperty = require('../internal/baseProperty'),
|
||||
isArrayLike = require('../internal/isArrayLike');
|
||||
|
||||
/** Used to the length of n-tuples for `_.unzip`. */
|
||||
var getLength = baseProperty('length');
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeMax = Math.max;
|
||||
|
||||
/**
|
||||
* This method is like `_.zip` except that it accepts an array of grouped
|
||||
* elements and creates an array regrouping the elements to their pre-`_.zip`
|
||||
* elements and creates an array regrouping the elements to their pre-zip
|
||||
* configuration.
|
||||
*
|
||||
* @static
|
||||
@@ -24,10 +25,19 @@ var getLength = baseProperty('length');
|
||||
* // => [['fred', 'barney'], [30, 40], [true, false]]
|
||||
*/
|
||||
function unzip(array) {
|
||||
if (!(array && array.length)) {
|
||||
return [];
|
||||
}
|
||||
var index = -1,
|
||||
length = (array && array.length && arrayMax(arrayMap(array, getLength))) >>> 0,
|
||||
result = Array(length);
|
||||
length = 0;
|
||||
|
||||
array = arrayFilter(array, function(group) {
|
||||
if (isArrayLike(group)) {
|
||||
length = nativeMax(group.length, length);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
var result = Array(length);
|
||||
while (++index < length) {
|
||||
result[index] = arrayMap(array, baseProperty(index));
|
||||
}
|
||||
|
||||
41
array/unzipWith.js
Normal file
41
array/unzipWith.js
Normal file
@@ -0,0 +1,41 @@
|
||||
var arrayMap = require('../internal/arrayMap'),
|
||||
arrayReduce = require('../internal/arrayReduce'),
|
||||
bindCallback = require('../internal/bindCallback'),
|
||||
unzip = require('./unzip');
|
||||
|
||||
/**
|
||||
* This method is like `_.unzip` except that it accepts an iteratee to specify
|
||||
* how regrouped values should be combined. The `iteratee` is bound to `thisArg`
|
||||
* and invoked with four arguments: (accumulator, value, index, group).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Array
|
||||
* @param {Array} array The array of grouped elements to process.
|
||||
* @param {Function} [iteratee] The function to combine regrouped values.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {Array} Returns the new array of regrouped elements.
|
||||
* @example
|
||||
*
|
||||
* var zipped = _.zip([1, 2], [10, 20], [100, 200]);
|
||||
* // => [[1, 10, 100], [2, 20, 200]]
|
||||
*
|
||||
* _.unzipWith(zipped, _.add);
|
||||
* // => [3, 30, 300]
|
||||
*/
|
||||
function unzipWith(array, iteratee, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
var result = unzip(array);
|
||||
if (iteratee == null) {
|
||||
return result;
|
||||
}
|
||||
iteratee = bindCallback(iteratee, thisArg, 4);
|
||||
return arrayMap(result, function(group) {
|
||||
return arrayReduce(group, iteratee, undefined, true);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = unzipWith;
|
||||
@@ -1,14 +1,11 @@
|
||||
var baseDifference = require('../internal/baseDifference'),
|
||||
baseSlice = require('../internal/baseSlice');
|
||||
isArrayLike = require('../internal/isArrayLike'),
|
||||
restParam = require('../function/restParam');
|
||||
|
||||
/**
|
||||
* Creates an array excluding all provided values using `SameValueZero` for
|
||||
* equality comparisons.
|
||||
*
|
||||
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
|
||||
* e.g. `===`, except that `NaN` matches `NaN`. See the
|
||||
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for more details.
|
||||
* Creates an array excluding all provided values using
|
||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for equality comparisons.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -21,8 +18,10 @@ var baseDifference = require('../internal/baseDifference'),
|
||||
* _.without([1, 2, 1, 3], 1, 2);
|
||||
* // => [3]
|
||||
*/
|
||||
function without(array) {
|
||||
return baseDifference(array, baseSlice(arguments, 1));
|
||||
}
|
||||
var without = restParam(function(array, values) {
|
||||
return isArrayLike(array)
|
||||
? baseDifference(array, values)
|
||||
: [];
|
||||
});
|
||||
|
||||
module.exports = without;
|
||||
|
||||
10
array/xor.js
10
array/xor.js
@@ -1,12 +1,10 @@
|
||||
var baseDifference = require('../internal/baseDifference'),
|
||||
baseUniq = require('../internal/baseUniq'),
|
||||
isArguments = require('../lang/isArguments'),
|
||||
isArray = require('../lang/isArray');
|
||||
isArrayLike = require('../internal/isArrayLike');
|
||||
|
||||
/**
|
||||
* Creates an array that is the symmetric difference of the provided arrays.
|
||||
* See [Wikipedia](https://en.wikipedia.org/wiki/Symmetric_difference) for
|
||||
* more details.
|
||||
* Creates an array that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
|
||||
* of the provided arrays.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -24,7 +22,7 @@ function xor() {
|
||||
|
||||
while (++index < length) {
|
||||
var array = arguments[index];
|
||||
if (isArray(array) || isArguments(array)) {
|
||||
if (isArrayLike(array)) {
|
||||
var result = result
|
||||
? baseDifference(result, array).concat(baseDifference(array, result))
|
||||
: array;
|
||||
|
||||
13
array/zip.js
13
array/zip.js
@@ -1,4 +1,5 @@
|
||||
var unzip = require('./unzip');
|
||||
var restParam = require('../function/restParam'),
|
||||
unzip = require('./unzip');
|
||||
|
||||
/**
|
||||
* Creates an array of grouped elements, the first of which contains the first
|
||||
@@ -15,14 +16,6 @@ var unzip = require('./unzip');
|
||||
* _.zip(['fred', 'barney'], [30, 40], [true, false]);
|
||||
* // => [['fred', 30, true], ['barney', 40, false]]
|
||||
*/
|
||||
function zip() {
|
||||
var length = arguments.length,
|
||||
array = Array(length);
|
||||
|
||||
while (length--) {
|
||||
array[length] = arguments[length];
|
||||
}
|
||||
return unzip(array);
|
||||
}
|
||||
var zip = restParam(unzip);
|
||||
|
||||
module.exports = zip;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
var isArray = require('../lang/isArray');
|
||||
|
||||
/**
|
||||
* Creates an object composed from arrays of property names and values. Provide
|
||||
* either a single two dimensional array, e.g. `[[key1, value1], [key2, value2]]`
|
||||
* or two arrays, one of property names and one of corresponding values.
|
||||
* The inverse of `_.pairs`; this method returns an object composed from arrays
|
||||
* of property names and values. Provide either a single two dimensional array,
|
||||
* e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
|
||||
* and one of corresponding values.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -14,6 +15,9 @@ var isArray = require('../lang/isArray');
|
||||
* @returns {Object} Returns the new object.
|
||||
* @example
|
||||
*
|
||||
* _.zipObject([['fred', 30], ['barney', 40]]);
|
||||
* // => { 'fred': 30, 'barney': 40 }
|
||||
*
|
||||
* _.zipObject(['fred', 'barney'], [30, 40]);
|
||||
* // => { 'fred': 30, 'barney': 40 }
|
||||
*/
|
||||
|
||||
36
array/zipWith.js
Normal file
36
array/zipWith.js
Normal file
@@ -0,0 +1,36 @@
|
||||
var restParam = require('../function/restParam'),
|
||||
unzipWith = require('./unzipWith');
|
||||
|
||||
/**
|
||||
* This method is like `_.zip` except that it accepts an iteratee to specify
|
||||
* how grouped values should be combined. The `iteratee` is bound to `thisArg`
|
||||
* and invoked with four arguments: (accumulator, value, index, group).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Array
|
||||
* @param {...Array} [arrays] The arrays to process.
|
||||
* @param {Function} [iteratee] The function to combine grouped values.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {Array} Returns the new array of grouped elements.
|
||||
* @example
|
||||
*
|
||||
* _.zipWith([1, 2], [10, 20], [100, 200], _.add);
|
||||
* // => [111, 222]
|
||||
*/
|
||||
var zipWith = restParam(function(arrays) {
|
||||
var length = arrays.length,
|
||||
iteratee = arrays[length - 2],
|
||||
thisArg = arrays[length - 1];
|
||||
|
||||
if (length > 2 && typeof iteratee == 'function') {
|
||||
length -= 2;
|
||||
} else {
|
||||
iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
|
||||
thisArg = undefined;
|
||||
}
|
||||
arrays.length = length;
|
||||
return unzipWith(arrays, iteratee, thisArg);
|
||||
});
|
||||
|
||||
module.exports = zipWith;
|
||||
@@ -50,8 +50,8 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
|
||||
* `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
|
||||
* `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
|
||||
* `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
|
||||
* `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
||||
* `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`,
|
||||
* `merge`, `mixin`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
||||
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
|
||||
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
|
||||
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
|
||||
@@ -65,15 +65,15 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
|
||||
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
|
||||
* `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
|
||||
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
|
||||
* `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
|
||||
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
|
||||
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
|
||||
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
|
||||
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
|
||||
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
|
||||
* `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
|
||||
* `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
|
||||
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`
|
||||
* `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`,
|
||||
* `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `isTypedArray`,
|
||||
* `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, `noConflict`,
|
||||
* `noop`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`,
|
||||
* `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, `shift`, `size`,
|
||||
* `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`, `startsWith`,
|
||||
* `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, `unescape`,
|
||||
* `uniqueId`, `value`, and `words`
|
||||
*
|
||||
* The wrapper method `sample` will return a wrapped value when `n` is provided,
|
||||
* otherwise an unwrapped value is returned.
|
||||
@@ -88,8 +88,8 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* var wrapped = _([1, 2, 3]);
|
||||
*
|
||||
* // returns an unwrapped value
|
||||
* wrapped.reduce(function(sum, n) {
|
||||
* return sum + n;
|
||||
* wrapped.reduce(function(total, n) {
|
||||
* return total + n;
|
||||
* });
|
||||
* // => 6
|
||||
*
|
||||
|
||||
@@ -10,13 +10,14 @@
|
||||
* @returns {*} Returns the result of `interceptor`.
|
||||
* @example
|
||||
*
|
||||
* _([1, 2, 3])
|
||||
* .last()
|
||||
* _(' abc ')
|
||||
* .chain()
|
||||
* .trim()
|
||||
* .thru(function(value) {
|
||||
* return [value];
|
||||
* })
|
||||
* .value();
|
||||
* // => [3]
|
||||
* // => ['abc']
|
||||
*/
|
||||
function thru(value, interceptor, thisArg) {
|
||||
return interceptor.call(thisArg, value);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
var baseAt = require('../internal/baseAt'),
|
||||
baseFlatten = require('../internal/baseFlatten'),
|
||||
isLength = require('../internal/isLength'),
|
||||
toIterable = require('../internal/toIterable');
|
||||
restParam = require('../function/restParam');
|
||||
|
||||
/**
|
||||
* Creates an array of elements corresponding to the given keys, or indexes,
|
||||
@@ -20,15 +19,11 @@ var baseAt = require('../internal/baseAt'),
|
||||
* _.at(['a', 'b', 'c'], [0, 2]);
|
||||
* // => ['a', 'c']
|
||||
*
|
||||
* _.at(['fred', 'barney', 'pebbles'], 0, 2);
|
||||
* // => ['fred', 'pebbles']
|
||||
* _.at(['barney', 'fred', 'pebbles'], 0, 2);
|
||||
* // => ['barney', 'pebbles']
|
||||
*/
|
||||
function at(collection) {
|
||||
var length = collection ? collection.length : 0;
|
||||
if (isLength(length)) {
|
||||
collection = toIterable(collection);
|
||||
}
|
||||
return baseAt(collection, baseFlatten(arguments, false, false, 1));
|
||||
}
|
||||
var at = restParam(function(collection, props) {
|
||||
return baseAt(collection, baseFlatten(props));
|
||||
});
|
||||
|
||||
module.exports = at;
|
||||
|
||||
@@ -10,17 +10,17 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* Creates an object composed of keys generated from the results of running
|
||||
* each element of `collection` through `iteratee`. The corresponding value
|
||||
* of each key is the number of times the key was returned by `iteratee`.
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* If a property name is provided for `iteratee` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
||||
* style callback returns `true` for elements that have a matching property
|
||||
* value, else `false`.
|
||||
*
|
||||
* If an object is provided for `predicate` the created `_.matches` style
|
||||
* If an object is provided for `iteratee` the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
var arrayEvery = require('../internal/arrayEvery'),
|
||||
baseCallback = require('../internal/baseCallback'),
|
||||
baseEvery = require('../internal/baseEvery'),
|
||||
isArray = require('../lang/isArray');
|
||||
isArray = require('../lang/isArray'),
|
||||
isIterateeCall = require('../internal/isIterateeCall');
|
||||
|
||||
/**
|
||||
* Checks if `predicate` returns truthy for **all** elements of `collection`.
|
||||
* The predicate is bound to `thisArg` and invoked with three arguments;
|
||||
* The predicate is bound to `thisArg` and invoked with three arguments:
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
@@ -53,7 +54,10 @@ var arrayEvery = require('../internal/arrayEvery'),
|
||||
*/
|
||||
function every(collection, predicate, thisArg) {
|
||||
var func = isArray(collection) ? arrayEvery : baseEvery;
|
||||
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
|
||||
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
|
||||
predicate = null;
|
||||
}
|
||||
if (typeof predicate != 'function' || thisArg !== undefined) {
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
}
|
||||
return func(collection, predicate);
|
||||
|
||||
@@ -6,7 +6,7 @@ var arrayFilter = require('../internal/arrayFilter'),
|
||||
/**
|
||||
* Iterates over elements of `collection`, returning an array of all elements
|
||||
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
|
||||
* invoked with three arguments; (value, index|key, collection).
|
||||
* invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
baseEach = require('../internal/baseEach'),
|
||||
baseFind = require('../internal/baseFind'),
|
||||
findIndex = require('../array/findIndex'),
|
||||
isArray = require('../lang/isArray');
|
||||
var baseEach = require('../internal/baseEach'),
|
||||
createFind = require('../internal/createFind');
|
||||
|
||||
/**
|
||||
* Iterates over elements of `collection`, returning the first element
|
||||
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
|
||||
* invoked with three arguments; (value, index|key, collection).
|
||||
* invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
@@ -54,13 +51,6 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* _.result(_.find(users, 'active'), 'user');
|
||||
* // => 'barney'
|
||||
*/
|
||||
function find(collection, predicate, thisArg) {
|
||||
if (isArray(collection)) {
|
||||
var index = findIndex(collection, predicate, thisArg);
|
||||
return index > -1 ? collection[index] : undefined;
|
||||
}
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
return baseFind(collection, predicate, baseEach);
|
||||
}
|
||||
var find = createFind(baseEach);
|
||||
|
||||
module.exports = find;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
baseEachRight = require('../internal/baseEachRight'),
|
||||
baseFind = require('../internal/baseFind');
|
||||
var baseEachRight = require('../internal/baseEachRight'),
|
||||
createFind = require('../internal/createFind');
|
||||
|
||||
/**
|
||||
* This method is like `_.find` except that it iterates over elements of
|
||||
@@ -21,9 +20,6 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* });
|
||||
* // => 3
|
||||
*/
|
||||
function findLast(collection, predicate, thisArg) {
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
return baseFind(collection, predicate, baseEachRight);
|
||||
}
|
||||
var findLast = createFind(baseEachRight, true);
|
||||
|
||||
module.exports = findLast;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
var arrayEach = require('../internal/arrayEach'),
|
||||
baseEach = require('../internal/baseEach'),
|
||||
bindCallback = require('../internal/bindCallback'),
|
||||
isArray = require('../lang/isArray');
|
||||
createForEach = require('../internal/createForEach');
|
||||
|
||||
/**
|
||||
* Iterates over elements of `collection` invoking `iteratee` for each element.
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
|
||||
* (value, index|key, collection). Iterator functions may exit iteration early
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
||||
* (value, index|key, collection). Iteratee functions may exit iteration early
|
||||
* by explicitly returning `false`.
|
||||
*
|
||||
* **Note:** As with other "Collections" methods, objects with a `length` property
|
||||
* **Note:** As with other "Collections" methods, objects with a "length" property
|
||||
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
|
||||
* may be used for object iteration.
|
||||
*
|
||||
@@ -33,10 +32,6 @@ var arrayEach = require('../internal/arrayEach'),
|
||||
* });
|
||||
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
|
||||
*/
|
||||
function forEach(collection, iteratee, thisArg) {
|
||||
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
|
||||
? arrayEach(collection, iteratee)
|
||||
: baseEach(collection, bindCallback(iteratee, thisArg, 3));
|
||||
}
|
||||
var forEach = createForEach(arrayEach, baseEach);
|
||||
|
||||
module.exports = forEach;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
var arrayEachRight = require('../internal/arrayEachRight'),
|
||||
baseEachRight = require('../internal/baseEachRight'),
|
||||
bindCallback = require('../internal/bindCallback'),
|
||||
isArray = require('../lang/isArray');
|
||||
createForEach = require('../internal/createForEach');
|
||||
|
||||
/**
|
||||
* This method is like `_.forEach` except that it iterates over elements of
|
||||
@@ -19,13 +18,9 @@ var arrayEachRight = require('../internal/arrayEachRight'),
|
||||
*
|
||||
* _([1, 2]).forEachRight(function(n) {
|
||||
* console.log(n);
|
||||
* }).join(',');
|
||||
* }).value();
|
||||
* // => logs each value from right to left and returns the array
|
||||
*/
|
||||
function forEachRight(collection, iteratee, thisArg) {
|
||||
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
|
||||
? arrayEachRight(collection, iteratee)
|
||||
: baseEachRight(collection, bindCallback(iteratee, thisArg, 3));
|
||||
}
|
||||
var forEachRight = createForEach(arrayEachRight, baseEachRight);
|
||||
|
||||
module.exports = forEachRight;
|
||||
|
||||
@@ -10,17 +10,17 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* Creates an object composed of keys generated from the results of running
|
||||
* each element of `collection` through `iteratee`. The corresponding value
|
||||
* of each key is an array of the elements responsible for generating the key.
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* If a property name is provided for `iteratee` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
||||
* style callback returns `true` for elements that have a matching property
|
||||
* value, else `false`.
|
||||
*
|
||||
* If an object is provided for `predicate` the created `_.matches` style
|
||||
* If an object is provided for `iteratee` the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
var baseIndexOf = require('../internal/baseIndexOf'),
|
||||
getLength = require('../internal/getLength'),
|
||||
isArray = require('../lang/isArray'),
|
||||
isIterateeCall = require('../internal/isIterateeCall'),
|
||||
isLength = require('../internal/isLength'),
|
||||
isString = require('../lang/isString'),
|
||||
values = require('../object/values');
|
||||
@@ -8,14 +10,10 @@ var baseIndexOf = require('../internal/baseIndexOf'),
|
||||
var nativeMax = Math.max;
|
||||
|
||||
/**
|
||||
* Checks if `value` is in `collection` using `SameValueZero` for equality
|
||||
* comparisons. If `fromIndex` is negative, it is used as the offset from
|
||||
* the end of `collection`.
|
||||
*
|
||||
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
|
||||
* e.g. `===`, except that `NaN` matches `NaN`. See the
|
||||
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for more details.
|
||||
* Checks if `value` is in `collection` using
|
||||
* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
|
||||
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
|
||||
* from the end of `collection`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -24,6 +22,7 @@ var nativeMax = Math.max;
|
||||
* @param {Array|Object|string} collection The collection to search.
|
||||
* @param {*} target The value to search for.
|
||||
* @param {number} [fromIndex=0] The index to search from.
|
||||
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
|
||||
* @returns {boolean} Returns `true` if a matching element is found, else `false`.
|
||||
* @example
|
||||
*
|
||||
@@ -39,8 +38,8 @@ var nativeMax = Math.max;
|
||||
* _.includes('pebbles', 'eb');
|
||||
* // => true
|
||||
*/
|
||||
function includes(collection, target, fromIndex) {
|
||||
var length = collection ? collection.length : 0;
|
||||
function includes(collection, target, fromIndex, guard) {
|
||||
var length = collection ? getLength(collection) : 0;
|
||||
if (!isLength(length)) {
|
||||
collection = values(collection);
|
||||
length = collection.length;
|
||||
@@ -48,10 +47,10 @@ function includes(collection, target, fromIndex) {
|
||||
if (!length) {
|
||||
return false;
|
||||
}
|
||||
if (typeof fromIndex == 'number') {
|
||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
||||
} else {
|
||||
if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
|
||||
fromIndex = 0;
|
||||
} else {
|
||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
||||
}
|
||||
return (typeof collection == 'string' || !isArray(collection) && isString(collection))
|
||||
? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)
|
||||
|
||||
@@ -4,17 +4,17 @@ var createAggregator = require('../internal/createAggregator');
|
||||
* Creates an object composed of keys generated from the results of running
|
||||
* each element of `collection` through `iteratee`. The corresponding value
|
||||
* of each key is the last element responsible for generating the key. The
|
||||
* iteratee function is bound to `thisArg` and invoked with three arguments;
|
||||
* iteratee function is bound to `thisArg` and invoked with three arguments:
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* If a property name is provided for `iteratee` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
||||
* style callback returns `true` for elements that have a matching property
|
||||
* value, else `false`.
|
||||
*
|
||||
* If an object is provided for `predicate` the created `_.matches` style
|
||||
* If an object is provided for `iteratee` the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
var baseInvoke = require('../internal/baseInvoke'),
|
||||
baseSlice = require('../internal/baseSlice');
|
||||
var baseEach = require('../internal/baseEach'),
|
||||
invokePath = require('../internal/invokePath'),
|
||||
isArrayLike = require('../internal/isArrayLike'),
|
||||
isKey = require('../internal/isKey'),
|
||||
restParam = require('../function/restParam');
|
||||
|
||||
/**
|
||||
* Invokes the method named by `methodName` on each element in `collection`,
|
||||
* returning an array of the results of each invoked method. Any additional
|
||||
* arguments are provided to each invoked method. If `methodName` is a function
|
||||
* it is invoked for, and `this` bound to, each element in `collection`.
|
||||
* Invokes the method at `path` on each element in `collection`, returning
|
||||
* an array of the results of each invoked method. Any additional arguments
|
||||
* are provided to each invoked method. If `methodName` is a function it is
|
||||
* invoked for, and `this` bound to, each element in `collection`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|string} methodName The name of the method to invoke or
|
||||
* @param {Array|Function|string} path The path of the method to invoke or
|
||||
* the function invoked per iteration.
|
||||
* @param {...*} [args] The arguments to invoke the method with.
|
||||
* @returns {Array} Returns the array of results.
|
||||
@@ -23,8 +26,17 @@ var baseInvoke = require('../internal/baseInvoke'),
|
||||
* _.invoke([123, 456], String.prototype.split, '');
|
||||
* // => [['1', '2', '3'], ['4', '5', '6']]
|
||||
*/
|
||||
function invoke(collection, methodName) {
|
||||
return baseInvoke(collection, methodName, baseSlice(arguments, 2));
|
||||
}
|
||||
var invoke = restParam(function(collection, path, args) {
|
||||
var index = -1,
|
||||
isFunc = typeof path == 'function',
|
||||
isProp = isKey(path),
|
||||
result = isArrayLike(collection) ? Array(collection.length) : [];
|
||||
|
||||
baseEach(collection, function(value) {
|
||||
var func = isFunc ? path : (isProp && value != null && value[path]);
|
||||
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
|
||||
});
|
||||
return result;
|
||||
});
|
||||
|
||||
module.exports = invoke;
|
||||
|
||||
@@ -6,16 +6,16 @@ var arrayMap = require('../internal/arrayMap'),
|
||||
/**
|
||||
* Creates an array of values by running each element in `collection` through
|
||||
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
|
||||
* arguments; (value, index|key, collection).
|
||||
* arguments: (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* If a property name is provided for `iteratee` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
||||
* style callback returns `true` for elements that have a matching property
|
||||
* value, else `false`.
|
||||
*
|
||||
* If an object is provided for `predicate` the created `_.matches` style
|
||||
* If an object is provided for `iteratee` the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
@@ -23,10 +23,11 @@ var arrayMap = require('../internal/arrayMap'),
|
||||
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
||||
*
|
||||
* The guarded methods are:
|
||||
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
|
||||
* `dropRight`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, `slice`,
|
||||
* `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, `trimRight`,
|
||||
* `trunc`, `random`, `range`, `sample`, `uniq`, and `words`
|
||||
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
|
||||
* `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
|
||||
* `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
|
||||
* `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
|
||||
* `sum`, `uniq`, and `words`
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -35,7 +36,6 @@ var arrayMap = require('../internal/arrayMap'),
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||
* per iteration.
|
||||
* create a `_.property` or `_.matches` style callback respectively.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {Array} Returns the new mapped array.
|
||||
* @example
|
||||
|
||||
@@ -4,7 +4,7 @@ var createAggregator = require('../internal/createAggregator');
|
||||
* Creates an array of elements split into two groups, the first of which
|
||||
* contains elements `predicate` returns truthy for, while the second of which
|
||||
* contains elements `predicate` returns falsey for. The predicate is bound
|
||||
* to `thisArg` and invoked with three arguments; (value, index|key, collection).
|
||||
* to `thisArg` and invoked with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
var baseProperty = require('../internal/baseProperty'),
|
||||
map = require('./map');
|
||||
var map = require('./map'),
|
||||
property = require('../utility/property');
|
||||
|
||||
/**
|
||||
* Gets the value of `key` from all elements in `collection`.
|
||||
* Gets the property value of `path` from all elements in `collection`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {string} key The key of the property to pluck.
|
||||
* @param {Array|string} path The path of the property to pluck.
|
||||
* @returns {Array} Returns the property values.
|
||||
* @example
|
||||
*
|
||||
@@ -24,8 +24,8 @@ var baseProperty = require('../internal/baseProperty'),
|
||||
* _.pluck(userIndex, 'age');
|
||||
* // => [36, 40] (iteration order is not guaranteed)
|
||||
*/
|
||||
function pluck(collection, key) {
|
||||
return map(collection, baseProperty(key));
|
||||
function pluck(collection, path) {
|
||||
return map(collection, property(path));
|
||||
}
|
||||
|
||||
module.exports = pluck;
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
var arrayReduce = require('../internal/arrayReduce'),
|
||||
baseCallback = require('../internal/baseCallback'),
|
||||
baseEach = require('../internal/baseEach'),
|
||||
baseReduce = require('../internal/baseReduce'),
|
||||
isArray = require('../lang/isArray');
|
||||
createReduce = require('../internal/createReduce');
|
||||
|
||||
/**
|
||||
* Reduces `collection` to a value which is the accumulated result of running
|
||||
* each element in `collection` through `iteratee`, where each successive
|
||||
* invocation is supplied the return value of the previous. If `accumulator`
|
||||
* is not provided the first element of `collection` is used as the initial
|
||||
* value. The `iteratee` is bound to `thisArg`and invoked with four arguments;
|
||||
* value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
|
||||
* (accumulator, value, index|key, collection).
|
||||
*
|
||||
* Many lodash methods are guarded to work as interatees for methods like
|
||||
* `_.reduce`, `_.reduceRight`, and `_.transform`.
|
||||
*
|
||||
* The guarded methods are:
|
||||
* `assign`, `defaults`, `merge`, and `sortAllBy`
|
||||
* `assign`, `defaults`, `includes`, `merge`, `sortByAll`, and `sortByOrder`
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -29,8 +27,8 @@ var arrayReduce = require('../internal/arrayReduce'),
|
||||
* @returns {*} Returns the accumulated value.
|
||||
* @example
|
||||
*
|
||||
* _.reduce([1, 2], function(sum, n) {
|
||||
* return sum + n;
|
||||
* _.reduce([1, 2], function(total, n) {
|
||||
* return total + n;
|
||||
* });
|
||||
* // => 3
|
||||
*
|
||||
@@ -40,9 +38,6 @@ var arrayReduce = require('../internal/arrayReduce'),
|
||||
* }, {});
|
||||
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
|
||||
*/
|
||||
function reduce(collection, iteratee, accumulator, thisArg) {
|
||||
var func = isArray(collection) ? arrayReduce : baseReduce;
|
||||
return func(collection, baseCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEach);
|
||||
}
|
||||
var reduce = createReduce(arrayReduce, baseEach);
|
||||
|
||||
module.exports = reduce;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
var arrayReduceRight = require('../internal/arrayReduceRight'),
|
||||
baseCallback = require('../internal/baseCallback'),
|
||||
baseEachRight = require('../internal/baseEachRight'),
|
||||
baseReduce = require('../internal/baseReduce'),
|
||||
isArray = require('../lang/isArray');
|
||||
createReduce = require('../internal/createReduce');
|
||||
|
||||
/**
|
||||
* This method is like `_.reduce` except that it iterates over elements of
|
||||
@@ -26,9 +24,6 @@ var arrayReduceRight = require('../internal/arrayReduceRight'),
|
||||
* }, []);
|
||||
* // => [4, 5, 2, 3, 0, 1]
|
||||
*/
|
||||
function reduceRight(collection, iteratee, accumulator, thisArg) {
|
||||
var func = isArray(collection) ? arrayReduceRight : baseReduce;
|
||||
return func(collection, baseCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEachRight);
|
||||
}
|
||||
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
|
||||
|
||||
module.exports = reduceRight;
|
||||
|
||||
@@ -7,17 +7,6 @@ var arrayFilter = require('../internal/arrayFilter'),
|
||||
* The opposite of `_.filter`; this method returns the elements of `collection`
|
||||
* that `predicate` does **not** return truthy for.
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
||||
* style callback returns `true` for elements that have a matching property
|
||||
* value, else `false`.
|
||||
*
|
||||
* If an object is provided for `predicate` the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
|
||||
@@ -2,9 +2,8 @@ var baseRandom = require('../internal/baseRandom'),
|
||||
toIterable = require('../internal/toIterable');
|
||||
|
||||
/**
|
||||
* Creates an array of shuffled values, using a version of the Fisher-Yates
|
||||
* shuffle. See [Wikipedia](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle)
|
||||
* for more details.
|
||||
* Creates an array of shuffled values, using a version of the
|
||||
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var isLength = require('../internal/isLength'),
|
||||
var getLength = require('../internal/getLength'),
|
||||
isLength = require('../internal/isLength'),
|
||||
keys = require('../object/keys');
|
||||
|
||||
/**
|
||||
@@ -22,7 +23,7 @@ var isLength = require('../internal/isLength'),
|
||||
* // => 7
|
||||
*/
|
||||
function size(collection) {
|
||||
var length = collection ? collection.length : 0;
|
||||
var length = collection ? getLength(collection) : 0;
|
||||
return isLength(length) ? length : keys(collection).length;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
var arraySome = require('../internal/arraySome'),
|
||||
baseCallback = require('../internal/baseCallback'),
|
||||
baseSome = require('../internal/baseSome'),
|
||||
isArray = require('../lang/isArray');
|
||||
isArray = require('../lang/isArray'),
|
||||
isIterateeCall = require('../internal/isIterateeCall');
|
||||
|
||||
/**
|
||||
* Checks if `predicate` returns truthy for **any** element of `collection`.
|
||||
* The function returns as soon as it finds a passing value and does not iterate
|
||||
* over the entire collection. The predicate is bound to `thisArg` and invoked
|
||||
* with three arguments; (value, index|key, collection).
|
||||
* with three arguments: (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
@@ -54,7 +55,10 @@ var arraySome = require('../internal/arraySome'),
|
||||
*/
|
||||
function some(collection, predicate, thisArg) {
|
||||
var func = isArray(collection) ? arraySome : baseSome;
|
||||
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
|
||||
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
|
||||
predicate = null;
|
||||
}
|
||||
if (typeof predicate != 'function' || thisArg !== undefined) {
|
||||
predicate = baseCallback(predicate, thisArg, 3);
|
||||
}
|
||||
return func(collection, predicate);
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
var baseCallback = require('../internal/baseCallback'),
|
||||
baseEach = require('../internal/baseEach'),
|
||||
baseMap = require('../internal/baseMap'),
|
||||
baseSortBy = require('../internal/baseSortBy'),
|
||||
compareAscending = require('../internal/compareAscending'),
|
||||
isIterateeCall = require('../internal/isIterateeCall'),
|
||||
isLength = require('../internal/isLength');
|
||||
isIterateeCall = require('../internal/isIterateeCall');
|
||||
|
||||
/**
|
||||
* Creates an array of elements, sorted in ascending order by the results of
|
||||
* running each element in a collection through `iteratee`. This method performs
|
||||
* a stable sort, that is, it preserves the original sort order of equal elements.
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* If a property name is provided for `iteratee` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
||||
* style callback returns `true` for elements that have a matching property
|
||||
* value, else `false`.
|
||||
*
|
||||
* If an object is provided for `predicate` the created `_.matches` style
|
||||
* If an object is provided for `iteratee` the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
@@ -27,9 +26,8 @@ var baseCallback = require('../internal/baseCallback'),
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Array|Function|Object|string} [iteratee=_.identity] The function
|
||||
* invoked per iteration. If a property name or an object is provided it is
|
||||
* used to create a `_.property` or `_.matches` style callback respectively.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {Array} Returns the new sorted array.
|
||||
* @example
|
||||
@@ -58,16 +56,14 @@ function sortBy(collection, iteratee, thisArg) {
|
||||
if (collection == null) {
|
||||
return [];
|
||||
}
|
||||
var index = -1,
|
||||
length = collection.length,
|
||||
result = isLength(length) ? Array(length) : [];
|
||||
|
||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||
iteratee = null;
|
||||
}
|
||||
var index = -1;
|
||||
iteratee = baseCallback(iteratee, thisArg, 3);
|
||||
baseEach(collection, function(value, key, collection) {
|
||||
result[++index] = { 'criteria': iteratee(value, key, collection), 'index': index, 'value': value };
|
||||
|
||||
var result = baseMap(collection, function(value, key, collection) {
|
||||
return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
|
||||
});
|
||||
return baseSortBy(result, compareAscending);
|
||||
}
|
||||
|
||||
@@ -1,41 +1,52 @@
|
||||
var baseFlatten = require('../internal/baseFlatten'),
|
||||
baseSortByOrder = require('../internal/baseSortByOrder'),
|
||||
isIterateeCall = require('../internal/isIterateeCall');
|
||||
isIterateeCall = require('../internal/isIterateeCall'),
|
||||
restParam = require('../function/restParam');
|
||||
|
||||
/**
|
||||
* This method is like `_.sortBy` except that it sorts by property names
|
||||
* instead of an iteratee function.
|
||||
* This method is like `_.sortBy` except that it can sort by multiple iteratees
|
||||
* or property names.
|
||||
*
|
||||
* If a property name is provided for an iteratee the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for an iteratee the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {...(string|string[])} props The property names to sort by,
|
||||
* specified as individual property names or arrays of property names.
|
||||
* @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
|
||||
* The iteratees to sort by, specified as individual values or arrays of values.
|
||||
* @returns {Array} Returns the new sorted array.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'fred', 'age': 48 },
|
||||
* { 'user': 'barney', 'age': 36 },
|
||||
* { 'user': 'fred', 'age': 40 },
|
||||
* { 'user': 'barney', 'age': 26 },
|
||||
* { 'user': 'fred', 'age': 30 }
|
||||
* { 'user': 'fred', 'age': 42 },
|
||||
* { 'user': 'barney', 'age': 34 }
|
||||
* ];
|
||||
*
|
||||
* _.map(_.sortByAll(users, ['user', 'age']), _.values);
|
||||
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
|
||||
* // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
|
||||
*
|
||||
* _.map(_.sortByAll(users, 'user', function(chr) {
|
||||
* return Math.floor(chr.age / 10);
|
||||
* }), _.values);
|
||||
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
||||
*/
|
||||
function sortByAll(collection) {
|
||||
var sortByAll = restParam(function(collection, iteratees) {
|
||||
if (collection == null) {
|
||||
return [];
|
||||
}
|
||||
var args = arguments,
|
||||
guard = args[3];
|
||||
|
||||
if (guard && isIterateeCall(args[1], args[2], guard)) {
|
||||
args = [collection, args[1]];
|
||||
var guard = iteratees[2];
|
||||
if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
|
||||
iteratees.length = 1;
|
||||
}
|
||||
return baseSortByOrder(collection, baseFlatten(args, false, false, 1), []);
|
||||
}
|
||||
return baseSortByOrder(collection, baseFlatten(iteratees), []);
|
||||
});
|
||||
|
||||
module.exports = sortByAll;
|
||||
|
||||
@@ -4,45 +4,52 @@ var baseSortByOrder = require('../internal/baseSortByOrder'),
|
||||
|
||||
/**
|
||||
* This method is like `_.sortByAll` except that it allows specifying the
|
||||
* sort orders of the property names to sort by. A truthy value in `orders`
|
||||
* will sort the corresponding property name in ascending order while a
|
||||
* falsey value will sort it in descending order.
|
||||
* sort orders of the iteratees to sort by. A truthy value in `orders` will
|
||||
* sort the corresponding property name in ascending order while a falsey
|
||||
* value will sort it in descending order.
|
||||
*
|
||||
* If a property name is provided for an iteratee the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for an iteratee the created `_.matches` style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {string[]} props The property names to sort by.
|
||||
* @param {boolean[]} orders The sort orders of `props`.
|
||||
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
|
||||
* @param {boolean[]} orders The sort orders of `iteratees`.
|
||||
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
|
||||
* @returns {Array} Returns the new sorted array.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 26 },
|
||||
* { 'user': 'fred', 'age': 40 },
|
||||
* { 'user': 'barney', 'age': 36 },
|
||||
* { 'user': 'fred', 'age': 30 }
|
||||
* { 'user': 'fred', 'age': 48 },
|
||||
* { 'user': 'barney', 'age': 34 },
|
||||
* { 'user': 'fred', 'age': 42 },
|
||||
* { 'user': 'barney', 'age': 36 }
|
||||
* ];
|
||||
*
|
||||
* // sort by `user` in ascending order and by `age` in descending order
|
||||
* _.map(_.sortByOrder(users, ['user', 'age'], [true, false]), _.values);
|
||||
* // => [['barney', 36], ['barney', 26], ['fred', 40], ['fred', 30]]
|
||||
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
||||
*/
|
||||
function sortByOrder(collection, props, orders, guard) {
|
||||
function sortByOrder(collection, iteratees, orders, guard) {
|
||||
if (collection == null) {
|
||||
return [];
|
||||
}
|
||||
if (guard && isIterateeCall(props, orders, guard)) {
|
||||
if (guard && isIterateeCall(iteratees, orders, guard)) {
|
||||
orders = null;
|
||||
}
|
||||
if (!isArray(props)) {
|
||||
props = props == null ? [] : [props];
|
||||
if (!isArray(iteratees)) {
|
||||
iteratees = iteratees == null ? [] : [iteratees];
|
||||
}
|
||||
if (!isArray(orders)) {
|
||||
orders = orders == null ? [] : [orders];
|
||||
}
|
||||
return baseSortByOrder(collection, props, orders);
|
||||
return baseSortByOrder(collection, iteratees, orders);
|
||||
}
|
||||
|
||||
module.exports = sortByOrder;
|
||||
|
||||
@@ -20,6 +20,7 @@ module.exports = {
|
||||
'partial': require('./function/partial'),
|
||||
'partialRight': require('./function/partialRight'),
|
||||
'rearg': require('./function/rearg'),
|
||||
'restParam': require('./function/restParam'),
|
||||
'spread': require('./function/spread'),
|
||||
'throttle': require('./function/throttle'),
|
||||
'wrap': require('./function/wrap')
|
||||
|
||||
@@ -2,7 +2,7 @@ var createWrapper = require('../internal/createWrapper'),
|
||||
isIterateeCall = require('../internal/isIterateeCall');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var ARY_FLAG = 256;
|
||||
var ARY_FLAG = 128;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeMax = Math.max;
|
||||
|
||||
@@ -31,7 +31,8 @@ function before(n, func) {
|
||||
return function() {
|
||||
if (--n > 0) {
|
||||
result = func.apply(this, arguments);
|
||||
} else {
|
||||
}
|
||||
if (n <= 1) {
|
||||
func = null;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var baseSlice = require('../internal/baseSlice'),
|
||||
createWrapper = require('../internal/createWrapper'),
|
||||
replaceHolders = require('../internal/replaceHolders');
|
||||
var createWrapper = require('../internal/createWrapper'),
|
||||
replaceHolders = require('../internal/replaceHolders'),
|
||||
restParam = require('./restParam');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var BIND_FLAG = 1,
|
||||
@@ -14,7 +14,7 @@ var BIND_FLAG = 1,
|
||||
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
|
||||
* may be used as a placeholder for partially applied arguments.
|
||||
*
|
||||
* **Note:** Unlike native `Function#bind` this method does not set the `length`
|
||||
* **Note:** Unlike native `Function#bind` this method does not set the "length"
|
||||
* property of bound functions.
|
||||
*
|
||||
* @static
|
||||
@@ -22,7 +22,7 @@ var BIND_FLAG = 1,
|
||||
* @category Function
|
||||
* @param {Function} func The function to bind.
|
||||
* @param {*} thisArg The `this` binding of `func`.
|
||||
* @param {...*} [args] The arguments to be partially applied.
|
||||
* @param {...*} [partials] The arguments to be partially applied.
|
||||
* @returns {Function} Returns the new bound function.
|
||||
* @example
|
||||
*
|
||||
@@ -41,16 +41,14 @@ var BIND_FLAG = 1,
|
||||
* bound('hi');
|
||||
* // => 'hi fred!'
|
||||
*/
|
||||
function bind(func, thisArg) {
|
||||
var bind = restParam(function(func, thisArg, partials) {
|
||||
var bitmask = BIND_FLAG;
|
||||
if (arguments.length > 2) {
|
||||
var partials = baseSlice(arguments, 2),
|
||||
holders = replaceHolders(partials, bind.placeholder);
|
||||
|
||||
if (partials.length) {
|
||||
var holders = replaceHolders(partials, bind.placeholder);
|
||||
bitmask |= PARTIAL_FLAG;
|
||||
}
|
||||
return createWrapper(func, bitmask, thisArg, partials, holders);
|
||||
}
|
||||
});
|
||||
|
||||
// Assign default placeholders.
|
||||
bind.placeholder = {};
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
var baseBindAll = require('../internal/baseBindAll'),
|
||||
baseFlatten = require('../internal/baseFlatten'),
|
||||
functions = require('../object/functions');
|
||||
var baseFlatten = require('../internal/baseFlatten'),
|
||||
createWrapper = require('../internal/createWrapper'),
|
||||
functions = require('../object/functions'),
|
||||
restParam = require('./restParam');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var BIND_FLAG = 1;
|
||||
|
||||
/**
|
||||
* Binds methods of an object to the object itself, overwriting the existing
|
||||
@@ -8,7 +12,7 @@ var baseBindAll = require('../internal/baseBindAll'),
|
||||
* of method names. If no method names are provided all enumerable function
|
||||
* properties, own and inherited, of `object` are bound.
|
||||
*
|
||||
* **Note:** This method does not set the `length` property of bound functions.
|
||||
* **Note:** This method does not set the "length" property of bound functions.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -30,12 +34,17 @@ var baseBindAll = require('../internal/baseBindAll'),
|
||||
* jQuery('#docs').on('click', view.onClick);
|
||||
* // => logs 'clicked docs' when the element is clicked
|
||||
*/
|
||||
function bindAll(object) {
|
||||
return baseBindAll(object,
|
||||
arguments.length > 1
|
||||
? baseFlatten(arguments, false, false, 1)
|
||||
: functions(object)
|
||||
);
|
||||
}
|
||||
var bindAll = restParam(function(object, methodNames) {
|
||||
methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
|
||||
|
||||
var index = -1,
|
||||
length = methodNames.length;
|
||||
|
||||
while (++index < length) {
|
||||
var key = methodNames[index];
|
||||
object[key] = createWrapper(object[key], BIND_FLAG, object);
|
||||
}
|
||||
return object;
|
||||
});
|
||||
|
||||
module.exports = bindAll;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var baseSlice = require('../internal/baseSlice'),
|
||||
createWrapper = require('../internal/createWrapper'),
|
||||
replaceHolders = require('../internal/replaceHolders');
|
||||
var createWrapper = require('../internal/createWrapper'),
|
||||
replaceHolders = require('../internal/replaceHolders'),
|
||||
restParam = require('./restParam');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var BIND_FLAG = 1,
|
||||
@@ -13,7 +13,7 @@ var BIND_FLAG = 1,
|
||||
*
|
||||
* This method differs from `_.bind` by allowing bound functions to reference
|
||||
* methods that may be redefined or don't yet exist.
|
||||
* See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern)
|
||||
* See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
|
||||
* for more details.
|
||||
*
|
||||
* The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
|
||||
@@ -24,7 +24,7 @@ var BIND_FLAG = 1,
|
||||
* @category Function
|
||||
* @param {Object} object The object the method belongs to.
|
||||
* @param {string} key The key of the method.
|
||||
* @param {...*} [args] The arguments to be partially applied.
|
||||
* @param {...*} [partials] The arguments to be partially applied.
|
||||
* @returns {Function} Returns the new bound function.
|
||||
* @example
|
||||
*
|
||||
@@ -51,16 +51,14 @@ var BIND_FLAG = 1,
|
||||
* bound('hi');
|
||||
* // => 'hiya fred!'
|
||||
*/
|
||||
function bindKey(object, key) {
|
||||
var bindKey = restParam(function(object, key, partials) {
|
||||
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
|
||||
if (arguments.length > 2) {
|
||||
var partials = baseSlice(arguments, 2),
|
||||
holders = replaceHolders(partials, bindKey.placeholder);
|
||||
|
||||
if (partials.length) {
|
||||
var holders = replaceHolders(partials, bindKey.placeholder);
|
||||
bitmask |= PARTIAL_FLAG;
|
||||
}
|
||||
return createWrapper(key, bitmask, object, partials, holders);
|
||||
}
|
||||
});
|
||||
|
||||
// Assign default placeholders.
|
||||
bindKey.placeholder = {};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var createWrapper = require('../internal/createWrapper'),
|
||||
isIterateeCall = require('../internal/isIterateeCall');
|
||||
var createCurry = require('../internal/createCurry');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var CURRY_FLAG = 8;
|
||||
@@ -14,7 +13,7 @@ var CURRY_FLAG = 8;
|
||||
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
|
||||
* may be used as a placeholder for provided arguments.
|
||||
*
|
||||
* **Note:** This method does not set the `length` property of curried functions.
|
||||
* **Note:** This method does not set the "length" property of curried functions.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -44,14 +43,7 @@ var CURRY_FLAG = 8;
|
||||
* curried(1)(_, 3)(2);
|
||||
* // => [1, 2, 3]
|
||||
*/
|
||||
function curry(func, arity, guard) {
|
||||
if (guard && isIterateeCall(func, arity, guard)) {
|
||||
arity = null;
|
||||
}
|
||||
var result = createWrapper(func, CURRY_FLAG, null, null, null, null, null, arity);
|
||||
result.placeholder = curry.placeholder;
|
||||
return result;
|
||||
}
|
||||
var curry = createCurry(CURRY_FLAG);
|
||||
|
||||
// Assign default placeholders.
|
||||
curry.placeholder = {};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var createWrapper = require('../internal/createWrapper'),
|
||||
isIterateeCall = require('../internal/isIterateeCall');
|
||||
var createCurry = require('../internal/createCurry');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var CURRY_RIGHT_FLAG = 16;
|
||||
@@ -11,7 +10,7 @@ var CURRY_RIGHT_FLAG = 16;
|
||||
* The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
|
||||
* builds, may be used as a placeholder for provided arguments.
|
||||
*
|
||||
* **Note:** This method does not set the `length` property of curried functions.
|
||||
* **Note:** This method does not set the "length" property of curried functions.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -41,14 +40,7 @@ var CURRY_RIGHT_FLAG = 16;
|
||||
* curried(3)(1, _)(2);
|
||||
* // => [1, 2, 3]
|
||||
*/
|
||||
function curryRight(func, arity, guard) {
|
||||
if (guard && isIterateeCall(func, arity, guard)) {
|
||||
arity = null;
|
||||
}
|
||||
var result = createWrapper(func, CURRY_RIGHT_FLAG, null, null, null, null, null, arity);
|
||||
result.placeholder = curryRight.placeholder;
|
||||
return result;
|
||||
}
|
||||
var curryRight = createCurry(CURRY_RIGHT_FLAG);
|
||||
|
||||
// Assign default placeholders.
|
||||
curryRight.placeholder = {};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var baseDelay = require('../internal/baseDelay');
|
||||
var baseDelay = require('../internal/baseDelay'),
|
||||
restParam = require('./restParam');
|
||||
|
||||
/**
|
||||
* Defers invoking the `func` until the current call stack has cleared. Any
|
||||
@@ -17,8 +18,8 @@ var baseDelay = require('../internal/baseDelay');
|
||||
* }, 'deferred');
|
||||
* // logs 'deferred' after one or more milliseconds
|
||||
*/
|
||||
function defer(func) {
|
||||
return baseDelay(func, 1, arguments, 1);
|
||||
}
|
||||
var defer = restParam(function(func, args) {
|
||||
return baseDelay(func, 1, args);
|
||||
});
|
||||
|
||||
module.exports = defer;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var baseDelay = require('../internal/baseDelay');
|
||||
var baseDelay = require('../internal/baseDelay'),
|
||||
restParam = require('./restParam');
|
||||
|
||||
/**
|
||||
* Invokes `func` after `wait` milliseconds. Any additional arguments are
|
||||
@@ -18,8 +19,8 @@ var baseDelay = require('../internal/baseDelay');
|
||||
* }, 1000, 'later');
|
||||
* // => logs 'later' after one second
|
||||
*/
|
||||
function delay(func, wait) {
|
||||
return baseDelay(func, wait, arguments, 2);
|
||||
}
|
||||
var delay = restParam(function(func, wait, args) {
|
||||
return baseDelay(func, wait, args);
|
||||
});
|
||||
|
||||
module.exports = delay;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var createComposer = require('../internal/createComposer');
|
||||
var createFlow = require('../internal/createFlow');
|
||||
|
||||
/**
|
||||
* Creates a function that returns the result of invoking the provided
|
||||
@@ -20,6 +20,6 @@ var createComposer = require('../internal/createComposer');
|
||||
* addSquare(1, 2);
|
||||
* // => 9
|
||||
*/
|
||||
var flow = createComposer();
|
||||
var flow = createFlow();
|
||||
|
||||
module.exports = flow;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var createComposer = require('../internal/createComposer');
|
||||
var createFlow = require('../internal/createFlow');
|
||||
|
||||
/**
|
||||
* This method is like `_.flow` except that it creates a function that
|
||||
@@ -20,6 +20,6 @@ var createComposer = require('../internal/createComposer');
|
||||
* addSquare(1, 2);
|
||||
* // => 9
|
||||
*/
|
||||
var flowRight = createComposer(true);
|
||||
var flowRight = createFlow(true);
|
||||
|
||||
module.exports = flowRight;
|
||||
|
||||
@@ -13,10 +13,8 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
*
|
||||
* **Note:** The cache is exposed as the `cache` property on the memoized
|
||||
* function. Its creation may be customized by replacing the `_.memoize.Cache`
|
||||
* constructor with one whose instances implement the ES `Map` method interface
|
||||
* of `get`, `has`, and `set`. See the
|
||||
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
|
||||
* for more details.
|
||||
* constructor with one whose instances implement the [`Map`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
|
||||
* method interface of `get`, `has`, and `set`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
|
||||
@@ -3,7 +3,7 @@ var before = require('./before');
|
||||
/**
|
||||
* Creates a function that is restricted to invoking `func` once. Repeat calls
|
||||
* to the function return the value of the first call. The `func` is invoked
|
||||
* with the `this` binding of the created function.
|
||||
* with the `this` binding and arguments of the created function.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -18,7 +18,7 @@ var before = require('./before');
|
||||
* // `initialize` invokes `createApplication` once
|
||||
*/
|
||||
function once(func) {
|
||||
return before(func, 2);
|
||||
return before(2, func);
|
||||
}
|
||||
|
||||
module.exports = once;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
var baseSlice = require('../internal/baseSlice'),
|
||||
createWrapper = require('../internal/createWrapper'),
|
||||
replaceHolders = require('../internal/replaceHolders');
|
||||
var createPartial = require('../internal/createPartial');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var PARTIAL_FLAG = 32;
|
||||
@@ -13,14 +11,14 @@ var PARTIAL_FLAG = 32;
|
||||
* The `_.partial.placeholder` value, which defaults to `_` in monolithic
|
||||
* builds, may be used as a placeholder for partially applied arguments.
|
||||
*
|
||||
* **Note:** This method does not set the `length` property of partially
|
||||
* **Note:** This method does not set the "length" property of partially
|
||||
* applied functions.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Function
|
||||
* @param {Function} func The function to partially apply arguments to.
|
||||
* @param {...*} [args] The arguments to be partially applied.
|
||||
* @param {...*} [partials] The arguments to be partially applied.
|
||||
* @returns {Function} Returns the new partially applied function.
|
||||
* @example
|
||||
*
|
||||
@@ -37,12 +35,7 @@ var PARTIAL_FLAG = 32;
|
||||
* greetFred('hi');
|
||||
* // => 'hi fred'
|
||||
*/
|
||||
function partial(func) {
|
||||
var partials = baseSlice(arguments, 1),
|
||||
holders = replaceHolders(partials, partial.placeholder);
|
||||
|
||||
return createWrapper(func, PARTIAL_FLAG, null, partials, holders);
|
||||
}
|
||||
var partial = createPartial(PARTIAL_FLAG);
|
||||
|
||||
// Assign default placeholders.
|
||||
partial.placeholder = {};
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
var baseSlice = require('../internal/baseSlice'),
|
||||
createWrapper = require('../internal/createWrapper'),
|
||||
replaceHolders = require('../internal/replaceHolders');
|
||||
var createPartial = require('../internal/createPartial');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var PARTIAL_RIGHT_FLAG = 64;
|
||||
@@ -12,14 +10,14 @@ var PARTIAL_RIGHT_FLAG = 64;
|
||||
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
|
||||
* builds, may be used as a placeholder for partially applied arguments.
|
||||
*
|
||||
* **Note:** This method does not set the `length` property of partially
|
||||
* **Note:** This method does not set the "length" property of partially
|
||||
* applied functions.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Function
|
||||
* @param {Function} func The function to partially apply arguments to.
|
||||
* @param {...*} [args] The arguments to be partially applied.
|
||||
* @param {...*} [partials] The arguments to be partially applied.
|
||||
* @returns {Function} Returns the new partially applied function.
|
||||
* @example
|
||||
*
|
||||
@@ -36,12 +34,7 @@ var PARTIAL_RIGHT_FLAG = 64;
|
||||
* sayHelloTo('fred');
|
||||
* // => 'hello fred'
|
||||
*/
|
||||
function partialRight(func) {
|
||||
var partials = baseSlice(arguments, 1),
|
||||
holders = replaceHolders(partials, partialRight.placeholder);
|
||||
|
||||
return createWrapper(func, PARTIAL_RIGHT_FLAG, null, partials, holders);
|
||||
}
|
||||
var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
|
||||
|
||||
// Assign default placeholders.
|
||||
partialRight.placeholder = {};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
var baseFlatten = require('../internal/baseFlatten'),
|
||||
createWrapper = require('../internal/createWrapper');
|
||||
createWrapper = require('../internal/createWrapper'),
|
||||
restParam = require('./restParam');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var REARG_FLAG = 128;
|
||||
var REARG_FLAG = 256;
|
||||
|
||||
/**
|
||||
* Creates a function that invokes `func` with arguments arranged according
|
||||
@@ -32,9 +33,8 @@ var REARG_FLAG = 128;
|
||||
* }, [1, 2, 3]);
|
||||
* // => [3, 6, 9]
|
||||
*/
|
||||
function rearg(func) {
|
||||
var indexes = baseFlatten(arguments, false, false, 1);
|
||||
return createWrapper(func, REARG_FLAG, null, null, null, indexes);
|
||||
}
|
||||
var rearg = restParam(function(func, indexes) {
|
||||
return createWrapper(func, REARG_FLAG, null, null, null, baseFlatten(indexes));
|
||||
});
|
||||
|
||||
module.exports = rearg;
|
||||
|
||||
58
function/restParam.js
Normal file
58
function/restParam.js
Normal file
@@ -0,0 +1,58 @@
|
||||
/** 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 nativeMax = Math.max;
|
||||
|
||||
/**
|
||||
* Creates a function that invokes `func` with the `this` binding of the
|
||||
* created function and arguments from `start` and beyond provided as an array.
|
||||
*
|
||||
* **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Function
|
||||
* @param {Function} func The function to apply a rest parameter to.
|
||||
* @param {number} [start=func.length-1] The start position of the rest parameter.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var say = _.restParam(function(what, names) {
|
||||
* return what + ' ' + _.initial(names).join(', ') +
|
||||
* (_.size(names) > 1 ? ', & ' : '') + _.last(names);
|
||||
* });
|
||||
*
|
||||
* say('hello', 'fred', 'barney', 'pebbles');
|
||||
* // => 'hello fred, barney, & pebbles'
|
||||
*/
|
||||
function restParam(func, start) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
|
||||
return function() {
|
||||
var args = arguments,
|
||||
index = -1,
|
||||
length = nativeMax(args.length - start, 0),
|
||||
rest = Array(length);
|
||||
|
||||
while (++index < length) {
|
||||
rest[index] = args[start + index];
|
||||
}
|
||||
switch (start) {
|
||||
case 0: return func.call(this, rest);
|
||||
case 1: return func.call(this, args[0], rest);
|
||||
case 2: return func.call(this, args[0], args[1], rest);
|
||||
}
|
||||
var otherArgs = Array(start + 1);
|
||||
index = -1;
|
||||
while (++index < start) {
|
||||
otherArgs[index] = args[index];
|
||||
}
|
||||
otherArgs[start] = rest;
|
||||
return func.apply(this, otherArgs);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = restParam;
|
||||
@@ -2,23 +2,24 @@
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
/**
|
||||
* Creates a function that invokes `func` with the `this` binding of the
|
||||
* created function and the array of arguments provided to the created
|
||||
* function much like [Function#apply](http://es5.github.io/#x15.3.4.3).
|
||||
* Creates a function that invokes `func` with the `this` binding of the created
|
||||
* function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
|
||||
*
|
||||
* **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Function
|
||||
* @param {Function} func The function to spread arguments over.
|
||||
* @returns {*} Returns the new function.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var spread = _.spread(function(who, what) {
|
||||
* var say = _.spread(function(who, what) {
|
||||
* return who + ' says ' + what;
|
||||
* });
|
||||
*
|
||||
* spread(['Fred', 'hello']);
|
||||
* // => 'Fred says hello'
|
||||
* say(['fred', 'hello']);
|
||||
* // => 'fred says hello'
|
||||
*
|
||||
* // with a Promise
|
||||
* var numbers = Promise.all([
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* A specialized version of `_.forEach` for arrays without support for callback
|
||||
* shorthands or `this` binding.
|
||||
* shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* A specialized version of `_.forEachRight` for arrays without support for
|
||||
* callback shorthands or `this` binding.
|
||||
* callback shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* A specialized version of `_.every` for arrays without support for callback
|
||||
* shorthands or `this` binding.
|
||||
* shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* A specialized version of `_.filter` for arrays without support for callback
|
||||
* shorthands or `this` binding.
|
||||
* shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* A specialized version of `_.map` for arrays without support for callback
|
||||
* shorthands or `this` binding.
|
||||
* shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* A specialized version of `_.reduce` for arrays without support for callback
|
||||
* shorthands or `this` binding.
|
||||
* shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* A specialized version of `_.reduceRight` for arrays without support for
|
||||
* callback shorthands or `this` binding.
|
||||
* callback shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* A specialized version of `_.some` for arrays without support for callback
|
||||
* shorthands or `this` binding.
|
||||
* shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
|
||||
18
internal/arraySum.js
Normal file
18
internal/arraySum.js
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* A specialized version of `_.sum` for arrays without support for iteratees.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @returns {number} Returns the sum.
|
||||
*/
|
||||
function arraySum(array) {
|
||||
var length = array.length,
|
||||
result = 0;
|
||||
|
||||
while (length--) {
|
||||
result += +array[length] || 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = arraySum;
|
||||
@@ -7,7 +7,7 @@
|
||||
* @returns {*} Returns the value to assign to the destination object.
|
||||
*/
|
||||
function assignDefaults(objectValue, sourceValue) {
|
||||
return typeof objectValue == 'undefined' ? sourceValue : objectValue;
|
||||
return objectValue === undefined ? sourceValue : objectValue;
|
||||
}
|
||||
|
||||
module.exports = assignDefaults;
|
||||
|
||||
@@ -7,7 +7,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
/**
|
||||
* Used by `_.template` to customize its `_.assign` use.
|
||||
*
|
||||
* **Note:** This method is like `assignDefaults` except that it ignores
|
||||
* **Note:** This function is like `assignDefaults` except that it ignores
|
||||
* inherited property values when checking if a property is `undefined`.
|
||||
*
|
||||
* @private
|
||||
@@ -18,7 +18,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* @returns {*} Returns the value to assign to the destination object.
|
||||
*/
|
||||
function assignOwnDefaults(objectValue, sourceValue, key, object) {
|
||||
return (typeof objectValue == 'undefined' || !hasOwnProperty.call(object, key))
|
||||
return (objectValue === undefined || !hasOwnProperty.call(object, key))
|
||||
? sourceValue
|
||||
: objectValue;
|
||||
}
|
||||
|
||||
41
internal/assignWith.js
Normal file
41
internal/assignWith.js
Normal file
@@ -0,0 +1,41 @@
|
||||
var getSymbols = require('./getSymbols'),
|
||||
keys = require('../object/keys');
|
||||
|
||||
/** Used for native method references. */
|
||||
var arrayProto = Array.prototype;
|
||||
|
||||
/** Native method references. */
|
||||
var push = arrayProto.push;
|
||||
|
||||
/**
|
||||
* A specialized version of `_.assign` for customizing assigned values without
|
||||
* support for argument juggling, multiple sources, and `this` binding `customizer`
|
||||
* functions.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The destination object.
|
||||
* @param {Object} source The source object.
|
||||
* @param {Function} customizer The function to customize assigned values.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
function assignWith(object, source, customizer) {
|
||||
var props = keys(source);
|
||||
push.apply(props, getSymbols(source));
|
||||
|
||||
var index = -1,
|
||||
length = props.length;
|
||||
|
||||
while (++index < length) {
|
||||
var key = props[index],
|
||||
value = object[key],
|
||||
result = customizer(value, source[key], key, object, source);
|
||||
|
||||
if ((result === result ? (result !== value) : (value === value)) ||
|
||||
(value === undefined && !(key in object))) {
|
||||
object[key] = result;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
module.exports = assignWith;
|
||||
@@ -1,35 +1,47 @@
|
||||
var baseCopy = require('./baseCopy'),
|
||||
getSymbols = require('./getSymbols'),
|
||||
isNative = require('../lang/isNative'),
|
||||
keys = require('../object/keys');
|
||||
|
||||
/** Native method references. */
|
||||
var preventExtensions = isNative(preventExtensions = Object.preventExtensions) && preventExtensions;
|
||||
|
||||
/** Used as `baseAssign`. */
|
||||
var nativeAssign = (function() {
|
||||
// Avoid `Object.assign` in Firefox 34-37 which have an early implementation
|
||||
// with a now defunct try/catch behavior. See https://bugzilla.mozilla.org/show_bug.cgi?id=1103344
|
||||
// for more details.
|
||||
//
|
||||
// Use `Object.preventExtensions` on a plain object instead of simply using
|
||||
// `Object('x')` because Chrome and IE fail to throw an error when attempting
|
||||
// to assign values to readonly indexes of strings.
|
||||
var func = preventExtensions && isNative(func = Object.assign) && func;
|
||||
try {
|
||||
if (func) {
|
||||
var object = preventExtensions({ '1': 0 });
|
||||
object[0] = 1;
|
||||
}
|
||||
} catch(e) {
|
||||
// Only attempt in strict mode.
|
||||
try { func(object, 'xo'); } catch(e) {}
|
||||
return !object[1] && func;
|
||||
}
|
||||
return false;
|
||||
}());
|
||||
|
||||
/**
|
||||
* The base implementation of `_.assign` without support for argument juggling,
|
||||
* multiple sources, and `this` binding `customizer` functions.
|
||||
* multiple sources, and `customizer` functions.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The destination object.
|
||||
* @param {Object} source The source object.
|
||||
* @param {Function} [customizer] The function to customize assigning values.
|
||||
* @returns {Object} Returns the destination object.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
function baseAssign(object, source, customizer) {
|
||||
var props = keys(source);
|
||||
if (!customizer) {
|
||||
return baseCopy(source, object, props);
|
||||
}
|
||||
var index = -1,
|
||||
length = props.length;
|
||||
|
||||
while (++index < length) {
|
||||
var key = props[index],
|
||||
value = object[key],
|
||||
result = customizer(value, source[key], key, object, source);
|
||||
|
||||
if ((result === result ? (result !== value) : (value === value)) ||
|
||||
(typeof value == 'undefined' && !(key in object))) {
|
||||
object[key] = result;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
var baseAssign = nativeAssign || function(object, source) {
|
||||
return source == null
|
||||
? object
|
||||
: baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object));
|
||||
};
|
||||
|
||||
module.exports = baseAssign;
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
var isIndex = require('./isIndex'),
|
||||
isLength = require('./isLength');
|
||||
var isArrayLike = require('./isArrayLike'),
|
||||
isIndex = require('./isIndex');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.at` without support for strings and individual
|
||||
* key arguments.
|
||||
* The base implementation of `_.at` without support for string collections
|
||||
* and individual key arguments.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {number[]|string[]} [props] The property names or indexes of elements to pick.
|
||||
* @param {number[]|string[]} props The property names or indexes of elements to pick.
|
||||
* @returns {Array} Returns the new array of picked elements.
|
||||
*/
|
||||
function baseAt(collection, props) {
|
||||
var index = -1,
|
||||
length = collection.length,
|
||||
isArr = isLength(length),
|
||||
isNil = collection == null,
|
||||
isArr = !isNil && isArrayLike(collection),
|
||||
length = isArr && collection.length,
|
||||
propsLength = props.length,
|
||||
result = Array(propsLength);
|
||||
|
||||
while(++index < propsLength) {
|
||||
var key = props[index];
|
||||
if (isArr) {
|
||||
key = parseFloat(key);
|
||||
result[index] = isIndex(key, length) ? collection[key] : undefined;
|
||||
} else {
|
||||
result[index] = collection[key];
|
||||
result[index] = isNil ? undefined : collection[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
var createWrapper = require('./createWrapper');
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var BIND_FLAG = 1;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.bindAll` without support for individual
|
||||
* method name arguments.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to bind and assign the bound methods to.
|
||||
* @param {string[]} methodNames The object method names to bind.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
function baseBindAll(object, methodNames) {
|
||||
var index = -1,
|
||||
length = methodNames.length;
|
||||
|
||||
while (++index < length) {
|
||||
var key = methodNames[index];
|
||||
object[key] = createWrapper(object[key], BIND_FLAG, object);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
module.exports = baseBindAll;
|
||||
@@ -1,9 +1,8 @@
|
||||
var baseMatches = require('./baseMatches'),
|
||||
baseMatchesProperty = require('./baseMatchesProperty'),
|
||||
baseProperty = require('./baseProperty'),
|
||||
bindCallback = require('./bindCallback'),
|
||||
identity = require('../utility/identity'),
|
||||
isBindable = require('./isBindable');
|
||||
property = require('../utility/property');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.callback` which supports specifying the
|
||||
@@ -18,9 +17,9 @@ var baseMatches = require('./baseMatches'),
|
||||
function baseCallback(func, thisArg, argCount) {
|
||||
var type = typeof func;
|
||||
if (type == 'function') {
|
||||
return (typeof thisArg != 'undefined' && isBindable(func))
|
||||
? bindCallback(func, thisArg, argCount)
|
||||
: func;
|
||||
return thisArg === undefined
|
||||
? func
|
||||
: bindCallback(func, thisArg, argCount);
|
||||
}
|
||||
if (func == null) {
|
||||
return identity;
|
||||
@@ -28,9 +27,9 @@ function baseCallback(func, thisArg, argCount) {
|
||||
if (type == 'object') {
|
||||
return baseMatches(func);
|
||||
}
|
||||
return typeof thisArg == 'undefined'
|
||||
? baseProperty(func + '')
|
||||
: baseMatchesProperty(func + '', thisArg);
|
||||
return thisArg === undefined
|
||||
? property(func)
|
||||
: baseMatchesProperty(func, thisArg);
|
||||
}
|
||||
|
||||
module.exports = baseCallback;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
var arrayCopy = require('./arrayCopy'),
|
||||
arrayEach = require('./arrayEach'),
|
||||
baseCopy = require('./baseCopy'),
|
||||
baseAssign = require('./baseAssign'),
|
||||
baseForOwn = require('./baseForOwn'),
|
||||
initCloneArray = require('./initCloneArray'),
|
||||
initCloneByTag = require('./initCloneByTag'),
|
||||
initCloneObject = require('./initCloneObject'),
|
||||
isArray = require('../lang/isArray'),
|
||||
isObject = require('../lang/isObject'),
|
||||
keys = require('../object/keys');
|
||||
isObject = require('../lang/isObject');
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var argsTag = '[object Arguments]',
|
||||
@@ -54,9 +53,8 @@ cloneableTags[weakMapTag] = false;
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the `toStringTag` of values.
|
||||
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* for more details.
|
||||
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
|
||||
* of values.
|
||||
*/
|
||||
var objToString = objectProto.toString;
|
||||
|
||||
@@ -79,7 +77,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
|
||||
if (customizer) {
|
||||
result = object ? customizer(value, key, object) : customizer(value);
|
||||
}
|
||||
if (typeof result != 'undefined') {
|
||||
if (result !== undefined) {
|
||||
return result;
|
||||
}
|
||||
if (!isObject(value)) {
|
||||
@@ -98,7 +96,7 @@ function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
|
||||
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
||||
result = initCloneObject(isFunc ? {} : value);
|
||||
if (!isDeep) {
|
||||
return baseCopy(value, result, keys(value));
|
||||
return baseAssign(result, value);
|
||||
}
|
||||
} else {
|
||||
return cloneableTags[tag]
|
||||
|
||||
@@ -12,10 +12,10 @@ function baseCompareAscending(value, other) {
|
||||
var valIsReflexive = value === value,
|
||||
othIsReflexive = other === other;
|
||||
|
||||
if (value > other || !valIsReflexive || (typeof value == 'undefined' && othIsReflexive)) {
|
||||
if (value > other || !valIsReflexive || (value === undefined && othIsReflexive)) {
|
||||
return 1;
|
||||
}
|
||||
if (value < other || !othIsReflexive || (typeof other == 'undefined' && valIsReflexive)) {
|
||||
if (value < other || !othIsReflexive || (other === undefined && valIsReflexive)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
/**
|
||||
* Copies the properties of `source` to `object`.
|
||||
* Copies properties of `source` to `object`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} source The object to copy properties from.
|
||||
* @param {Object} [object={}] The object to copy properties to.
|
||||
* @param {Array} props The property names to copy.
|
||||
* @param {Object} [object={}] The object to copy properties to.
|
||||
* @returns {Object} Returns `object`.
|
||||
*/
|
||||
function baseCopy(source, object, props) {
|
||||
if (!props) {
|
||||
props = object;
|
||||
object = {};
|
||||
}
|
||||
function baseCopy(source, props, object) {
|
||||
object || (object = {});
|
||||
|
||||
var index = -1,
|
||||
length = props.length;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
var baseSlice = require('./baseSlice');
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
@@ -10,14 +8,14 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
* @private
|
||||
* @param {Function} func The function to delay.
|
||||
* @param {number} wait The number of milliseconds to delay invocation.
|
||||
* @param {Object} args The `arguments` object to slice and provide to `func`.
|
||||
* @param {Object} args The arguments provide to `func`.
|
||||
* @returns {number} Returns the timer id.
|
||||
*/
|
||||
function baseDelay(func, wait, args, fromIndex) {
|
||||
function baseDelay(func, wait, args) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);
|
||||
return setTimeout(function() { func.apply(undefined, args); }, wait);
|
||||
}
|
||||
|
||||
module.exports = baseDelay;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
var baseForOwn = require('./baseForOwn'),
|
||||
isLength = require('./isLength'),
|
||||
toObject = require('./toObject');
|
||||
createBaseEach = require('./createBaseEach');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.forEach` without support for callback
|
||||
@@ -11,20 +10,6 @@ var baseForOwn = require('./baseForOwn'),
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {Array|Object|string} Returns `collection`.
|
||||
*/
|
||||
function baseEach(collection, iteratee) {
|
||||
var length = collection ? collection.length : 0;
|
||||
if (!isLength(length)) {
|
||||
return baseForOwn(collection, iteratee);
|
||||
}
|
||||
var index = -1,
|
||||
iterable = toObject(collection);
|
||||
|
||||
while (++index < length) {
|
||||
if (iteratee(iterable[index], index, iterable) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
var baseEach = createBaseEach(baseForOwn);
|
||||
|
||||
module.exports = baseEach;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
var baseForOwnRight = require('./baseForOwnRight'),
|
||||
isLength = require('./isLength'),
|
||||
toObject = require('./toObject');
|
||||
createBaseEach = require('./createBaseEach');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.forEachRight` without support for callback
|
||||
@@ -11,18 +10,6 @@ var baseForOwnRight = require('./baseForOwnRight'),
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {Array|Object|string} Returns `collection`.
|
||||
*/
|
||||
function baseEachRight(collection, iteratee) {
|
||||
var length = collection ? collection.length : 0;
|
||||
if (!isLength(length)) {
|
||||
return baseForOwnRight(collection, iteratee);
|
||||
}
|
||||
var iterable = toObject(collection);
|
||||
while (length--) {
|
||||
if (iteratee(iterable[length], length, iterable) === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
var baseEachRight = createBaseEach(baseForOwnRight, true);
|
||||
|
||||
module.exports = baseEachRight;
|
||||
|
||||
@@ -2,7 +2,7 @@ var baseEach = require('./baseEach');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.every` without support for callback
|
||||
* shorthands or `this` binding.
|
||||
* shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
|
||||
@@ -15,7 +15,7 @@ function baseFill(array, value, start, end) {
|
||||
if (start < 0) {
|
||||
start = -start > length ? 0 : (length + start);
|
||||
}
|
||||
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
|
||||
end = (end === undefined || end > length) ? length : (+end || 0);
|
||||
if (end < 0) {
|
||||
end += length;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ var baseEach = require('./baseEach');
|
||||
|
||||
/**
|
||||
* The base implementation of `_.filter` without support for callback
|
||||
* shorthands or `this` binding.
|
||||
* shorthands and `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user