Compare commits

..

3 Commits

Author SHA1 Message Date
jdalton
b82c7ebc32 Bump to v3.2.0. 2015-02-12 21:30:09 -08:00
jdalton
d5f4043617 Bump to v3.1.0. 2015-02-03 08:54:32 -08:00
jdalton
891d0482c6 Bump to v3.0.1. 2015-01-29 22:32:39 -08:00
106 changed files with 904 additions and 422 deletions

View File

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

View File

@@ -5,6 +5,7 @@ import drop from './array/drop';
import dropRight from './array/dropRight';
import dropRightWhile from './array/dropRightWhile';
import dropWhile from './array/dropWhile';
import fill from './array/fill';
import findIndex from './array/findIndex';
import findLastIndex from './array/findLastIndex';
import first from './array/first';
@@ -46,6 +47,7 @@ export default {
'dropRight': dropRight,
'dropRightWhile': dropRightWhile,
'dropWhile': dropWhile,
'fill': fill,
'findIndex': findIndex,
'findLastIndex': findLastIndex,
'first': first,

View File

@@ -16,7 +16,7 @@ var nativeMax = Math.max;
* @memberOf _
* @category Array
* @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`.
* @returns {Array} Returns the new array containing chunks.
* @example

View File

@@ -6,7 +6,6 @@ import isIterateeCall from '../internal/isIterateeCall';
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop.

View File

@@ -6,7 +6,6 @@ import isIterateeCall from '../internal/isIterateeCall';
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to drop.

View File

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

View File

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

31
array/fill.js Normal file
View File

@@ -0,0 +1,31 @@
import baseFill from '../internal/baseFill';
import isIterateeCall from '../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);
}
export default fill;

View File

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

View File

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

View File

@@ -11,10 +11,14 @@ var splice = arrayProto.splice;
* and returns an array of the removed elements. The predicate is bound to
* `thisArg` and invoked with three arguments; (value, index, array).
*
* If a property name is provided for `predicate` the created "_.property"
* If a property name is provided for `predicate` the created `_.property`
* 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
* object, else `false`.
*
@@ -25,8 +29,7 @@ var splice = arrayProto.splice;
* @category Array
* @param {Array} array The array to modify.
* @param {Function|Object|string} [predicate=_.identity] 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.
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new array of removed elements.
* @example

View File

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

View File

@@ -13,8 +13,7 @@ import binaryIndexBy from '../internal/binaryIndexBy';
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @param {Function|Object|string} [iteratee=_.identity] 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.
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.

View File

@@ -6,7 +6,6 @@ import isIterateeCall from '../internal/isIterateeCall';
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to take.

View File

@@ -6,7 +6,6 @@ import isIterateeCall from '../internal/isIterateeCall';
*
* @static
* @memberOf _
* @type Function
* @category Array
* @param {Array} array The array to query.
* @param {number} [n=1] The number of elements to take.

View File

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

View File

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

View File

@@ -11,10 +11,14 @@ import sortedUniq from '../internal/sortedUniq';
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
* with three arguments; (value, index, array).
*
* If a property name is provided for `predicate` the created "_.property"
* If a property name is provided for `predicate` the created `_.property`
* 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
* object, else `false`.
*
@@ -30,8 +34,6 @@ import sortedUniq from '../internal/sortedUniq';
* @param {Array} array The array to inspect.
* @param {boolean} [isSorted] Specify the array is sorted.
* @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`.
* @returns {Array} Returns the new duplicate-value-free array.
* @example
@@ -47,7 +49,7 @@ import sortedUniq from '../internal/sortedUniq';
* _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math);
* // => [1, 2.5]
*
* // using the "_.property" callback shorthand
* // using the `_.property` callback shorthand
* _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }, { 'x': 2 }]
*/

View File

