Compare commits

...

2 Commits

Author SHA1 Message Date
jdalton
05cb7419a6 Bump to v3.2.0. 2015-02-12 21:33:32 -08:00
jdalton
9e749daefa Bump to v3.1.0. 2015-02-04 00:42:01 -08:00
100 changed files with 1641 additions and 772 deletions

View File

@@ -1,4 +1,4 @@
# lodash v3.0.1 # lodash v3.2.0
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules. The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules.
@@ -28,7 +28,7 @@ var array = require('lodash/array');
var chunk = require('lodash/array/chunk'); var chunk = require('lodash/array/chunk');
``` ```
See the [package source](https://github.com/lodash/lodash/tree/3.0.1-npm) for more details. See the [package source](https://github.com/lodash/lodash/tree/3.2.0-npm) for more details.
**Note:**<br> **Note:**<br>
Dont assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br> Dont 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. lodash is also available in a variety of other builds & module formats.
* npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds * npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.0.1-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.0.1-amd) builds * AMD modules for [modern](https://github.com/lodash/lodash/tree/3.2.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.2.0-amd) builds
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.0.1-es) build * ES modules for the [modern](https://github.com/lodash/lodash/tree/3.2.0-es) build
## Further Reading ## Further Reading
@@ -68,8 +68,9 @@ lodash is also available in a variety of other builds & module formats.
* [_.create](https://lodash.com/docs#create) for easier object inheritance * [_.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 * [_.curry](https://lodash.com/docs#curry) & [_.curryRight](https://lodash.com/docs#curryRight) for creating [curried](http://hughfdjackson.com/javascript/why-curry-helps/) functions
* [_.debounce](https://lodash.com/docs#debounce) & [_.throttle](https://lodash.com/docs#throttle) are cancelable & accept options for more control * [_.debounce](https://lodash.com/docs#debounce) & [_.throttle](https://lodash.com/docs#throttle) are cancelable & accept options for more control
* [_.fill](https://lodash.com/docs#fill) to fill arrays with values
* [_.findIndex](https://lodash.com/docs#findIndex) & [_.findKey](https://lodash.com/docs#findKey) for finding indexes & keys * [_.findIndex](https://lodash.com/docs#findIndex) & [_.findKey](https://lodash.com/docs#findKey) for finding indexes & keys
* [_.flow](https://lodash.com/docs#flow) to complement [_.flowRight](https://lodash.com/docs#flowRight) (a.k.a `_.backflow` & `_.compose`) * [_.flow](https://lodash.com/docs#flow) to complement [_.flowRight](https://lodash.com/docs#flowRight) (a.k.a `_.compose`)
* [_.forEach](https://lodash.com/docs#forEach) supports exiting early * [_.forEach](https://lodash.com/docs#forEach) supports exiting early
* [_.forIn](https://lodash.com/docs#forIn) for iterating all enumerable properties * [_.forIn](https://lodash.com/docs#forIn) for iterating all enumerable properties
* [_.forOwn](https://lodash.com/docs#forOwn) for iterating own properties * [_.forOwn](https://lodash.com/docs#forOwn) for iterating own properties
@@ -81,6 +82,7 @@ lodash is also available in a variety of other builds & module formats.
* [_.keysIn](https://lodash.com/docs#keysIn) & [_.valuesIn](https://lodash.com/docs#valuesIn) for getting keys & values of all enumerable properties * [_.keysIn](https://lodash.com/docs#keysIn) & [_.valuesIn](https://lodash.com/docs#valuesIn) for getting keys & values of all enumerable properties
* [_.mapValues](https://lodash.com/docs#mapValues) for [mapping](https://lodash.com/docs#map) values to an object * [_.mapValues](https://lodash.com/docs#mapValues) for [mapping](https://lodash.com/docs#map) values to an object
* [_.matches](https://lodash.com/docs#matches) supports deep object comparisons * [_.matches](https://lodash.com/docs#matches) supports deep object comparisons
* [_.matchesProperty](https://lodash.com/docs#matchesProperty) to complement [_.matches](https://lodash.com/docs#matches) & [_.property](https://lodash.com/docs#property)
* [_.merge](https://lodash.com/docs#merge) for a deep [_.extend](https://lodash.com/docs#extend) * [_.merge](https://lodash.com/docs#merge) for a deep [_.extend](https://lodash.com/docs#extend)
* [_.parseInt](https://lodash.com/docs#parseInt) for consistent cross-environment behavior * [_.parseInt](https://lodash.com/docs#parseInt) for consistent cross-environment behavior
* [_.propertyOf](https://lodash.com/docs#propertyOf) to complement [_.property](https://lodash.com/docs#property) * [_.propertyOf](https://lodash.com/docs#propertyOf) to complement [_.property](https://lodash.com/docs#property)
@@ -89,15 +91,15 @@ lodash is also available in a variety of other builds & module formats.
* [_.runInContext](https://lodash.com/docs#runInContext) for collisionless mixins & easier mocking * [_.runInContext](https://lodash.com/docs#runInContext) for collisionless mixins & easier mocking
* [_.slice](https://lodash.com/docs#slice) for creating subsets of array-like values * [_.slice](https://lodash.com/docs#slice) for creating subsets of array-like values
* [_.sortByAll](https://lodash.com/docs#sortBy) for sorting by multiple properties * [_.sortByAll](https://lodash.com/docs#sortBy) for sorting by multiple properties
* [_.spread](https://lodash.com/docs#spread) for creating a function to spread an array of arguments to another
* [_.support](https://lodash.com/docs#support) for flagging environment features * [_.support](https://lodash.com/docs#support) for flagging environment features
* [_.template](https://lodash.com/docs#template) supports [*“imports”*](https://lodash.com/docs#templateSettings-imports) options & [ES template delimiters](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components) * [_.template](https://lodash.com/docs#template) supports [*“imports”*](https://lodash.com/docs#templateSettings-imports) options & [ES template delimiters](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
* [_.transform](https://lodash.com/docs#transform) as a powerful alternative to [_.reduce](https://lodash.com/docs#reduce) for transforming objects * [_.transform](https://lodash.com/docs#transform) as a powerful alternative to [_.reduce](https://lodash.com/docs#reduce) for transforming objects
* [_.thru](https://lodash.com/docs#thru) to pass values thru method chains
* [_.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) * [_.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)
* [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), & * [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), &
[more](https://lodash.com/docs "_.bindKey, _.curryRight, _.partialRight") support customizable argument placeholders [more](https://lodash.com/docs "_.bindKey, _.curryRight, _.partialRight") support customizable argument placeholders
* [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), & * [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), &
[more](https://lodash.com/docs "_.camelCase, _.deburr, _.endsWith, _.escapeRegExp, _.kebabCase, _.pad, _.padLeft, _.padRight, _.repeat, _.snakeCase, _.startsWith, _.trimLeft, _.trimRight, _.trunc, _.words") string methods [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), & * [_.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 callbacks
* [_.dropWhile](https://lodash.com/docs#dropWhile), [_.takeWhile](https://lodash.com/docs#takeWhile), & * [_.dropWhile](https://lodash.com/docs#dropWhile), [_.takeWhile](https://lodash.com/docs#takeWhile), &
@@ -106,9 +108,11 @@ lodash is also available in a variety of other builds & module formats.
[more](https://lodash.com/docs "_.findLastKey, _.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.partialRight") right-associative methods [more](https://lodash.com/docs "_.findLastKey, _.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.partialRight") right-associative methods
* [_.includes](https://lodash.com/docs#includes), [_.toArray](https://lodash.com/docs#toArray), & * [_.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, _.forEach, _.forEachRight, _.groupBy, _.indexBy, _.invoke, _.map, _.max, _.min, _.partition, _.pluck, _.reduce, _.reduceRight, _.reject, _.shuffle, _.size, _.some, _.sortBy") 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 ## Support
Tested in Chrome 39-40, Firefox 34-35, IE 6-11, Opera 25-26, Safari 5-8, io.js 1.0.4, Node.js 0.8.28 & 0.10.35, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5. Tested in Chrome 39-40, Firefox 34-35, IE 6-11, Opera 26-27, Safari 5-8, io.js 1.2.0, Node.js 0.8.28, 0.10.36, & 0.12.0, 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. 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.

View File

@@ -6,6 +6,7 @@ module.exports = {
'dropRight': require('./array/dropRight'), 'dropRight': require('./array/dropRight'),
'dropRightWhile': require('./array/dropRightWhile'), 'dropRightWhile': require('./array/dropRightWhile'),
'dropWhile': require('./array/dropWhile'), 'dropWhile': require('./array/dropWhile'),
'fill': require('./array/fill'),
'findIndex': require('./array/findIndex'), 'findIndex': require('./array/findIndex'),
'findLastIndex': require('./array/findLastIndex'), 'findLastIndex': require('./array/findLastIndex'),
'first': require('./array/first'), 'first': require('./array/first'),

View File

@@ -16,7 +16,7 @@ var nativeMax = Math.max;
* @memberOf _ * @memberOf _
* @category Array * @category Array
* @param {Array} array The array to process. * @param {Array} array The array to process.
* @param {numer} [size=1] The length of each chunk. * @param {number} [size=1] The length of each chunk.
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
* @returns {Array} Returns the new array containing chunks. * @returns {Array} Returns the new array containing chunks.
* @example * @example

View File

@@ -6,7 +6,6 @@ var baseSlice = require('../internal/baseSlice'),
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop. * @param {number} [n=1] The number of elements to drop.

View File

@@ -6,7 +6,6 @@ var baseSlice = require('../internal/baseSlice'),
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop. * @param {number} [n=1] The number of elements to drop.

View File

@@ -6,20 +6,23 @@ var baseCallback = require('../internal/baseCallback'),
* Elements are dropped until `predicate` returns falsey. The predicate is * 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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * If a value is also provided for `thisArg` the created `_.matchesProperty`
* callback returns `true` for elements that have the properties of the given * 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 match the properties of the given
* object, else `false`. * object, else `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per element. * per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
@@ -28,18 +31,22 @@ var baseCallback = require('../internal/baseCallback'),
* // => [1] * // => [1]
* *
* var users = [ * var users = [
* { 'user': 'barney', 'status': 'busy', 'active': false }, * { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'status': 'busy', 'active': true }, * { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'status': 'away', 'active': true } * { 'user': 'pebbles', 'active': false }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.matches` callback shorthand
* _.pluck(_.dropRightWhile(users, 'active'), 'user'); * _.pluck(_.dropRightWhile(users, { 'user': pebbles, 'active': false }), 'user');
* // => ['barney', 'fred']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.dropRightWhile(users, 'active', false), 'user');
* // => ['barney'] * // => ['barney']
* *
* // using the "_.matches" callback shorthand * // using the `_.property` callback shorthand
* _.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user'); * _.pluck(_.dropRightWhile(users, 'active'), 'user');
* // => ['barney', 'fred'] * // => ['barney', 'fred', 'pebbles']
*/ */
function dropRightWhile(array, predicate, thisArg) { function dropRightWhile(array, predicate, thisArg) {
var length = array ? array.length : 0; var length = array ? array.length : 0;

View File

@@ -6,20 +6,23 @@ var baseCallback = require('../internal/baseCallback'),
* Elements are dropped until `predicate` returns falsey. The predicate is * 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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per element. * per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
@@ -28,18 +31,22 @@ var baseCallback = require('../internal/baseCallback'),
* // => [3] * // => [3]
* *
* var users = [ * var users = [
* { 'user': 'barney', 'status': 'busy', 'active': true }, * { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'status': 'busy', 'active': false }, * { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'status': 'away', 'active': true } * { 'user': 'pebbles', 'active': true }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.matches` callback shorthand
* _.pluck(_.dropWhile(users, 'active'), 'user'); * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
* // => ['fred', 'pebbles'] * // => ['fred', 'pebbles']
* *
* // using the "_.matches" callback shorthand * // using the `_.matchesProperty` callback shorthand
* _.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user'); * _.pluck(_.dropWhile(users, 'active', false), 'user');
* // => ['pebbles'] * // => ['pebbles']
*
* // using the `_.property` callback shorthand
* _.pluck(_.dropWhile(users, 'active'), 'user');
* // => ['barney', 'fred', 'pebbles']
*/ */
function dropWhile(array, predicate, thisArg) { function dropWhile(array, predicate, thisArg) {
var length = array ? array.length : 0; var length = array ? array.length : 0;

31
array/fill.js Normal file
View File

@@ -0,0 +1,31 @@
var baseFill = require('../internal/baseFill'),
isIterateeCall = require('../internal/isIterateeCall');
/**
* Fills elements of `array` with `value` from `start` up to, but not
* including, `end`.
*
* **Note:** This method mutates `array`.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to fill.
* @param {*} value The value to fill `array` with.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns `array`.
*/
function fill(array, value, start, end) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
start = 0;
end = length;
}
return baseFill(array, value, start, end);
}
module.exports = fill;

View File

@@ -4,10 +4,14 @@ var baseCallback = require('../internal/baseCallback');
* This method is like `_.find` except that it returns the index of the first * 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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -16,28 +20,31 @@ var baseCallback = require('../internal/baseCallback');
* @category Array * @category Array
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {number} Returns the index of the found element, else `-1`. * @returns {number} Returns the index of the found element, else `-1`.
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': false }, * { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'age': 40, 'active': true }, * { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'age': 1, 'active': false } * { 'user': 'pebbles', 'active': true }
* ]; * ];
* *
* _.findIndex(users, function(chr) { return chr.age < 40; }); * _.findIndex(users, function(chr) { return chr.user == 'barney'; });
* // => 0 * // => 0
* *
* // using the "_.matches" callback shorthand * // using the `_.matches` callback shorthand
* _.findIndex(users, { 'age': 1 }); * _.findIndex(users, { 'user': 'fred', 'active': false });
* // => 2
*
* // using the "_.property" callback shorthand
* _.findIndex(users, 'active');
* // => 1 * // => 1
*
* // using the `_.matchesProperty` callback shorthand
* _.findIndex(users, 'active', false);
* // => 0
*
* // using the `_.property` callback shorthand
* _.findIndex(users, 'active');
* // => 2
*/ */
function findIndex(array, predicate, thisArg) { function findIndex(array, predicate, thisArg) {
var index = -1, var index = -1,

View File

@@ -4,10 +4,14 @@ var baseCallback = require('../internal/baseCallback');
* This method is like `_.findIndex` except that it iterates over elements * This method is like `_.findIndex` except that it iterates over elements
* of `collection` from right to left. * of `collection` from right to left.
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -16,26 +20,29 @@ var baseCallback = require('../internal/baseCallback');
* @category Array * @category Array
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {number} Returns the index of the found element, else `-1`. * @returns {number} Returns the index of the found element, else `-1`.
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': true }, * { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }, * { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'age': 1, 'active': false } * { 'user': 'pebbles', 'active': false }
* ]; * ];
* *
* _.findLastIndex(users, function(chr) { return chr.age < 40; }); * _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; });
* // => 2 * // => 2
* *
* // using the "_.matches" callback shorthand * // using the `_.matches` callback shorthand
* _.findLastIndex(users, { 'age': 40 }); * _.findLastIndex(users, { user': 'barney', 'active': true });
* // => 0
*
* // using the `_.matchesProperty` callback shorthand
* _.findLastIndex(users, 'active', false);
* // => 1 * // => 1
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.findLastIndex(users, 'active'); * _.findLastIndex(users, 'active');
* // => 0 * // => 0
*/ */

View File

@@ -11,10 +11,14 @@ var splice = arrayProto.splice;
* and returns an array of the removed elements. The predicate is bound to * 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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -25,8 +29,7 @@ var splice = arrayProto.splice;
* @category Array * @category Array
* @param {Array} array The array to modify. * @param {Array} array The array to modify.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new array of removed elements. * @returns {Array} Returns the new array of removed elements.
* @example * @example

View File

@@ -9,10 +9,14 @@ var baseCallback = require('../internal/baseCallback'),
* to compute their sort ranking. The iteratee is bound to `thisArg` and * to compute their sort ranking. The iteratee is bound to `thisArg` and
* invoked with one argument; (value). * invoked with one argument; (value).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -22,8 +26,7 @@ var baseCallback = require('../internal/baseCallback'),
* @param {Array} array The sorted array to inspect. * @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate. * @param {*} value The value to evaluate.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {number} Returns the index at which `value` should be inserted * @returns {number} Returns the index at which `value` should be inserted
* into `array`. * into `array`.
@@ -43,7 +46,7 @@ var baseCallback = require('../internal/baseCallback'),
* }, dict); * }, dict);
* // => 1 * // => 1
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
* // => 1 * // => 1
*/ */

View File

@@ -13,8 +13,7 @@ var baseCallback = require('../internal/baseCallback'),
* @param {Array} array The sorted array to inspect. * @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate. * @param {*} value The value to evaluate.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {number} Returns the index at which `value` should be inserted * @returns {number} Returns the index at which `value` should be inserted
* into `array`. * into `array`.

View File

@@ -6,7 +6,6 @@ var baseSlice = require('../internal/baseSlice'),
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to take. * @param {number} [n=1] The number of elements to take.

View File

@@ -6,7 +6,6 @@ var baseSlice = require('../internal/baseSlice'),
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to take. * @param {number} [n=1] The number of elements to take.

View File

@@ -6,20 +6,23 @@ var baseCallback = require('../internal/baseCallback'),
* taken until `predicate` returns falsey. The predicate is bound to `thisArg` * 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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per element. * per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
@@ -28,18 +31,22 @@ var baseCallback = require('../internal/baseCallback'),
* // => [2, 3] * // => [2, 3]
* *
* var users = [ * var users = [
* { 'user': 'barney', 'status': 'busy', 'active': false }, * { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'status': 'busy', 'active': true }, * { 'user': 'fred', 'active': false },
* { 'user': 'pebbles', 'status': 'away', 'active': true } * { 'user': 'pebbles', 'active': false }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.matches` callback shorthand
* _.pluck(_.takeRightWhile(users, 'active'), 'user'); * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
* // => ['pebbles']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.takeRightWhile(users, 'active', false), 'user');
* // => ['fred', 'pebbles'] * // => ['fred', 'pebbles']
* *
* // using the "_.matches" callback shorthand * // using the `_.property` callback shorthand
* _.pluck(_.takeRightWhile(users, { 'status': 'away' }), 'user'); * _.pluck(_.takeRightWhile(users, 'active'), 'user');
* // => ['pebbles'] * // => []
*/ */
function takeRightWhile(array, predicate, thisArg) { function takeRightWhile(array, predicate, thisArg) {
var length = array ? array.length : 0; var length = array ? array.length : 0;

View File

@@ -6,20 +6,23 @@ var baseCallback = require('../internal/baseCallback'),
* are taken until `predicate` returns falsey. The predicate is bound to * 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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Array * @category Array
* @param {Array} array The array to query. * @param {Array} array The array to query.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per element. * per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
@@ -28,18 +31,22 @@ var baseCallback = require('../internal/baseCallback'),
* // => [1, 2] * // => [1, 2]
* *
* var users = [ * var users = [
* { 'user': 'barney', 'status': 'busy', 'active': true }, * { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'status': 'busy', 'active': false }, * { 'user': 'fred', 'active': false},
* { 'user': 'pebbles', 'status': 'away', 'active': true } * { 'user': 'pebbles', 'active': true }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.matches` callback shorthand
* _.pluck(_.takeWhile(users, 'active'), 'user'); * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
* // => ['barney'] * // => ['barney']
* *
* // using the "_.matches" callback shorthand * // using the `_.matchesProperty` callback shorthand
* _.pluck(_.takeWhile(users, { 'status': 'busy' }), 'user'); * _.pluck(_.takeWhile(users, 'active', false), 'user');
* // => ['barney', 'fred'] * // => ['barney', 'fred']
*
* // using the `_.property` callback shorthand
* _.pluck(_.takeWhile(users, 'active'), 'user');
* // => []
*/ */
function takeWhile(array, predicate, thisArg) { function takeWhile(array, predicate, thisArg) {
var length = array ? array.length : 0; var length = array ? array.length : 0;

View File

@@ -11,10 +11,14 @@ var baseCallback = require('../internal/baseCallback'),
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked * uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
* with three arguments; (value, index, array). * with three arguments; (value, index, array).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -30,8 +34,6 @@ var baseCallback = require('../internal/baseCallback'),
* @param {Array} array The array to inspect. * @param {Array} array The array to inspect.
* @param {boolean} [isSorted] Specify the array is sorted. * @param {boolean} [isSorted] Specify the array is sorted.
* @param {Function|Object|string} [iteratee] The function invoked per iteration. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
* If a property name or object is provided it is used to create a "_.property"
* or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new duplicate-value-free array. * @returns {Array} Returns the new duplicate-value-free array.
* @example * @example
@@ -47,7 +49,7 @@ var baseCallback = require('../internal/baseCallback'),
* _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math); * _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math);
* // => [1, 2.5] * // => [1, 2.5]
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }, { 'x': 2 }] * // => [{ 'x': 1 }, { 'x': 2 }]
*/ */

View File

@@ -1,7 +1,10 @@
module.exports = { module.exports = {
'chain': require('./chain/chain'), 'chain': require('./chain/chain'),
'commit': require('./chain/commit'),
'lodash': require('./chain/lodash'), 'lodash': require('./chain/lodash'),
'plant': require('./chain/plant'),
'reverse': require('./chain/reverse'), 'reverse': require('./chain/reverse'),
'run': require('./chain/run'),
'tap': require('./chain/tap'), 'tap': require('./chain/tap'),
'thru': require('./chain/thru'), 'thru': require('./chain/thru'),
'toJSON': require('./chain/toJSON'), 'toJSON': require('./chain/toJSON'),

View File

@@ -8,7 +8,7 @@ var lodash = require('./lodash');
* @memberOf _ * @memberOf _
* @category Chain * @category Chain
* @param {*} value The value to wrap. * @param {*} value The value to wrap.
* @returns {Object} Returns the new `lodash` object. * @returns {Object} Returns the new `lodash` wrapper instance.
* @example * @example
* *
* var users = [ * var users = [

1
chain/commit.js Normal file
View File

@@ -0,0 +1 @@
module.exports = require('./wrapperCommit');

View File

@@ -1,7 +1,8 @@
var LodashWrapper = require('../internal/LodashWrapper'), var LazyWrapper = require('../internal/LazyWrapper'),
arrayCopy = require('../internal/arrayCopy'), LodashWrapper = require('../internal/LodashWrapper'),
isArray = require('../lang/isArray'), isArray = require('../lang/isArray'),
isObjectLike = require('../internal/isObjectLike'); isObjectLike = require('../internal/isObjectLike'),
wrapperClone = require('../internal/wrapperClone');
/** Used for native method references. */ /** Used for native method references. */
var objectProto = Object.prototype; var objectProto = Object.prototype;
@@ -10,7 +11,7 @@ var objectProto = Object.prototype;
var hasOwnProperty = objectProto.hasOwnProperty; var hasOwnProperty = objectProto.hasOwnProperty;
/** /**
* Creates a `lodash` object which wraps `value` to enable intuitive chaining. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
* Methods that operate on and return arrays, collections, and functions can * Methods that operate on and return arrays, collections, and functions can
* be chained together. Methods that return a boolean or single value will * be chained together. Methods that return a boolean or single value will
* automatically end the chain returning the unwrapped value. Explicit chaining * automatically end the chain returning the unwrapped value. Explicit chaining
@@ -29,51 +30,53 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`, * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
* and `unshift` * and `unshift`
* *
* The wrapper functions that support shortcut fusion are: * The wrapper methods that support shortcut fusion are:
* `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `first`, * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
* `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, `slice`, * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `where` * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
* and `where`
* *
* The chainable wrapper functions are: * The chainable wrapper methods are:
* `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`, * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
* `callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`, * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
* `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
* `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
* `flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`, * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
* `forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`, * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
* `initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`, * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
* `mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`, * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
* `omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`, * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
* `pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
* `rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
* `sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`, * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `splice`, `spread`,
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
* `transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, * `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
* `where`, `without`, `wrap`, `xor`, `zip`, and `zipObject` * `unshift`, `unzip`, `values`, `valuesIn`, `where`, `without`, `wrap`, `xor`,
* `zip`, and `zipObject`
* *
* The wrapper functions that are **not** chainable by default are: * The wrapper methods that are **not** chainable by default are:
* `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`, * `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
* `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, * `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`,
* `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`, * `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`,
* `isFunction`, `isMatch` , `isNative`, `isNaN`, `isNull`, `isNumber`, * `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, * `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, * `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, * `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, * `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
* `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, * `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`,
* `unescape`, `uniqueId`, `value`, and `words` * `trunc`, `unescape`, `uniqueId`, `value`, and `words`
* *
* The wrapper function `sample` will return a wrapped value when `n` is provided, * The wrapper method `sample` will return a wrapped value when `n` is provided,
* otherwise an unwrapped value is returned. * otherwise an unwrapped value is returned.
* *
* @name _ * @name _
* @constructor * @constructor
* @category Chain * @category Chain
* @param {*} value The value to wrap in a `lodash` instance. * @param {*} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns a `lodash` instance. * @returns {Object} Returns the new `lodash` wrapper instance.
* @example * @example
* *
* var wrapped = _([1, 2, 3]); * var wrapped = _([1, 2, 3]);
@@ -92,18 +95,15 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* // => true * // => true
*/ */
function lodash(value) { function lodash(value) {
if (isObjectLike(value) && !isArray(value)) { if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
if (value instanceof LodashWrapper) { if (value instanceof LodashWrapper) {
return value; return value;
} }
if (hasOwnProperty.call(value, '__wrapped__')) { if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
return new LodashWrapper(value.__wrapped__, value.__chain__, arrayCopy(value.__actions__)); return wrapperClone(value);
} }
} }
return new LodashWrapper(value); return new LodashWrapper(value);
} }
// Ensure `new LodashWrapper` is an instance of `lodash`.
LodashWrapper.prototype = lodash.prototype;
module.exports = lodash; module.exports = lodash;

1
chain/plant.js Normal file
View File

@@ -0,0 +1 @@
module.exports = require('./wrapperPlant');

1
chain/run.js Normal file
View File

@@ -0,0 +1 @@
module.exports = require('./wrapperValue');

View File

@@ -6,7 +6,7 @@ var chain = require('./chain');
* @name chain * @name chain
* @memberOf _ * @memberOf _
* @category Chain * @category Chain
* @returns {*} Returns the `lodash` object. * @returns {Object} Returns the new `lodash` wrapper instance.
* @example * @example
* *
* var users = [ * var users = [

32
chain/wrapperCommit.js Normal file
View File

@@ -0,0 +1,32 @@
var LodashWrapper = require('../internal/LodashWrapper');
/**
* Executes the chained sequence and returns the wrapped result.
*
* @name commit
* @memberOf _
* @category Chain
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var array = [1, 2];
* var wrapper = _(array).push(3);
*
* console.log(array);
* // => [1, 2]
*
* wrapper = wrapper.commit();
* console.log(array);
* // => [1, 2, 3]
*
* wrapper.last();
* // => 3
*
* console.log(array);
* // => [1, 2, 3]
*/
function wrapperCommit() {
return new LodashWrapper(this.value(), this.__chain__);
}
module.exports = wrapperCommit;

45
chain/wrapperPlant.js Normal file
View File

@@ -0,0 +1,45 @@
var LodashWrapper = require('../internal/LodashWrapper'),
wrapperClone = require('../internal/wrapperClone');
/**
* Creates a clone of the chained sequence planting `value` as the wrapped value.
*
* @name plant
* @memberOf _
* @category Chain
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var array = [1, 2];
* var wrapper = _(array).map(function(value) {
* return Math.pow(value, 2);
* });
*
* var other = [3, 4];
* var otherWrapper = wrapper.plant(other);
*
* otherWrapper.value();
* // => [9, 16]
*
* wrapper.value();
* // => [1, 4]
*/
function wrapperPlant(value) {
var result,
parent = this;
while (parent instanceof LodashWrapper) {
var clone = wrapperClone(parent);
if (result) {
previous.__wrapped__ = clone;
} else {
result = clone;
}
var previous = clone;
parent = parent.__wrapped__;
}
previous.__wrapped__ = value;
return result;
}
module.exports = wrapperPlant;

View File

@@ -11,7 +11,7 @@ var LazyWrapper = require('../internal/LazyWrapper'),
* @name reverse * @name reverse
* @memberOf _ * @memberOf _
* @category Chain * @category Chain
* @returns {Object} Returns the new reversed `lodash` object. * @returns {Object} Returns the new reversed `lodash` wrapper instance.
* @example * @example
* *
* var array = [1, 2, 3]; * var array = [1, 2, 3];
@@ -28,7 +28,7 @@ function wrapperReverse() {
if (this.__actions__.length) { if (this.__actions__.length) {
value = new LazyWrapper(this); value = new LazyWrapper(this);
} }
return new LodashWrapper(value.reverse()); return new LodashWrapper(value.reverse(), this.__chain__);
} }
return this.thru(function(value) { return this.thru(function(value) {
return value.reverse(); return value.reverse();

View File

@@ -5,7 +5,7 @@ var baseWrapperValue = require('../internal/baseWrapperValue');
* *
* @name value * @name value
* @memberOf _ * @memberOf _
* @alias toJSON, valueOf * @alias run, toJSON, valueOf
* @category Chain * @category Chain
* @returns {*} Returns the resolved unwrapped value. * @returns {*} Returns the resolved unwrapped value.
* @example * @example

View File

@@ -13,10 +13,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* 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). * (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -25,8 +29,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object. * @returns {Object} Returns the composed aggregate object.
* @example * @example

View File

@@ -8,10 +8,14 @@ var arrayEvery = require('../internal/arrayEvery'),
* 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). * (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -21,27 +25,30 @@ var arrayEvery = require('../internal/arrayEvery'),
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {boolean} Returns `true` if all elements pass the predicate check, * @returns {boolean} Returns `true` if all elements pass the predicate check,
* else `false`. * else `false`.
* @example * @example
* *
* _.every([true, 1, null, 'yes']); * _.every([true, 1, null, 'yes'], Boolean);
* // => false * // => false
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36 }, * { 'user': 'barney', 'active': false },
* { 'user': 'fred', 'age': 40 } * { 'user': 'fred', 'active': false }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.matches` callback shorthand
* _.every(users, 'age'); * _.every(users, { 'user': 'barney', 'active': false });
* // => false
*
* // using the `_.matchesProperty` callback shorthand
* _.every(users, 'active', false);
* // => true * // => true
* *
* // using the "_.matches" callback shorthand * // using the `_.property` callback shorthand
* _.every(users, { 'age': 36 }); * _.every(users, 'active');
* // => false * // => false
*/ */
function every(collection, predicate, thisArg) { function every(collection, predicate, thisArg) {

View File

@@ -8,10 +8,14 @@ var arrayFilter = require('../internal/arrayFilter'),
* `predicate` returns truthy for. The predicate is bound to `thisArg` and * `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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -21,8 +25,7 @@ var arrayFilter = require('../internal/arrayFilter'),
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new filtered array. * @returns {Array} Returns the new filtered array.
* @example * @example
@@ -31,16 +34,20 @@ var arrayFilter = require('../internal/arrayFilter'),
* // => [2, 4] * // => [2, 4]
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': false }, * { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': true } * { 'user': 'fred', 'age': 40, 'active': false }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.matches` callback shorthand
* _.pluck(_.filter(users, 'active'), 'user'); * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
* // => ['barney']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.filter(users, 'active', false), 'user');
* // => ['fred'] * // => ['fred']
* *
* // using the "_.matches" callback shorthand * // using the `_.property` callback shorthand
* _.pluck(_.filter(users, { 'age': 36 }), 'user'); * _.pluck(_.filter(users, 'active'), 'user');
* // => ['barney'] * // => ['barney']
*/ */
function filter(collection, predicate, thisArg) { function filter(collection, predicate, thisArg) {

View File

@@ -9,10 +9,14 @@ var baseCallback = require('../internal/baseCallback'),
* `predicate` returns truthy for. The predicate is bound to `thisArg` and * `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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -22,28 +26,31 @@ var baseCallback = require('../internal/baseCallback'),
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to search. * @param {Array|Object|string} collection The collection to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {*} Returns the matched element, else `undefined`. * @returns {*} Returns the matched element, else `undefined`.
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': false }, * { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': true }, * { 'user': 'fred', 'age': 40, 'active': false },
* { 'user': 'pebbles', 'age': 1, 'active': false } * { 'user': 'pebbles', 'age': 1, 'active': true }
* ]; * ];
* *
* _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user'); * _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user');
* // => 'barney' * // => 'barney'
* *
* // using the "_.matches" callback shorthand * // using the `_.matches` callback shorthand
* _.result(_.find(users, { 'age': 1 }), 'user'); * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
* // => 'pebbles' * // => 'pebbles'
* *
* // using the "_.property" callback shorthand * // using the `_.matchesProperty` callback shorthand
* _.result(_.find(users, 'active'), 'user'); * _.result(_.find(users, 'active', false), 'user');
* // => 'fred' * // => 'fred'
*
* // using the `_.property` callback shorthand
* _.result(_.find(users, 'active'), 'user');
* // => 'barney'
*/ */
function find(collection, predicate, thisArg) { function find(collection, predicate, thisArg) {
if (isArray(collection)) { if (isArray(collection)) {

View File

@@ -11,8 +11,7 @@ var baseCallback = require('../internal/baseCallback'),
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to search. * @param {Array|Object|string} collection The collection to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {*} Returns the matched element, else `undefined`. * @returns {*} Returns the matched element, else `undefined`.
* @example * @example

View File

@@ -1,11 +1,16 @@
var find = require('./find'), var baseMatches = require('../internal/baseMatches'),
matches = require('../utility/matches'); find = require('./find');
/** /**
* Performs a deep comparison between each element in `collection` and the * Performs a deep comparison between each element in `collection` and the
* source object, returning the first element that has equivalent property * source object, returning the first element that has equivalent property
* values. * values.
* *
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. For comparing a single
* own or inherited property value see `_.matchesProperty`.
*
* @static * @static
* @memberOf _ * @memberOf _
* @category Collection * @category Collection
@@ -15,18 +20,18 @@ var find = require('./find'),
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'status': 'busy' }, * { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'status': 'busy' } * { 'user': 'fred', 'age': 40, 'active': false }
* ]; * ];
* *
* _.result(_.findWhere(users, { 'status': 'busy' }), 'user'); * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
* // => 'barney' * // => 'barney'
* *
* _.result(_.findWhere(users, { 'age': 40 }), 'user'); * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
* // => 'fred' * // => 'fred'
*/ */
function findWhere(collection, source) { function findWhere(collection, source) {
return find(collection, matches(source)); return find(collection, baseMatches(source));
} }
module.exports = findWhere; module.exports = findWhere;

View File

@@ -13,10 +13,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* 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). * (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -25,8 +29,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object. * @returns {Object} Returns the composed aggregate object.
* @example * @example
@@ -37,7 +40,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math); * _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math);
* // => { '4': [4.2], '6': [6.1, 6.4] } * // => { '4': [4.2], '6': [6.1, 6.4] }
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.groupBy(['one', 'two', 'three'], 'length'); * _.groupBy(['one', 'two', 'three'], 'length');
* // => { '3': ['one', 'two'], '5': ['three'] } * // => { '3': ['one', 'two'], '5': ['three'] }
*/ */

View File

@@ -7,10 +7,14 @@ var createAggregator = require('../internal/createAggregator');
* 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). * (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -19,8 +23,7 @@ var createAggregator = require('../internal/createAggregator');
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object. * @returns {Object} Returns the composed aggregate object.
* @example * @example

View File

@@ -8,21 +8,34 @@ var arrayMap = require('../internal/arrayMap'),
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three * `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 `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
* Many lodash methods are guarded to work as interatees for methods like
* `_.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`
*
* @static * @static
* @memberOf _ * @memberOf _
* @alias collect * @alias collect
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively. * create a `_.property` or `_.matches` style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new mapped array. * @returns {Array} Returns the new mapped array.
* @example * @example
@@ -38,7 +51,7 @@ var arrayMap = require('../internal/arrayMap'),
* { 'user': 'fred' } * { 'user': 'fred' }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.map(users, 'user'); * _.map(users, 'user');
* // => ['barney', 'fred'] * // => ['barney', 'fred']
*/ */

View File

@@ -8,10 +8,14 @@ var arrayMax = require('../internal/arrayMax'),
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* arguments; (value, index, collection). * arguments; (value, index, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -20,8 +24,6 @@ var arrayMax = require('../internal/arrayMax'),
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee] The function invoked per iteration. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
* If a property name or object is provided it is used to create a "_.property"
* or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the maximum value. * @returns {*} Returns the maximum value.
* @example * @example
@@ -40,7 +42,7 @@ var arrayMax = require('../internal/arrayMax'),
* _.max(users, function(chr) { return chr.age; }); * _.max(users, function(chr) { return chr.age; });
* // => { 'user': 'fred', 'age': 40 }; * // => { 'user': 'fred', 'age': 40 };
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.max(users, 'age'); * _.max(users, 'age');
* // => { 'user': 'fred', 'age': 40 }; * // => { 'user': 'fred', 'age': 40 };
*/ */

View File

@@ -8,10 +8,14 @@ var arrayMin = require('../internal/arrayMin'),
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* arguments; (value, index, collection). * arguments; (value, index, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -20,8 +24,6 @@ var arrayMin = require('../internal/arrayMin'),
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee] The function invoked per iteration. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
* If a property name or object is provided it is used to create a "_.property"
* or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the minimum value. * @returns {*} Returns the minimum value.
* @example * @example
@@ -40,7 +42,7 @@ var arrayMin = require('../internal/arrayMin'),
* _.min(users, function(chr) { return chr.age; }); * _.min(users, function(chr) { return chr.age; });
* // => { 'user': 'barney', 'age': 36 }; * // => { 'user': 'barney', 'age': 36 };
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.min(users, 'age'); * _.min(users, 'age');
* // => { 'user': 'barney', 'age': 36 }; * // => { 'user': 'barney', 'age': 36 };
*/ */

View File

@@ -6,10 +6,14 @@ var createAggregator = require('../internal/createAggregator');
* contains elements `predicate` returns falsey for. The predicate is bound * 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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -18,8 +22,7 @@ var createAggregator = require('../internal/createAggregator');
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the array of grouped elements. * @returns {Array} Returns the array of grouped elements.
* @example * @example
@@ -36,12 +39,18 @@ var createAggregator = require('../internal/createAggregator');
* { 'user': 'pebbles', 'age': 1, 'active': false } * { 'user': 'pebbles', 'age': 1, 'active': false }
* ]; * ];
* *
* // using the "_.matches" callback shorthand * var mapper = function(array) { return _.pluck(array, 'user'); };
* _.map(_.partition(users, { 'age': 1 }), function(array) { return _.pluck(array, 'user'); }); *
* // using the `_.matches` callback shorthand
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
* // => [['pebbles'], ['barney', 'fred']] * // => [['pebbles'], ['barney', 'fred']]
* *
* // using the "_.property" callback shorthand * // using the `_.matchesProperty` callback shorthand
* _.map(_.partition(users, 'active'), function(array) { return _.pluck(array, 'user'); }); * _.map(_.partition(users, 'active', false), mapper);
* // => [['barney', 'pebbles'], ['fred']]
*
* // using the `_.property` callback shorthand
* _.map(_.partition(users, 'active'), mapper);
* // => [['fred'], ['barney', 'pebbles']] * // => [['fred'], ['barney', 'pebbles']]
*/ */
var partition = createAggregator(function(result, value, key) { var partition = createAggregator(function(result, value, key) {

View File

@@ -1,5 +1,5 @@
var map = require('./map'), var baseProperty = require('../internal/baseProperty'),
property = require('../utility/property'); map = require('./map');
/** /**
* Gets the value of `key` from all elements in `collection`. * Gets the value of `key` from all elements in `collection`.
@@ -25,7 +25,7 @@ var map = require('./map'),
* // => [36, 40] (iteration order is not guaranteed) * // => [36, 40] (iteration order is not guaranteed)
*/ */
function pluck(collection, key) { function pluck(collection, key) {
return map(collection, property(key)); return map(collection, baseProperty(key));
} }
module.exports = pluck; module.exports = pluck;

View File

@@ -12,6 +12,12 @@ var arrayReduce = require('../internal/arrayReduce'),
* value. The `iteratee` is bound to `thisArg`and invoked with four arguments; * value. The `iteratee` is bound to `thisArg`and invoked with four arguments;
* (accumulator, value, index|key, collection). * (accumulator, value, index|key, collection).
* *
* Many lodash methods are guarded to work as interatees for methods like
* `_.reduce`, `_.reduceRight`, and `_.transform`.
*
* The guarded methods are:
* `assign`, `defaults`, `merge`, and `sortAllBy`
*
* @static * @static
* @memberOf _ * @memberOf _
* @alias foldl, inject * @alias foldl, inject

View File

@@ -7,10 +7,14 @@ var arrayFilter = require('../internal/arrayFilter'),
* The opposite of `_.filter`; this method returns the elements of `collection` * The opposite of `_.filter`; this method returns the elements of `collection`
* that `predicate` does **not** return truthy for. * that `predicate` does **not** return truthy for.
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -19,8 +23,7 @@ var arrayFilter = require('../internal/arrayFilter'),
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new filtered array. * @returns {Array} Returns the new filtered array.
* @example * @example
@@ -33,13 +36,17 @@ var arrayFilter = require('../internal/arrayFilter'),
* { 'user': 'fred', 'age': 40, 'active': true } * { 'user': 'fred', 'age': 40, 'active': true }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.matches` callback shorthand
* _.pluck(_.reject(users, 'active'), 'user'); * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
* // => ['barney'] * // => ['barney']
* *
* // using the "_.matches" callback shorthand * // using the `_.matchesProperty` callback shorthand
* _.pluck(_.reject(users, { 'age': 36 }), 'user'); * _.pluck(_.reject(users, 'active', false), 'user');
* // => ['fred'] * // => ['fred']
*
* // using the `_.property` callback shorthand
* _.pluck(_.reject(users, 'active'), 'user');
* // => ['barney']
*/ */
function reject(collection, predicate, thisArg) { function reject(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayFilter : baseFilter; var func = isArray(collection) ? arrayFilter : baseFilter;

View File

@@ -9,10 +9,14 @@ var arraySome = require('../internal/arraySome'),
* over the entire collection. The predicate is bound to `thisArg` and invoked * 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" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -22,8 +26,7 @@ var arraySome = require('../internal/arraySome'),
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {boolean} Returns `true` if any element passes the predicate check, * @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`. * else `false`.
@@ -33,17 +36,21 @@ var arraySome = require('../internal/arraySome'),
* // => true * // => true
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': false }, * { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'age': 40, 'active': true } * { 'user': 'fred', 'active': false }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.matches` callback shorthand
* _.some(users, 'active'); * _.some(users, { user': 'barney', 'active': false });
* // => false
*
* // using the `_.matchesProperty` callback shorthand
* _.some(users, 'active', false);
* // => true * // => true
* *
* // using the "_.matches" callback shorthand * // using the `_.property` callback shorthand
* _.some(users, { 'age': 1 }); * _.some(users, 'active');
* // => false * // => true
*/ */
function some(collection, predicate, thisArg) { function some(collection, predicate, thisArg) {
var func = isArray(collection) ? arraySome : baseSome; var func = isArray(collection) ? arraySome : baseSome;

View File

@@ -12,10 +12,14 @@ var baseCallback = require('../internal/baseCallback'),
* 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). * (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -25,7 +29,7 @@ var baseCallback = require('../internal/baseCallback'),
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Array|Function|Object|string} [iteratee=_.identity] The function * @param {Array|Function|Object|string} [iteratee=_.identity] The function
* invoked per iteration. If a property name or an object is provided it is * invoked per iteration. If a property name or an object is provided it is
* used to create a "_.property" or "_.matches" style callback respectively. * used to create a `_.property` or `_.matches` style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new sorted array. * @returns {Array} Returns the new sorted array.
* @example * @example
@@ -42,7 +46,7 @@ var baseCallback = require('../internal/baseCallback'),
* { 'user': 'barney' } * { 'user': 'barney' }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.pluck(_.sortBy(users, 'user'), 'user'); * _.pluck(_.sortBy(users, 'user'), 'user');
* // => ['barney', 'fred', 'pebbles'] * // => ['barney', 'fred', 'pebbles']
*/ */

View File

@@ -38,7 +38,7 @@ function sortByAll(collection) {
props = baseFlatten(args, false, false, 1), props = baseFlatten(args, false, false, 1),
result = isLength(length) ? Array(length) : []; result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value, key, collection) { baseEach(collection, function(value) {
var length = props.length, var length = props.length,
criteria = Array(length); criteria = Array(length);

View File

@@ -1,11 +1,16 @@
var filter = require('./filter'), var baseMatches = require('../internal/baseMatches'),
matches = require('../utility/matches'); filter = require('./filter');
/** /**
* Performs a deep comparison between each element in `collection` and the * Performs a deep comparison between each element in `collection` and the
* source object, returning an array of all elements that have equivalent * source object, returning an array of all elements that have equivalent
* property values. * property values.
* *
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. For comparing a single
* own or inherited property value see `_.matchesProperty`.
*
* @static * @static
* @memberOf _ * @memberOf _
* @category Collection * @category Collection
@@ -15,21 +20,18 @@ var filter = require('./filter'),
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'status': 'busy', 'pets': ['hoppy'] }, * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
* { 'user': 'fred', 'age': 40, 'status': 'busy', 'pets': ['baby puss', 'dino'] } * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
* ]; * ];
* *
* _.pluck(_.where(users, { 'age': 36 }), 'user'); * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
* // => ['barney'] * // => ['barney']
* *
* _.pluck(_.where(users, { 'pets': ['dino'] }), 'user'); * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
* // => ['fred'] * // => ['fred']
*
* _.pluck(_.where(users, { 'status': 'busy' }), 'user');
* // => ['barney', 'fred']
*/ */
function where(collection, source) { function where(collection, source) {
return filter(collection, matches(source)); return filter(collection, baseMatches(source));
} }
module.exports = where; module.exports = where;

View File

@@ -20,6 +20,7 @@ module.exports = {
'partial': require('./function/partial'), 'partial': require('./function/partial'),
'partialRight': require('./function/partialRight'), 'partialRight': require('./function/partialRight'),
'rearg': require('./function/rearg'), 'rearg': require('./function/rearg'),
'spread': require('./function/spread'),
'throttle': require('./function/throttle'), 'throttle': require('./function/throttle'),
'wrap': require('./function/wrap') 'wrap': require('./function/wrap')
}; };

View File

@@ -1,5 +1,3 @@
var isFunction = require('../lang/isFunction');
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function'; var FUNC_ERROR_TEXT = 'Expected a function';
@@ -30,8 +28,8 @@ var nativeIsFinite = global.isFinite;
* // => logs 'done saving!' after the two async saves have completed * // => logs 'done saving!' after the two async saves have completed
*/ */
function after(n, func) { function after(n, func) {
if (!isFunction(func)) { if (typeof func != 'function') {
if (isFunction(n)) { if (typeof n == 'function') {
var temp = n; var temp = n;
n = func; n = func;
func = temp; func = temp;

View File

@@ -1,5 +1,3 @@
var isFunction = require('../lang/isFunction');
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function'; var FUNC_ERROR_TEXT = 'Expected a function';
@@ -21,8 +19,8 @@ var FUNC_ERROR_TEXT = 'Expected a function';
*/ */
function before(n, func) { function before(n, func) {
var result; var result;
if (!isFunction(func)) { if (typeof func != 'function') {
if (isFunction(n)) { if (typeof n == 'function') {
var temp = n; var temp = n;
n = func; n = func;
func = temp; func = temp;

View File

@@ -1,5 +1,4 @@
var isFunction = require('../lang/isFunction'), var isObject = require('../lang/isObject'),
isObject = require('../lang/isObject'),
now = require('../date/now'); now = require('../date/now');
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
@@ -82,7 +81,7 @@ function debounce(func, wait, options) {
maxWait = false, maxWait = false,
trailing = true; trailing = true;
if (!isFunction(func)) { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
wait = wait < 0 ? 0 : wait; wait = wait < 0 ? 0 : wait;

View File

@@ -33,7 +33,7 @@ function flow() {
length = funcs.length; length = funcs.length;
if (!length) { if (!length) {
return function() {}; return function() { return arguments[0]; };
} }
if (!arrayEvery(funcs, isFunction)) { if (!arrayEvery(funcs, isFunction)) {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);

View File

@@ -33,7 +33,7 @@ function flowRight() {
fromIndex = funcs.length - 1; fromIndex = funcs.length - 1;
if (fromIndex < 0) { if (fromIndex < 0) {
return function() {}; return function() { return arguments[0]; };
} }
if (!arrayEvery(funcs, isFunction)) { if (!arrayEvery(funcs, isFunction)) {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);

View File

@@ -1,5 +1,4 @@
var MapCache = require('../internal/MapCache'), var MapCache = require('../internal/MapCache');
isFunction = require('../lang/isFunction');
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function'; var FUNC_ERROR_TEXT = 'Expected a function';
@@ -58,7 +57,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* // => { 'user': 'barney' } * // => { 'user': 'barney' }
*/ */
function memoize(func, resolver) { function memoize(func, resolver) {
if (!isFunction(func) || (resolver && !isFunction(resolver))) { if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
var memoized = function() { var memoized = function() {

View File

@@ -1,5 +1,3 @@
var isFunction = require('../lang/isFunction');
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function'; var FUNC_ERROR_TEXT = 'Expected a function';
@@ -23,7 +21,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* // => [1, 3, 5] * // => [1, 3, 5]
*/ */
function negate(predicate) { function negate(predicate) {
if (!isFunction(predicate)) { if (typeof predicate != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
return function() { return function() {

View File

@@ -7,7 +7,6 @@ var before = require('./before');
* *
* @static * @static
* @memberOf _ * @memberOf _
* @type Function
* @category Function * @category Function
* @param {Function} func The function to restrict. * @param {Function} func The function to restrict.
* @returns {Function} Returns the new restricted function. * @returns {Function} Returns the new restricted function.

43
function/spread.js Normal file
View File

@@ -0,0 +1,43 @@
/** Used as the `TypeError` message for "Functions" methods. */
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).
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to spread arguments over.
* @returns {*} Returns the new function.
* @example
*
* var spread = _.spread(function(who, what) {
* return who + ' says ' + what;
* });
*
* spread(['Fred', 'hello']);
* // => 'Fred says hello'
*
* // with a Promise
* var numbers = Promise.all([
* Promise.resolve(40),
* Promise.resolve(36)
* ]);
*
* numbers.then(_.spread(function(x, y) {
* return x + y;
* }));
* // => a Promise of 76
*/
function spread(func) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function(array) {
return func.apply(this, array);
};
}
module.exports = spread;

View File

@@ -1,5 +1,4 @@
var debounce = require('./debounce'), var debounce = require('./debounce'),
isFunction = require('../lang/isFunction'),
isObject = require('../lang/isObject'); isObject = require('../lang/isObject');
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
@@ -54,7 +53,7 @@ function throttle(func, wait, options) {
var leading = true, var leading = true,
trailing = true; trailing = true;
if (!isFunction(func)) { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
if (options === false) { if (options === false) {

1182
index.js

File diff suppressed because it is too large Load Diff

View File

@@ -8,14 +8,14 @@ var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
* @param {*} value The value to wrap. * @param {*} value The value to wrap.
*/ */
function LazyWrapper(value) { function LazyWrapper(value) {
this.actions = null; this.__wrapped__ = value;
this.dir = 1; this.__actions__ = null;
this.dropCount = 0; this.__dir__ = 1;
this.filtered = false; this.__dropCount__ = 0;
this.iteratees = null; this.__filtered__ = false;
this.takeCount = POSITIVE_INFINITY; this.__iteratees__ = null;
this.views = null; this.__takeCount__ = POSITIVE_INFINITY;
this.wrapped = value; this.__views__ = null;
} }
module.exports = LazyWrapper; module.exports = LazyWrapper;

View File

@@ -7,9 +7,9 @@
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
*/ */
function LodashWrapper(value, chainAll, actions) { function LodashWrapper(value, chainAll, actions) {
this.__wrapped__ = value;
this.__actions__ = actions || []; this.__actions__ = actions || [];
this.__chain__ = !!chainAll; this.__chain__ = !!chainAll;
this.__wrapped__ = value;
} }
module.exports = LodashWrapper; module.exports = LodashWrapper;

View File

@@ -17,7 +17,7 @@ function baseAssign(object, source, customizer) {
return baseCopy(source, object, props); return baseCopy(source, object, props);
} }
var index = -1, var index = -1,
length = props.length length = props.length;
while (++index < length) { while (++index < length) {
var key = props[index], var key = props[index],

View File

@@ -1,4 +1,5 @@
var baseMatches = require('./baseMatches'), var baseMatches = require('./baseMatches'),
baseMatchesProperty = require('./baseMatchesProperty'),
baseProperty = require('./baseProperty'), baseProperty = require('./baseProperty'),
bindCallback = require('./bindCallback'), bindCallback = require('./bindCallback'),
identity = require('../utility/identity'), identity = require('../utility/identity'),
@@ -24,10 +25,12 @@ function baseCallback(func, thisArg, argCount) {
if (func == null) { if (func == null) {
return identity; return identity;
} }
// Handle "_.property" and "_.matches" style callback shorthands. if (type == 'object') {
return type == 'object' return baseMatches(func);
? baseMatches(func, !argCount) }
: baseProperty(func + ''); return typeof thisArg == 'undefined'
? baseProperty(func + '')
: baseMatchesProperty(func + '', thisArg);
} }
module.exports = baseCallback; module.exports = baseCallback;

View File

@@ -1,5 +1,4 @@
var baseSlice = require('./baseSlice'), var baseSlice = require('./baseSlice');
isFunction = require('../lang/isFunction');
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function'; var FUNC_ERROR_TEXT = 'Expected a function';
@@ -15,7 +14,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* @returns {number} Returns the timer id. * @returns {number} Returns the timer id.
*/ */
function baseDelay(func, wait, args, fromIndex) { function baseDelay(func, wait, args, fromIndex) {
if (!isFunction(func)) { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait); return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);

31
internal/baseFill.js Normal file
View File

@@ -0,0 +1,31 @@
/**
* The base implementation of `_.fill` without an iteratee call guard.
*
* @private
* @param {Array} array The array to fill.
* @param {*} value The value to fill `array` with.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns `array`.
*/
function baseFill(array, value, start, end) {
var length = array.length;
start = start == null ? 0 : (+start || 0);
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
if (end < 0) {
end += length;
}
length = start > end ? 0 : end >>> 0;
start >>>= 0;
while (start < length) {
array[start++] = value;
}
return array;
}
module.exports = baseFill;

View File

@@ -11,7 +11,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* shorthands or `this` binding. * shorthands or `this` binding.
* *
* @private * @private
* @param {Object} source The object to inspect. * @param {Object} object The object to inspect.
* @param {Array} props The source property names to match. * @param {Array} props The source property names to match.
* @param {Array} values The source values to match. * @param {Array} values The source values to match.
* @param {Array} strictCompareFlags Strict comparison flags for source values. * @param {Array} strictCompareFlags Strict comparison flags for source values.

View File

@@ -1,5 +1,4 @@
var baseClone = require('./baseClone'), var baseIsMatch = require('./baseIsMatch'),
baseIsMatch = require('./baseIsMatch'),
isStrictComparable = require('./isStrictComparable'), isStrictComparable = require('./isStrictComparable'),
keys = require('../object/keys'); keys = require('../object/keys');
@@ -10,15 +9,13 @@ var objectProto = Object.prototype;
var hasOwnProperty = objectProto.hasOwnProperty; var hasOwnProperty = objectProto.hasOwnProperty;
/** /**
* The base implementation of `_.matches` which supports specifying whether * The base implementation of `_.matches` which does not clone `source`.
* `source` should be cloned.
* *
* @private * @private
* @param {Object} source The object of property values to match. * @param {Object} source The object of property values to match.
* @param {boolean} [isCloned] Specify cloning the source object.
* @returns {Function} Returns the new function. * @returns {Function} Returns the new function.
*/ */
function baseMatches(source, isCloned) { function baseMatches(source) {
var props = keys(source), var props = keys(source),
length = props.length; length = props.length;
@@ -28,13 +25,10 @@ function baseMatches(source, isCloned) {
if (isStrictComparable(value)) { if (isStrictComparable(value)) {
return function(object) { return function(object) {
return object != null && value === object[key] && hasOwnProperty.call(object, key); return object != null && object[key] === value && hasOwnProperty.call(object, key);
}; };
} }
} }
if (isCloned) {
source = baseClone(source, true);
}
var values = Array(length), var values = Array(length),
strictCompareFlags = Array(length); strictCompareFlags = Array(length);

View File

@@ -0,0 +1,24 @@
var baseIsEqual = require('./baseIsEqual'),
isStrictComparable = require('./isStrictComparable');
/**
* The base implementation of `_.matchesProperty` which does not coerce `key`
* to a string.
*
* @private
* @param {string} key The key of the property to get.
* @param {*} value The value to compare.
* @returns {Function} Returns the new function.
*/
function baseMatchesProperty(key, value) {
if (isStrictComparable(value)) {
return function(object) {
return object != null && object[key] === value;
};
}
return function(object) {
return object != null && baseIsEqual(value, object[key], null, true);
};
}
module.exports = baseMatchesProperty;

View File

@@ -16,7 +16,7 @@ function baseReduce(collection, iteratee, accumulator, initFromCollection, eachF
eachFunc(collection, function(value, index, collection) { eachFunc(collection, function(value, index, collection) {
accumulator = initFromCollection accumulator = initFromCollection
? (initFromCollection = false, value) ? (initFromCollection = false, value)
: iteratee(accumulator, value, index, collection) : iteratee(accumulator, value, index, collection);
}); });
return accumulator; return accumulator;
} }

View File

@@ -5,8 +5,7 @@ var baseCallback = require('./baseCallback'),
/** /**
* Creates a function that aggregates a collection, creating an accumulator * Creates a function that aggregates a collection, creating an accumulator
* object composed from the results of running each element in the collection * object composed from the results of running each element in the collection
* through an iteratee. The `setter` sets the keys and values of the accumulator * through an iteratee.
* object. If `initializer` is provided initializes the accumulator object.
* *
* @private * @private
* @param {Function} setter The function to set keys and values of the accumulator object. * @param {Function} setter The function to set keys and values of the accumulator object.

View File

@@ -3,7 +3,6 @@ var baseSetData = require('./baseSetData'),
createHybridWrapper = require('./createHybridWrapper'), createHybridWrapper = require('./createHybridWrapper'),
createPartialWrapper = require('./createPartialWrapper'), createPartialWrapper = require('./createPartialWrapper'),
getData = require('./getData'), getData = require('./getData'),
isFunction = require('../lang/isFunction'),
mergeData = require('./mergeData'), mergeData = require('./mergeData'),
setData = require('./setData'); setData = require('./setData');
@@ -46,7 +45,7 @@ var nativeMax = Math.max;
*/ */
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
var isBindKey = bitmask & BIND_KEY_FLAG; var isBindKey = bitmask & BIND_KEY_FLAG;
if (!isBindKey && !isFunction(func)) { if (!isBindKey && typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
var length = partials ? partials.length : 0; var length = partials ? partials.length : 0;
@@ -76,9 +75,9 @@ function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, a
if (bitmask == BIND_FLAG) { if (bitmask == BIND_FLAG) {
var result = createBindWrapper(newData[0], newData[2]); var result = createBindWrapper(newData[0], newData[2]);
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) { } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
result = createPartialWrapper.apply(null, newData); result = createPartialWrapper.apply(undefined, newData);
} else { } else {
result = createHybridWrapper.apply(null, newData); result = createHybridWrapper.apply(undefined, newData);
} }
var setter = data ? baseSetData : setData; var setter = data ? baseSetData : setData;
return setter(result, newData); return setter(result, newData);

View File

@@ -1,6 +1,6 @@
/** /**
* Used as the maximum length of an array-like value. * Used as the maximum length of an array-like value.
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
* for more details. * for more details.
*/ */
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;

View File

@@ -20,7 +20,7 @@ function isIterateeCall(value, index, object) {
var length = object.length, var length = object.length,
prereq = isLength(length) && isIndex(index, length); prereq = isLength(length) && isIndex(index, length);
} else { } else {
prereq = type == 'string' && index in value; prereq = type == 'string' && index in object;
} }
return prereq && object[index] === value; return prereq && object[index] === value;
} }

View File

@@ -1,6 +1,6 @@
/** /**
* Used as the maximum length of an array-like value. * Used as the maximum length of an array-like value.
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) * See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
* for more details. * for more details.
*/ */
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
@@ -8,6 +8,10 @@ var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
/** /**
* Checks if `value` is a valid array-like length. * Checks if `value` is a valid array-like length.
* *
* **Note:** This function is based on ES `ToLength`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
* for more details.
*
* @private * @private
* @param {*} value The value to check. * @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.

View File

@@ -10,18 +10,18 @@ var LazyWrapper = require('./LazyWrapper'),
* @returns {Object} Returns the cloned `LazyWrapper` object. * @returns {Object} Returns the cloned `LazyWrapper` object.
*/ */
function lazyClone() { function lazyClone() {
var actions = this.actions, var actions = this.__actions__,
iteratees = this.iteratees, iteratees = this.__iteratees__,
views = this.views, views = this.__views__,
result = new LazyWrapper(this.wrapped); result = new LazyWrapper(this.__wrapped__);
result.actions = actions ? arrayCopy(actions) : null; result.__actions__ = actions ? arrayCopy(actions) : null;
result.dir = this.dir; result.__dir__ = this.__dir__;
result.dropCount = this.dropCount; result.__dropCount__ = this.__dropCount__;
result.filtered = this.filtered; result.__filtered__ = this.__filtered__;
result.iteratees = iteratees ? arrayCopy(iteratees) : null; result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
result.takeCount = this.takeCount; result.__takeCount__ = this.__takeCount__;
result.views = views ? arrayCopy(views) : null; result.__views__ = views ? arrayCopy(views) : null;
return result; return result;
} }

View File

@@ -9,13 +9,13 @@ var LazyWrapper = require('./LazyWrapper');
* @returns {Object} Returns the new reversed `LazyWrapper` object. * @returns {Object} Returns the new reversed `LazyWrapper` object.
*/ */
function lazyReverse() { function lazyReverse() {
if (this.filtered) { if (this.__filtered__) {
var result = new LazyWrapper(this); var result = new LazyWrapper(this);
result.dir = -1; result.__dir__ = -1;
result.filtered = true; result.__filtered__ = true;
} else { } else {
result = this.clone(); result = this.clone();
result.dir *= -1; result.__dir__ *= -1;
} }
return result; return result;
} }

View File

@@ -18,20 +18,20 @@ var nativeMin = Math.min;
* @returns {*} Returns the unwrapped value. * @returns {*} Returns the unwrapped value.
*/ */
function lazyValue() { function lazyValue() {
var array = this.wrapped.value(); var array = this.__wrapped__.value();
if (!isArray(array)) { if (!isArray(array)) {
return baseWrapperValue(array, this.actions); return baseWrapperValue(array, this.__actions__);
} }
var dir = this.dir, var dir = this.__dir__,
isRight = dir < 0, isRight = dir < 0,
view = getView(0, array.length, this.views), view = getView(0, array.length, this.__views__),
start = view.start, start = view.start,
end = view.end, end = view.end,
length = end - start, length = end - start,
dropCount = this.dropCount, dropCount = this.__dropCount__,
takeCount = nativeMin(length, this.takeCount - dropCount), takeCount = nativeMin(length, this.__takeCount__),
index = isRight ? end : start - 1, index = isRight ? end : start - 1,
iteratees = this.iteratees, iteratees = this.__iteratees__,
iterLength = iteratees ? iteratees.length : 0, iterLength = iteratees ? iteratees.length : 0,
resIndex = 0, resIndex = 0,
result = []; result = [];

18
internal/wrapperClone.js Normal file
View File

@@ -0,0 +1,18 @@
var LazyWrapper = require('./LazyWrapper'),
LodashWrapper = require('./LodashWrapper'),
arrayCopy = require('./arrayCopy');
/**
* Creates a clone of `wrapper`.
*
* @private
* @param {Object} wrapper The wrapper to clone.
* @returns {Object} Returns the cloned wrapper.
*/
function wrapperClone(wrapper) {
return wrapper instanceof LazyWrapper
? wrapper.clone()
: new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
}
module.exports = wrapperClone;

View File

@@ -10,7 +10,8 @@ var baseIsEqual = require('../internal/baseIsEqual'),
* arguments; (value, other [, index|key]). * arguments; (value, other [, index|key]).
* *
* **Note:** This method supports comparing arrays, booleans, `Date` objects, * **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Functions and DOM nodes * numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. Functions and DOM nodes
* are **not** supported. Provide a customizer function to extend support * are **not** supported. Provide a customizer function to extend support
* for comparing other values. * for comparing other values.
* *

View File

@@ -24,7 +24,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @static * @static
* @memberOf _ * @memberOf _
* @category Lang * @category Lang
* @param {Object} source The object to inspect. * @param {Object} object The object to inspect.
* @param {Object} source The object of property values to match. * @param {Object} source The object of property values to match.
* @param {Function} [customizer] The function to customize comparing values. * @param {Function} [customizer] The function to customize comparing values.
* @param {*} [thisArg] The `this` binding of `customizer`. * @param {*} [thisArg] The `this` binding of `customizer`.

View File

@@ -6,10 +6,14 @@ var baseCallback = require('../internal/baseCallback'),
* This method is like `_.findIndex` except that it returns the key of the * This method is like `_.findIndex` except that it returns the key of the
* first element `predicate` returns truthy for, instead of the element itself. * first element `predicate` returns truthy for, instead of the element itself.
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -18,8 +22,7 @@ var baseCallback = require('../internal/baseCallback'),
* @category Object * @category Object
* @param {Object} object The object to search. * @param {Object} object The object to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {string|undefined} Returns the key of the matched element, else `undefined`. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
* @example * @example
@@ -33,11 +36,15 @@ var baseCallback = require('../internal/baseCallback'),
* _.findKey(users, function(chr) { return chr.age < 40; }); * _.findKey(users, function(chr) { return chr.age < 40; });
* // => 'barney' (iteration order is not guaranteed) * // => 'barney' (iteration order is not guaranteed)
* *
* // using the "_.matches" callback shorthand * // using the `_.matches` callback shorthand
* _.findKey(users, { 'age': 1 }); * _.findKey(users, { 'age': 1, 'active': true });
* // => 'pebbles' * // => 'pebbles'
* *
* // using the "_.property" callback shorthand * // using the `_.matchesProperty` callback shorthand
* _.findKey(users, 'active', false);
* // => 'fred'
*
* // using the `_.property` callback shorthand
* _.findKey(users, 'active'); * _.findKey(users, 'active');
* // => 'barney' * // => 'barney'
*/ */

View File

@@ -6,10 +6,14 @@ var baseCallback = require('../internal/baseCallback'),
* This method is like `_.findKey` except that it iterates over elements of * This method is like `_.findKey` except that it iterates over elements of
* a collection in the opposite order. * a collection in the opposite order.
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * 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 * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -18,8 +22,7 @@ var baseCallback = require('../internal/baseCallback'),
* @category Object * @category Object
* @param {Object} object The object to search. * @param {Object} object The object to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {string|undefined} Returns the key of the matched element, else `undefined`. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
* @example * @example
@@ -33,11 +36,15 @@ var baseCallback = require('../internal/baseCallback'),
* _.findLastKey(users, function(chr) { return chr.age < 40; }); * _.findLastKey(users, function(chr) { return chr.age < 40; });
* // => returns `pebbles` assuming `_.findKey` returns `barney` * // => returns `pebbles` assuming `_.findKey` returns `barney`
* *
* // using the "_.matches" callback shorthand * // using the `_.matches` callback shorthand
* _.findLastKey(users, { 'age': 36 }); * _.findLastKey(users, { 'age': 36, 'active': true });
* // => 'barney' * // => 'barney'
* *
* // using the "_.property" callback shorthand * // using the `_.matchesProperty` callback shorthand
* _.findLastKey(users, 'active', false);
* // => 'fred'
*
* // using the `_.property` callback shorthand
* _.findLastKey(users, 'active'); * _.findLastKey(users, 'active');
* // => 'pebbles' * // => 'pebbles'
*/ */

View File

@@ -46,7 +46,7 @@ function keysIn(object) {
var Ctor = object.constructor, var Ctor = object.constructor,
index = -1, index = -1,
isProto = typeof Ctor == 'function' && Ctor.prototype == object, isProto = typeof Ctor == 'function' && Ctor.prototype === object,
result = Array(length), result = Array(length),
skipIndexes = length > 0; skipIndexes = length > 0;

View File

@@ -7,10 +7,14 @@ var baseCallback = require('../internal/baseCallback'),
* iteratee function is bound to `thisArg` and invoked with three arguments; * iteratee function is bound to `thisArg` and invoked with three arguments;
* (value, key, object). * (value, key, object).
* *
* If a property name is provided for `iteratee` the created "_.property" * If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `iteratee` the created "_.matches" style * 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 `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -19,8 +23,7 @@ var baseCallback = require('../internal/baseCallback'),
* @category Object * @category Object
* @param {Object} object The object to iterate over. * @param {Object} object The object to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the new mapped object. * @returns {Object} Returns the new mapped object.
* @example * @example
@@ -33,7 +36,7 @@ var baseCallback = require('../internal/baseCallback'),
* 'pebbles': { 'user': 'pebbles', 'age': 1 } * 'pebbles': { 'user': 'pebbles', 'age': 1 }
* }; * };
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.mapValues(users, 'age'); * _.mapValues(users, 'age');
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*/ */

View File

@@ -3,6 +3,7 @@ var arrayEach = require('../internal/arrayEach'),
baseCreate = require('../internal/baseCreate'), baseCreate = require('../internal/baseCreate'),
baseForOwn = require('../internal/baseForOwn'), baseForOwn = require('../internal/baseForOwn'),
isArray = require('../lang/isArray'), isArray = require('../lang/isArray'),
isFunction = require('../lang/isFunction'),
isObject = require('../lang/isObject'), isObject = require('../lang/isObject'),
isTypedArray = require('../lang/isTypedArray'); isTypedArray = require('../lang/isTypedArray');
@@ -47,7 +48,7 @@ function transform(object, iteratee, accumulator, thisArg) {
if (isArr) { if (isArr) {
accumulator = isArray(object) ? new Ctor : []; accumulator = isArray(object) ? new Ctor : [];
} else { } else {
accumulator = baseCreate(typeof Ctor == 'function' && Ctor.prototype); accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype);
} }
} else { } else {
accumulator = {}; accumulator = {};

View File

@@ -1,6 +1,6 @@
{ {
"name": "lodash", "name": "lodash",
"version": "3.0.1", "version": "3.2.0",
"description": "The modern build of lodash modular utilities.", "description": "The modern build of lodash modular utilities.",
"homepage": "https://lodash.com/", "homepage": "https://lodash.com/",
"icon": "https://lodash.com/icon.svg", "icon": "https://lodash.com/icon.svg",

View File

@@ -12,6 +12,7 @@ module.exports = {
'parseInt': require('./string/parseInt'), 'parseInt': require('./string/parseInt'),
'repeat': require('./string/repeat'), 'repeat': require('./string/repeat'),
'snakeCase': require('./string/snakeCase'), 'snakeCase': require('./string/snakeCase'),
'startCase': require('./string/startCase'),
'startsWith': require('./string/startsWith'), 'startsWith': require('./string/startsWith'),
'template': require('./string/template'), 'template': require('./string/template'),
'templateSettings': require('./string/templateSettings'), 'templateSettings': require('./string/templateSettings'),

View File

@@ -22,7 +22,7 @@ var createCompounder = require('../internal/createCompounder');
*/ */
var camelCase = createCompounder(function(result, word, index) { var camelCase = createCompounder(function(result, word, index) {
word = word.toLowerCase(); word = word.toLowerCase();
return index ? (result + word.charAt(0).toUpperCase() + word.slice(1)) : word; return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
}); });
module.exports = camelCase; module.exports = camelCase;

View File

@@ -14,10 +14,10 @@ var createCompounder = require('../internal/createCompounder');
* _.snakeCase('Foo Bar'); * _.snakeCase('Foo Bar');
* // => 'foo_bar' * // => 'foo_bar'
* *
* _.snakeCase('--foo-bar'); * _.snakeCase('fooBar');
* // => 'foo_bar' * // => 'foo_bar'
* *
* _.snakeCase('fooBar'); * _.snakeCase('--foo-bar');
* // => 'foo_bar' * // => 'foo_bar'
*/ */
var snakeCase = createCompounder(function(result, word, index) { var snakeCase = createCompounder(function(result, word, index) {

28
string/startCase.js Normal file
View File

@@ -0,0 +1,28 @@
var createCompounder = require('../internal/createCompounder');
/**
* Converts `string` to start case.
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage)
* for more details.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the start cased string.
* @example
*
* _.startCase('--foo-bar');
* // => 'Foo Bar'
*
* _.startCase('fooBar');
* // => 'Foo Bar'
*
* _.startCase('__foo_bar__');
* // => 'Foo Bar'
*/
var startCase = createCompounder(function(result, word, index) {
return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
});
module.exports = startCase;

View File

@@ -35,7 +35,7 @@ function trim(string, chars, guard) {
if (guard ? isIterateeCall(value, chars, guard) : chars == null) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1); return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
} }
chars = baseToString(chars); chars = (chars + '');
return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1); return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
} }

View File

@@ -28,9 +28,9 @@ function trimLeft(string, chars, guard) {
return string; return string;
} }
if (guard ? isIterateeCall(value, chars, guard) : chars == null) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(trimmedLeftIndex(string)) return string.slice(trimmedLeftIndex(string));
} }
return string.slice(charsLeftIndex(string, baseToString(chars))); return string.slice(charsLeftIndex(string, (chars + '')));
} }
module.exports = trimLeft; module.exports = trimLeft;

View File

@@ -28,9 +28,9 @@ function trimRight(string, chars, guard) {
return string; return string;
} }
if (guard ? isIterateeCall(value, chars, guard) : chars == null) { if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
return string.slice(0, trimmedRightIndex(string) + 1) return string.slice(0, trimmedRightIndex(string) + 1);
} }
return string.slice(0, charsRightIndex(string, baseToString(chars)) + 1); return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
} }
module.exports = trimRight; module.exports = trimRight;

View File

@@ -5,6 +5,7 @@ module.exports = {
'identity': require('./utility/identity'), 'identity': require('./utility/identity'),
'iteratee': require('./utility/iteratee'), 'iteratee': require('./utility/iteratee'),
'matches': require('./utility/matches'), 'matches': require('./utility/matches'),
'matchesProperty': require('./utility/matchesProperty'),
'mixin': require('./utility/mixin'), 'mixin': require('./utility/mixin'),
'noop': require('./utility/noop'), 'noop': require('./utility/noop'),
'property': require('./utility/property'), 'property': require('./utility/property'),

View File

@@ -1,8 +1,9 @@
var isError = require('../lang/isError'); var baseSlice = require('../internal/baseSlice'),
isError = require('../lang/isError');
/** /**
* Attempts to invoke `func`, returning either the result or the caught * Attempts to invoke `func`, returning either the result or the caught error
* error object. * object. Any additional arguments are provided to `func` when it is invoked.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -12,9 +13,9 @@ var isError = require('../lang/isError');
* @example * @example
* *
* // avoid throwing errors for invalid selectors * // avoid throwing errors for invalid selectors
* var elements = _.attempt(function() { * var elements = _.attempt(function(selector) {
* return document.querySelectorAll(selector); * return document.querySelectorAll(selector);
* }); * }, '>_>');
* *
* if (_.isError(elements)) { * if (_.isError(elements)) {
* elements = []; * elements = [];
@@ -22,9 +23,9 @@ var isError = require('../lang/isError');
*/ */
function attempt(func) { function attempt(func) {
try { try {
return func(); return func.apply(undefined, baseSlice(arguments, 1));
} catch(e) { } catch(e) {
return isError(e) ? e : Error(e); return isError(e) ? e : new Error(e);
} }
} }

View File

@@ -1,11 +1,14 @@
var baseCallback = require('../internal/baseCallback'), var baseCallback = require('../internal/baseCallback'),
isIterateeCall = require('../internal/isIterateeCall'); isIterateeCall = require('../internal/isIterateeCall'),
isObjectLike = require('../internal/isObjectLike'),
matches = require('./matches');
/** /**
* Creates a function bound to an optional `thisArg`. If `func` is a property * Creates a function that invokes `func` with the `this` binding of `thisArg`
* name the created callback returns the property value for a given element. * and arguments of the created function. If `func` is a property name the
* If `func` is an object the created callback returns `true` for elements * created callback returns the property value for a given element. If `func`
* that contain the equivalent object properties, otherwise it returns `false`. * is an object the created callback returns `true` for elements that contain
* the equivalent object properties, otherwise it returns `false`.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -40,7 +43,9 @@ function callback(func, thisArg, guard) {
if (guard && isIterateeCall(func, thisArg, guard)) { if (guard && isIterateeCall(func, thisArg, guard)) {
thisArg = null; thisArg = null;
} }
return baseCallback(func, thisArg); return isObjectLike(func)
? matches(func)
: baseCallback(func, thisArg);
} }
module.exports = callback; module.exports = callback;

View File

@@ -1,10 +1,16 @@
var baseMatches = require('../internal/baseMatches'); var baseClone = require('../internal/baseClone'),
baseMatches = require('../internal/baseMatches');
/** /**
* Creates a function which performs a deep comparison between a given object * Creates a function which performs a deep comparison between a given object
* and `source`, returning `true` if the given object has equivalent property * and `source`, returning `true` if the given object has equivalent property
* values, else `false`. * values, else `false`.
* *
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties. For comparing a single
* own or inherited property value see `_.matchesProperty`.
*
* @static * @static
* @memberOf _ * @memberOf _
* @category Utility * @category Utility
@@ -13,20 +19,15 @@ var baseMatches = require('../internal/baseMatches');
* @example * @example
* *
* var users = [ * var users = [
* { 'user': 'fred', 'age': 40 }, * { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'barney', 'age': 36 } * { 'user': 'fred', 'age': 40, 'active': false }
* ]; * ];
* *
* var matchesAge = _.matches({ 'age': 36 }); * _.filter(users, _.matches({ 'age': 40, 'active': false }));
* * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
* _.filter(users, matchesAge);
* // => [{ 'user': 'barney', 'age': 36 }]
*
* _.find(users, matchesAge);
* // => { 'user': 'barney', 'age': 36 }
*/ */
function matches(source) { function matches(source) {
return baseMatches(source, true); return baseMatches(baseClone(source, true));
} }
module.exports = matches; module.exports = matches;

View File

@@ -0,0 +1,33 @@
var baseClone = require('../internal/baseClone'),
baseMatchesProperty = require('../internal/baseMatchesProperty');
/**
* Creates a function which compares the property value of `key` on a given
* object to `value`.
*
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
* numbers, `Object` objects, regexes, and strings. Objects are compared by
* their own, not inherited, enumerable properties.
*
* @static
* @memberOf _
* @category Utility
* @param {string} key The key of the property to get.
* @param {*} value The value to compare.
* @returns {Function} Returns the new function.
* @example
*
* var users = [
* { 'user': 'barney' },
* { 'user': 'fred' },
* { 'user': 'pebbles' }
* ];
*
* _.find(users, _.matchesProperty('user', 'fred'));
* // => { 'user': 'fred', 'age': 40 }
*/
function matchesProperty(key, value) {
return baseMatchesProperty(key + '', baseClone(value, true));
}
module.exports = matchesProperty;

View File

@@ -32,6 +32,9 @@ var push = arrayProto.push;
* }); * });
* } * }
* *
* // use `_.runInContext` to avoid potential conflicts (esp. in Node.js)
* var _ = require('lodash').runInContext();
*
* _.mixin({ 'vowels': vowels }); * _.mixin({ 'vowels': vowels });
* _.vowels('fred'); * _.vowels('fred');
* // => ['e'] * // => ['e']