@@ -1,6 +1,9 @@
import chain from './chain/chain';
import commit from './chain/commit';
import lodash from './chain/lodash';
import plant from './chain/plant';
import reverse from './chain/reverse';
import run from './chain/run';
import tap from './chain/tap';
import thru from './chain/thru';
import toJSON from './chain/toJSON';
@@ -11,8 +14,11 @@ import wrapperChain from './chain/wrapperChain';
export default {
'chain': chain,
'commit': commit,
'lodash': lodash,
'plant': plant,
'reverse': reverse,
'run': run,
'tap': tap,
'thru': thru,
'toJSON': toJSON,

View File

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

2
chain/commit.js Normal file
View File

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

View File

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

2
chain/plant.js Normal file
View File

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

2
chain/run.js Normal file
View File

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

View File

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

32
chain/wrapperCommit.js Normal file
View File

@@ -0,0 +1,32 @@
import LodashWrapper from '../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__);
}
export default wrapperCommit;

45
chain/wrapperPlant.js Normal file
View File

@@ -0,0 +1,45 @@
import LodashWrapper from '../internal/LodashWrapper';
import wrapperClone from '../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;
}
export default wrapperPlant;

View File

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

View File

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

View File

@@ -13,10 +13,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection).
*
* If a property name is provided for `predicate` the created "_.property"
* If a property name is provided for `predicate` the created `_.property`
* 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
* object, else `false`.
*
@@ -25,8 +29,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] 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.
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object.
* @example

View File

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

View File

@@ -8,10 +8,14 @@ import isArray from '../lang/isArray';
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
* invoked with three arguments; (value, index|key, collection).
*
* If a property name is provided for `predicate` the created "_.property"
* If a property name is provided for `predicate` the created `_.property`
* 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
* object, else `false`.
*
@@ -21,8 +25,7 @@ import isArray from '../lang/isArray';
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] 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.
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new filtered array.
* @example
@@ -31,16 +34,20 @@ import isArray from '../lang/isArray';
* // => [2, 4]
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': false },
* { 'user': 'fred', 'age': 40, 'active': true }
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }
* ];
*
* // using the "_.property" callback shorthand
* _.pluck(_.filter(users, 'active'), 'user');
* // using the `_.matches` callback shorthand
* _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
* // => ['barney']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.filter(users, 'active', false), 'user');
* // => ['fred']
*
* // using the "_.matches" callback shorthand
* _.pluck(_.filter(users, { 'age': 36 }), 'user');
* // using the `_.property` callback shorthand
* _.pluck(_.filter(users, 'active'), 'user');
* // => ['barney']
*/
function filter(collection, predicate, thisArg) {

View File

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

View File

@@ -11,8 +11,7 @@ import baseFind from '../internal/baseFind';
* @category Collection
* @param {Array|Object|string} collection The collection to search.
* @param {Function|Object|string} [predicate=_.identity] 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.
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {*} Returns the matched element, else `undefined`.
* @example

View File

@@ -1,11 +1,16 @@
import baseMatches from '../internal/baseMatches';
import find from './find';
import matches from '../utility/matches';
/**
* Performs a deep comparison between each element in `collection` and the
* source object, returning the first element that has equivalent 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
* @memberOf _
* @category Collection
@@ -15,18 +20,18 @@ import matches from '../utility/matches';
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36, 'status': 'busy' },
* { 'user': 'fred', 'age': 40, 'status': 'busy' }
* { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': false }
* ];
*
* _.result(_.findWhere(users, { 'status': 'busy' }), 'user');
* _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
* // => 'barney'
*
* _.result(_.findWhere(users, { 'age': 40 }), 'user');
* _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
* // => 'fred'
*/
function findWhere(collection, source) {
return find(collection, matches(source));
return find(collection, baseMatches(source));
}
export default findWhere;

View File

@@ -23,7 +23,7 @@ import isArray from '../lang/isArray';
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2, 3]).forEach(function(n) { console.log(n); });
* _([1, 2, 3]).forEach(function(n) { console.log(n); }).value();
* // => logs each value from left to right and returns the array
*
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });

View File

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

View File

@@ -7,10 +7,14 @@ import createAggregator from '../internal/createAggregator';
* iteratee function is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection).
*
* If a property name is provided for `predicate` the created "_.property"
* If a property name is provided for `predicate` the created `_.property`
* 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
* object, else `false`.
*
@@ -19,8 +23,7 @@ import createAggregator from '../internal/createAggregator';
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] 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.
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object.
* @example

View File

@@ -8,21 +8,34 @@ import isArray from '../lang/isArray';
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
* arguments; (value, index|key, collection).
*
* If a property name is provided for `predicate` the created "_.property"
* If a property name is provided for `predicate` the created `_.property`
* 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
* 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
* @memberOf _
* @alias collect
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] 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.
* per iteration.
* create a `_.property` or `_.matches` style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new mapped array.
* @example
@@ -38,7 +51,7 @@ import isArray from '../lang/isArray';
* { 'user': 'fred' }
* ];
*
* // using the "_.property" callback shorthand
* // using the `_.property` callback shorthand
* _.map(users, 'user');
* // => ['barney', 'fred']
*/

View File

@@ -8,10 +8,14 @@ import createExtremum from '../internal/createExtremum';
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* 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.
*
* 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
* object, else `false`.
*
@@ -20,8 +24,6 @@ import createExtremum from '../internal/createExtremum';
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @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`.
* @returns {*} Returns the maximum value.
* @example
@@ -40,7 +42,7 @@ import createExtremum from '../internal/createExtremum';
* _.max(users, function(chr) { return chr.age; });
* // => { 'user': 'fred', 'age': 40 };
*
* // using the "_.property" callback shorthand
* // using the `_.property` callback shorthand
* _.max(users, 'age');
* // => { 'user': 'fred', 'age': 40 };
*/

View File

@@ -8,10 +8,14 @@ import createExtremum from '../internal/createExtremum';
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* 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.
*
* 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
* object, else `false`.
*
@@ -20,8 +24,6 @@ import createExtremum from '../internal/createExtremum';
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @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`.
* @returns {*} Returns the minimum value.
* @example
@@ -40,7 +42,7 @@ import createExtremum from '../internal/createExtremum';
* _.min(users, function(chr) { return chr.age; });
* // => { 'user': 'barney', 'age': 36 };
*
* // using the "_.property" callback shorthand
* // using the `_.property` callback shorthand
* _.min(users, 'age');
* // => { 'user': 'barney', 'age': 36 };
*/

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,11 +1,16 @@
import baseMatches from '../internal/baseMatches';
import filter from './filter';
import matches from '../utility/matches';
/**
* Performs a deep comparison between each element in `collection` and the
* source object, returning an array of all elements that have equivalent
* 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
* @memberOf _
* @category Collection
@@ -15,21 +20,18 @@ import matches from '../utility/matches';
* @example
*
* var users = [
* { 'user': 'barney', 'age': 36, 'status': 'busy', 'pets': ['hoppy'] },
* { 'user': 'fred', 'age': 40, 'status': 'busy', 'pets': ['baby puss', 'dino'] }
* { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
* { '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']
*
* _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
* // => ['fred']
*
* _.pluck(_.where(users, { 'status': 'busy' }), 'user');
* // => ['barney', 'fred']
*/
function where(collection, source) {
return filter(collection, matches(source));
return filter(collection, baseMatches(source));
}
export default where;

View File

@@ -19,6 +19,7 @@ import once from './function/once';
import partial from './function/partial';
import partialRight from './function/partialRight';
import rearg from './function/rearg';
import spread from './function/spread';
import throttle from './function/throttle';
import wrap from './function/wrap';
@@ -44,6 +45,7 @@ export default {
'partial': partial,
'partialRight': partialRight,
'rearg': rearg,
'spread': spread,
'throttle': throttle,
'wrap': wrap
};

View File

@@ -1,4 +1,3 @@
import isFunction from '../lang/isFunction';
import root from '../internal/root';
/** Used as the `TypeError` message for "Functions" methods. */
@@ -31,8 +30,8 @@ var nativeIsFinite = root.isFinite;
* // => logs 'done saving!' after the two async saves have completed
*/
function after(n, func) {
if (!isFunction(func)) {
if (isFunction(n)) {
if (typeof func != 'function') {
if (typeof n == 'function') {
var temp = n;
n = func;
func = temp;

View File

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

View File

@@ -1,4 +1,3 @@
import isFunction from '../lang/isFunction';
import isObject from '../lang/isObject';
import now from '../date/now';
@@ -82,7 +81,7 @@ function debounce(func, wait, options) {
maxWait = false,
trailing = true;
if (!isFunction(func)) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
wait = wait < 0 ? 0 : wait;

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,7 +7,6 @@ import before from './before';
*
* @static
* @memberOf _
* @type Function
* @category Function
* @param {Function} func The function to restrict.
* @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);
};
}
export default spread;

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
import baseMatches from './baseMatches';
import baseMatchesProperty from './baseMatchesProperty';
import baseProperty from './baseProperty';
import baseToString from './baseToString';
import bindCallback from './bindCallback';
import identity from '../utility/identity';
import isBindable from './isBindable';
@@ -25,10 +25,12 @@ function baseCallback(func, thisArg, argCount) {
if (func == null) {
return identity;
}
// Handle "_.property" and "_.matches" style callback shorthands.
return type == 'object'
? baseMatches(func, !argCount)
: baseProperty(argCount ? baseToString(func) : func);
if (type == 'object') {
return baseMatches(func);
}
return typeof thisArg == 'undefined'
? baseProperty(func + '')
: baseMatchesProperty(func + '', thisArg);
}
export default baseCallback;

View File

@@ -1,5 +1,4 @@
import baseSlice from './baseSlice';
import isFunction from '../lang/isFunction';
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
@@ -15,7 +14,7 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* @returns {number} Returns the timer id.
*/
function baseDelay(func, wait, args, fromIndex) {
if (!isFunction(func)) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
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;
}
export default baseFill;

View File

@@ -11,7 +11,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* shorthands or `this` binding.
*
* @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} values The source values to match.
* @param {Array} strictCompareFlags Strict comparison flags for source values.

View File

@@ -1,4 +1,3 @@
import baseClone from './baseClone';
import baseIsMatch from './baseIsMatch';
import isStrictComparable from './isStrictComparable';
import keys from '../object/keys';
@@ -10,15 +9,13 @@ var objectProto = Object.prototype;
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* The base implementation of `_.matches` which supports specifying whether
* `source` should be cloned.
* The base implementation of `_.matches` which does not clone `source`.
*
* @private
* @param {Object} source The object of property values to match.
* @param {boolean} [isCloned] Specify cloning the source object.
* @returns {Function} Returns the new function.
*/
function baseMatches(source, isCloned) {
function baseMatches(source) {
var props = keys(source),
length = props.length;
@@ -28,13 +25,10 @@ function baseMatches(source, isCloned) {
if (isStrictComparable(value)) {
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),
strictCompareFlags = Array(length);

View File

@@ -0,0 +1,24 @@
import baseIsEqual from './baseIsEqual';
import isStrictComparable from './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);
};
}
export default baseMatchesProperty;

View File

@@ -47,6 +47,9 @@ function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stack
? toPlainObject(value)
: (isPlainObject(value) ? value : {});
}
else {
isCommon = false;
}
}
// Add the source value to the stack of traversed objects and associate
// it with its merged value.

View File

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

View File

@@ -19,7 +19,8 @@ function baseSlice(array, start, end) {
if (end < 0) {
end += length;
}
length = start > end ? 0 : (end - start);
length = start > end ? 0 : (end - start) >>> 0;
start >>>= 0;
var result = Array(length);
while (++index < length) {

View File

@@ -5,8 +5,7 @@ import isArray from '../lang/isArray';
/**
* Creates a function that aggregates a collection, creating an accumulator
* 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
* object. If `initializer` is provided initializes the accumulator object.
* through an iteratee.
*
* @private
* @param {Function} setter The function to set keys and values of the accumulator object.

View File

@@ -1,4 +1,3 @@
import baseToString from './baseToString';
import repeat from '../string/repeat';
import root from './root';
@@ -27,7 +26,7 @@ function createPad(string, length, chars) {
return '';
}
var padLength = length - strLength;
chars = chars == null ? ' ' : baseToString(chars);
chars = chars == null ? ' ' : (chars + '');
return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
}

View File

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

View File

@@ -1,5 +1,3 @@
import baseToString from './baseToString';
/** `Object#toString` result references. */
var boolTag = '[object Boolean]',
dateTag = '[object Date]',
@@ -43,7 +41,7 @@ function equalByTag(object, other, tag) {
case stringTag:
// Coerce regexes to strings and treat strings primitives and string
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
return object == baseToString(other);
return object == (other + '');
}
return false;
}

View File

@@ -1,6 +1,6 @@
/**
* 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.
*/
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;

View File

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

View File

@@ -1,6 +1,6 @@
/**
* 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.
*/
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.
*
* **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
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.

View File

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

View File

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

View File

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

18
internal/wrapperClone.js Normal file
View File

@@ -0,0 +1,18 @@
import LazyWrapper from './LazyWrapper';
import LodashWrapper from './LodashWrapper';
import arrayCopy from './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__));
}
export default wrapperClone;

View File

@@ -10,7 +10,8 @@ import isStrictComparable from '../internal/isStrictComparable';
* arguments; (value, other [, index|key]).
*
* **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
* for comparing other values.
*

View File

@@ -24,7 +24,7 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @static
* @memberOf _
* @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 {Function} [customizer] The function to customize comparing values.
* @param {*} [thisArg] The `this` binding of `customizer`.

View File

@@ -1,6 +1,6 @@
/**
* @license
* lodash 3.0.0 (Custom Build) <https://lodash.com/>
* lodash 3.2.0 (Custom Build) <https://lodash.com/>
* Build: `lodash modularize modern exports="es" -o ./`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
@@ -21,8 +21,12 @@ import LazyWrapper from './internal/LazyWrapper';
import LodashWrapper from './internal/LodashWrapper';
import arrayEach from './internal/arrayEach';
import baseCallback from './internal/baseCallback';
import baseCreate from './internal/baseCreate';
import baseForOwn from './internal/baseForOwn';
import baseFunctions from './internal/baseFunctions';
import baseMatches from './internal/baseMatches';
import baseProperty from './internal/baseProperty';
import identity from './utility/identity';
import isArray from './lang/isArray';
import isObject from './lang/isObject';
import keys from './object/keys';
@@ -30,14 +34,12 @@ import lazyClone from './internal/lazyClone';
import lazyReverse from './internal/lazyReverse';
import lazyValue from './internal/lazyValue';
import lodash from './chain/lodash';
import matches from './utility/matches';
import _mixin from './utility/mixin';
import property from './utility/property';
import support from './support';
import thru from './chain/thru';
/** Used as the semantic version number. */
var VERSION = '3.0.0';
var VERSION = '3.2.0';
/** Used to indicate the type of lazy iteratees. */
var LAZY_FILTER_FLAG = 0,
@@ -47,13 +49,20 @@ var LAZY_FILTER_FLAG = 0,
var arrayProto = Array.prototype;
/** Native method references. */
var push = arrayProto.push,
unshift = arrayProto.unshift;
var floor = Math.floor,
push = arrayProto.push;
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max,
nativeMin = Math.min;
// Ensure `new LodashWrapper` is an instance of `lodash`.
LodashWrapper.prototype = baseCreate(lodash.prototype);
// Ensure `new LazyWraper` is an instance of `LodashWrapper`
LazyWrapper.prototype = baseCreate(LodashWrapper.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
// wrap `_.mixin` so it works when provided only one argument
var mixin = (function(func) {
return function(object, source, options) {
@@ -99,6 +108,7 @@ lodash.drop = array.drop;
lodash.dropRight = array.dropRight;
lodash.dropRightWhile = array.dropRightWhile;
lodash.dropWhile = array.dropWhile;
lodash.fill = array.fill;
lodash.filter = collection.filter;
lodash.flatten = array.flatten;
lodash.flattenDeep = array.flattenDeep;
@@ -121,7 +131,8 @@ lodash.keys = keys;
lodash.keysIn = object.keysIn;
lodash.map = collection.map;
lodash.mapValues = object.mapValues;
lodash.matches = matches;
lodash.matches = utility.matches;
lodash.matchesProperty = utility.matchesProperty;
lodash.memoize = func.memoize;
lodash.merge = object.merge;
lodash.mixin = mixin;
@@ -134,7 +145,7 @@ lodash.partialRight = func.partialRight;
lodash.partition = collection.partition;
lodash.pick = object.pick;
lodash.pluck = collection.pluck;
lodash.property = property;
lodash.property = utility.property;
lodash.propertyOf = utility.propertyOf;
lodash.pull = array.pull;
lodash.pullAt = array.pullAt;
@@ -147,6 +158,7 @@ lodash.shuffle = collection.shuffle;
lodash.slice = array.slice;
lodash.sortBy = collection.sortBy;
lodash.sortByAll = collection.sortByAll;
lodash.spread = func.spread;
lodash.take = array.take;
lodash.takeRight = array.takeRight;
lodash.takeRightWhile = array.takeRightWhile;
@@ -207,7 +219,7 @@ lodash.findLastKey = object.findLastKey;
lodash.findWhere = collection.findWhere;
lodash.first = array.first;
lodash.has = object.has;
lodash.identity = utility.identity;
lodash.identity = identity;
lodash.includes = collection.includes;
lodash.indexOf = array.indexOf;
lodash.isArguments = lang.isArguments;
@@ -252,6 +264,7 @@ lodash.snakeCase = string.snakeCase;
lodash.some = collection.some;
lodash.sortedIndex = array.sortedIndex;
lodash.sortedLastIndex = array.sortedLastIndex;
lodash.startCase = string.startCase;
lodash.startsWith = string.startsWith;
lodash.template = string.template;
lodash.trim = string.trim;
@@ -314,14 +327,15 @@ arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'],
// Add `LazyWrapper` methods that accept an `iteratee` value.
arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
var isFilter = index == LAZY_FILTER_FLAG;
var isFilter = index == LAZY_FILTER_FLAG,
isWhile = index == LAZY_WHILE_FLAG;
LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
var result = this.clone(),
filtered = result.filtered,
iteratees = result.iteratees || (result.iteratees = []);
filtered = result.__filtered__,
iteratees = result.__iteratees__ || (result.__iteratees__ = []);
result.filtered = filtered || isFilter || (index == LAZY_WHILE_FLAG && result.dir < 0);
result.__filtered__ = filtered || isFilter || (isWhile && result.__dir__ < 0);
iteratees.push({ 'iteratee': baseCallback(iteratee, thisArg, 3), 'type': index });
return result;
};
@@ -329,19 +343,19 @@ arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
// Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
arrayEach(['drop', 'take'], function(methodName, index) {
var countName = methodName + 'Count',
var countName = '__' + methodName + 'Count__',
whileName = methodName + 'While';
LazyWrapper.prototype[methodName] = function(n) {
n = n == null ? 1 : nativeMax(+n || 0, 0);
n = n == null ? 1 : nativeMax(floor(n) || 0, 0);
var result = this.clone();
if (result.filtered) {
if (result.__filtered__) {
var value = result[countName];
result[countName] = index ? nativeMin(value, n) : (value + n);
} else {
var views = result.views || (result.views = []);
views.push({ 'size': n, 'type': methodName + (result.dir < 0 ? 'Right' : '') });
var views = result.__views__ || (result.__views__ = []);
views.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
}
return result;
};
@@ -357,7 +371,7 @@ arrayEach(['drop', 'take'], function(methodName, index) {
// Add `LazyWrapper` methods for `_.first` and `_.last`.
arrayEach(['first', 'last'], function(methodName, index) {
var takeName = 'take' + (index ? 'Right': '');
var takeName = 'take' + (index ? 'Right' : '');
LazyWrapper.prototype[methodName] = function() {
return this[takeName](1).value()[0];
@@ -376,30 +390,29 @@ arrayEach(['initial', 'rest'], function(methodName, index) {
// Add `LazyWrapper` methods for `_.pluck` and `_.where`.
arrayEach(['pluck', 'where'], function(methodName, index) {
var operationName = index ? 'filter' : 'map',
createCallback = index ? matches : property;
createCallback = index ? baseMatches : baseProperty;
LazyWrapper.prototype[methodName] = function(value) {
return this[operationName](createCallback(value));
};
});
LazyWrapper.prototype.dropWhile = function(iteratee, thisArg) {
var done,
lastIndex,
isRight = this.dir < 0;
LazyWrapper.prototype.compact = function() {
return this.filter(identity);
};
iteratee = baseCallback(iteratee, thisArg, 3);
LazyWrapper.prototype.dropWhile = function(predicate, thisArg) {
var done;
predicate = baseCallback(predicate, thisArg, 3);
return this.filter(function(value, index, array) {
done = done && (isRight ? index < lastIndex : index > lastIndex);
lastIndex = index;
return done || (done = !iteratee(value, index, array));
return done || (done = !predicate(value, index, array));
});
};
LazyWrapper.prototype.reject = function(iteratee, thisArg) {
iteratee = baseCallback(iteratee, thisArg, 3);
LazyWrapper.prototype.reject = function(predicate, thisArg) {
predicate = baseCallback(predicate, thisArg, 3);
return this.filter(function(value, index, array) {
return !iteratee(value, index, array);
return !predicate(value, index, array);
});
};
@@ -414,9 +427,14 @@ LazyWrapper.prototype.slice = function(start, end) {
return result;
};
LazyWrapper.prototype.toArray = function() {
return this.drop(0);
};
// Add `LazyWrapper` methods to `lodash.prototype`.
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
var retUnwrapped = /^(?:first|last)$/.test(methodName);
var lodashFunc = lodash[methodName],
retUnwrapped = /^(?:first|last)$/.test(methodName);
lodash.prototype[methodName] = function() {
var value = this.__wrapped__,
@@ -429,19 +447,19 @@ baseForOwn(LazyWrapper.prototype, function(func, methodName) {
if (retUnwrapped && !chainAll) {
return onlyLazy
? func.call(value)
: lodash[methodName](this.value());
: lodashFunc.call(lodash, this.value());
}
var interceptor = function(value) {
var otherArgs = [value];
push.apply(otherArgs, args);
return lodash[methodName].apply(lodash, otherArgs);
return lodashFunc.apply(lodash, otherArgs);
};
if (isLazy || isArray(value)) {
var wrapper = onlyLazy ? value : new LazyWrapper(this),
result = func.apply(wrapper, args);
if (!retUnwrapped && (isHybrid || result.actions)) {
var actions = result.actions || (result.actions = []);
if (!retUnwrapped && (isHybrid || result.__actions__)) {
var actions = result.__actions__ || (result.__actions__ = []);
actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash });
}
return new LodashWrapper(result, chainAll);
@@ -474,9 +492,11 @@ LazyWrapper.prototype.value = lazyValue;
// Add chaining functions to the lodash wrapper.
lodash.prototype.chain = chain.wrapperChain;
lodash.prototype.commit = chain.commit;
lodash.prototype.plant = chain.plant;
lodash.prototype.reverse = chain.reverse;
lodash.prototype.toString = chain.toString;
lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = chain.value;
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = chain.value;
// Add function aliases to the lodash wrapper.
lodash.prototype.collect = lodash.prototype.map;

View File

@@ -6,10 +6,14 @@ import baseForOwn from '../internal/baseForOwn';
* This method is like `_.findIndex` except that it returns the key of the
* 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.
*
* 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
* object, else `false`.
*
@@ -18,8 +22,7 @@ import baseForOwn from '../internal/baseForOwn';
* @category Object
* @param {Object} object The object to search.
* @param {Function|Object|string} [predicate=_.identity] 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.
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {string|undefined} Returns the key of the matched element, else `undefined`.
* @example
@@ -33,11 +36,15 @@ import baseForOwn from '../internal/baseForOwn';
* _.findKey(users, function(chr) { return chr.age < 40; });
* // => 'barney' (iteration order is not guaranteed)
*
* // using the "_.matches" callback shorthand
* _.findKey(users, { 'age': 1 });
* // using the `_.matches` callback shorthand
* _.findKey(users, { 'age': 1, 'active': true });
* // => 'pebbles'
*
* // using the "_.property" callback shorthand
* // using the `_.matchesProperty` callback shorthand
* _.findKey(users, 'active', false);
* // => 'fred'
*
* // using the `_.property` callback shorthand
* _.findKey(users, 'active');
* // => 'barney'
*/

View File

@@ -6,10 +6,14 @@ import baseForOwnRight from '../internal/baseForOwnRight';
* This method is like `_.findKey` except that it iterates over elements of
* 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.
*
* 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
* object, else `false`.
*
@@ -18,8 +22,7 @@ import baseForOwnRight from '../internal/baseForOwnRight';
* @category Object
* @param {Object} object The object to search.
* @param {Function|Object|string} [predicate=_.identity] 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.
* per iteration.
* @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {string|undefined} Returns the key of the matched element, else `undefined`.
* @example
@@ -33,11 +36,15 @@ import baseForOwnRight from '../internal/baseForOwnRight';
* _.findLastKey(users, function(chr) { return chr.age < 40; });
* // => returns `pebbles` assuming `_.findKey` returns `barney`
*
* // using the "_.matches" callback shorthand
* _.findLastKey(users, { 'age': 36 });
* // using the `_.matches` callback shorthand
* _.findLastKey(users, { 'age': 36, 'active': true });
* // => 'barney'
*
* // using the "_.property" callback shorthand
* // using the `_.matchesProperty` callback shorthand
* _.findLastKey(users, 'active', false);
* // => 'fred'
*
* // using the `_.property` callback shorthand
* _.findLastKey(users, 'active');
* // => 'pebbles'
*/

View File

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

View File

@@ -7,10 +7,14 @@ import baseForOwn from '../internal/baseForOwn';
* iteratee function is bound to `thisArg` and invoked with three arguments;
* (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.
*
* 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
* object, else `false`.
*
@@ -19,8 +23,7 @@ import baseForOwn from '../internal/baseForOwn';
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] 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.
* per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the new mapped object.
* @example
@@ -33,7 +36,7 @@ import baseForOwn from '../internal/baseForOwn';
* 'pebbles': { 'user': 'pebbles', 'age': 1 }
* };
*
* // using the "_.property" callback shorthand
* // using the `_.property` callback shorthand
* _.mapValues(users, 'age');
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*/

View File

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

View File

@@ -1,6 +1,6 @@
{
"name": "lodash-es",
"version": "3.0.0",
"version": "3.2.0",
"description": "The modern build of lodash exported as ES modules.",
"homepage": "https://lodash.com/custom-builds",
"license": "MIT",

View File

@@ -11,6 +11,7 @@ import padRight from './string/padRight';
import parseInt from './string/parseInt';
import repeat from './string/repeat';
import snakeCase from './string/snakeCase';
import startCase from './string/startCase';
import startsWith from './string/startsWith';
import template from './string/template';
import templateSettings from './string/templateSettings';
@@ -35,6 +36,7 @@ export default {
'parseInt': parseInt,
'repeat': repeat,
'snakeCase': snakeCase,
'startCase': startCase,
'startsWith': startsWith,
'template': template,
'templateSettings': templateSettings,

View File

@@ -22,7 +22,7 @@ import createCompounder from '../internal/createCompounder';
*/
var camelCase = createCompounder(function(result, word, index) {
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);
});
export default camelCase;

View File

@@ -2,7 +2,7 @@ import createCompounder from '../internal/createCompounder';
/**
* Converts `string` to kebab case (a.k.a. spinal case).
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Computers) for
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for
* more details.
*
* @static

View File

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

28
string/startCase.js Normal file
View File

@@ -0,0 +1,28 @@
import createCompounder from '../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));
});
export default startCase;

View File

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

View File

@@ -28,9 +28,9 @@ function trimLeft(string, chars, guard) {
return string;
}
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 + '')));
}
export default trimLeft;

View File

@@ -28,9 +28,9 @@ function trimRight(string, chars, guard) {
return string;
}
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);
}
export default trimRight;

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