Compare commits

...

7 Commits

Author SHA1 Message Date
jdalton
ee1f12c851 Bump to v3.5.0. 2015-03-08 18:09:08 -07:00
jdalton
d01a1e4ef3 Bump to v3.4.0. 2015-03-06 01:11:05 -08:00
jdalton
1e05116bcb Bump to v3.3.1. 2015-02-24 00:27:34 -08:00
jdalton
ebf61a1bd9 Bump to v3.3.0. 2015-02-20 00:25:55 -08:00
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
187 changed files with 1795 additions and 886 deletions

View File

@@ -1,5 +1,5 @@
Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
Based on Underscore.js 1.7.0, copyright 2009-2015 Jeremy Ashkenas, Based on Underscore.js, copyright 2009-2015 Jeremy Ashkenas,
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining

View File

@@ -1,4 +1,4 @@
# lodash-es v3.0.0 # lodash-es v3.5.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. 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 ```bash
$ lodash modularize modern exports=es -o ./ $ lodash modularize modern exports=es -o ./
``` ```
See the [package source](https://github.com/lodash/lodash/tree/3.5.0-es) for more details.

View File

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

View File

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

View File

@@ -20,20 +20,21 @@ import isArray from '../lang/isArray';
* @returns {Array} Returns the new array of filtered values. * @returns {Array} Returns the new array of filtered values.
* @example * @example
* *
* _.difference([1, 2, 3], [5, 2, 10]); * _.difference([1, 2, 3], [4, 2]);
* // => [1, 3] * // => [1, 3]
*/ */
function difference() { function difference() {
var index = -1, var args = arguments,
length = arguments.length; index = -1,
length = args.length;
while (++index < length) { while (++index < length) {
var value = arguments[index]; var value = args[index];
if (isArray(value) || isArguments(value)) { if (isArray(value) || isArguments(value)) {
break; break;
} }
} }
return baseDifference(value, baseFlatten(arguments, false, true, ++index)); return baseDifference(value, baseFlatten(args, false, true, ++index));
} }
export default difference; export default difference;

View File

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

View File

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

View File

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

View File

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

31
array/fill.js Normal file
View File

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

View File

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

View File

@@ -14,11 +14,11 @@ import isIterateeCall from '../internal/isIterateeCall';
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
* @example * @example
* *
* _.flatten([1, [2], [3, [[4]]]]); * _.flatten([1, [2, 3, [4]]]);
* // => [1, 2, 3, [[4]]]; * // => [1, 2, 3, [4]];
* *
* // using `isDeep` * // using `isDeep`
* _.flatten([1, [2], [3, [[4]]]], true); * _.flatten([1, [2, 3, [4]]], true);
* // => [1, 2, 3, 4]; * // => [1, 2, 3, 4];
*/ */
function flatten(array, isDeep, guard) { function flatten(array, isDeep, guard) {
@@ -26,7 +26,7 @@ function flatten(array, isDeep, guard) {
if (guard && isIterateeCall(array, isDeep, guard)) { if (guard && isIterateeCall(array, isDeep, guard)) {
isDeep = false; isDeep = false;
} }
return length ? baseFlatten(array, isDeep) : []; return length ? baseFlatten(array, isDeep, false, 0) : [];
} }
export default flatten; export default flatten;

View File

@@ -10,12 +10,12 @@ import baseFlatten from '../internal/baseFlatten';
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
* @example * @example
* *
* _.flattenDeep([1, [2], [3, [[4]]]]); * _.flattenDeep([1, [2, 3, [4]]]);
* // => [1, 2, 3, 4]; * // => [1, 2, 3, 4];
*/ */
function flattenDeep(array) { function flattenDeep(array) {
var length = array ? array.length : 0; var length = array ? array.length : 0;
return length ? baseFlatten(array, true) : []; return length ? baseFlatten(array, true, false, 0) : [];
} }
export default flattenDeep; export default flattenDeep;

View File

@@ -25,15 +25,15 @@ var nativeMax = Math.max;
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
* @example * @example
* *
* _.indexOf([1, 2, 3, 1, 2, 3], 2); * _.indexOf([1, 2, 1, 2], 2);
* // => 1 * // => 1
* *
* // using `fromIndex` * // using `fromIndex`
* _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); * _.indexOf([1, 2, 1, 2], 2, 2);
* // => 4 * // => 3
* *
* // performing a binary search * // performing a binary search
* _.indexOf([4, 4, 5, 5, 6, 6], 5, true); * _.indexOf([1, 1, 2, 2], 2, true);
* // => 2 * // => 2
*/ */
function indexOf(array, value, fromIndex) { function indexOf(array, value, fromIndex) {
@@ -42,14 +42,17 @@ function indexOf(array, value, fromIndex) {
return -1; return -1;
} }
if (typeof fromIndex == 'number') { if (typeof fromIndex == 'number') {
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0); fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
} else if (fromIndex) { } else if (fromIndex) {
var index = binaryIndex(array, value), var index = binaryIndex(array, value),
other = array[index]; other = array[index];
return (value === value ? value === other : other !== other) ? index : -1; if (value === value ? (value === other) : (other !== other)) {
return index;
}
return -1;
} }
return baseIndexOf(array, value, fromIndex); return baseIndexOf(array, value, fromIndex || 0);
} }
export default indexOf; export default indexOf;

View File

@@ -19,9 +19,8 @@ import isArray from '../lang/isArray';
* @param {...Array} [arrays] The arrays to inspect. * @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of shared values. * @returns {Array} Returns the new array of shared values.
* @example * @example
* * _.intersection([1, 2], [4, 2], [2, 1]);
* _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); * // => [2]
* // => [1, 2]
*/ */
function intersection() { function intersection() {
var args = [], var args = [],
@@ -35,7 +34,7 @@ function intersection() {
var value = arguments[argsIndex]; var value = arguments[argsIndex];
if (isArray(value) || isArguments(value)) { if (isArray(value) || isArguments(value)) {
args.push(value); args.push(value);
caches.push(isCommon && value.length >= 120 && createCache(argsIndex && value)); caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null);
} }
} }
argsLength = args.length; argsLength = args.length;
@@ -48,11 +47,11 @@ function intersection() {
outer: outer:
while (++index < length) { while (++index < length) {
value = array[index]; value = array[index];
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value)) < 0) { if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
argsIndex = argsLength; argsIndex = argsLength;
while (--argsIndex) { while (--argsIndex) {
var cache = caches[argsIndex]; var cache = caches[argsIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value)) < 0) { if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value, 0)) < 0) {
continue outer; continue outer;
} }
} }

View File

@@ -19,15 +19,15 @@ var nativeMax = Math.max,
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
* @example * @example
* *
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); * _.lastIndexOf([1, 2, 1, 2], 2);
* // => 4 * // => 3
* *
* // using `fromIndex` * // using `fromIndex`
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); * _.lastIndexOf([1, 2, 1, 2], 2, 2);
* // => 1 * // => 1
* *
* // performing a binary search * // performing a binary search
* _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true); * _.lastIndexOf([1, 1, 2, 2], 2, true);
* // => 3 * // => 3
*/ */
function lastIndexOf(array, value, fromIndex) { function lastIndexOf(array, value, fromIndex) {
@@ -41,7 +41,10 @@ function lastIndexOf(array, value, fromIndex) {
} else if (fromIndex) { } else if (fromIndex) {
index = binaryIndex(array, value, true) - 1; index = binaryIndex(array, value, true) - 1;
var other = array[index]; var other = array[index];
return (value === value ? value === other : other !== other) ? index : -1; if (value === value ? (value === other) : (other !== other)) {
return index;
}
return -1;
} }
if (value !== value) { if (value !== value) {
return indexOfNaN(array, index, true); return indexOfNaN(array, index, true);

View File

@@ -25,22 +25,25 @@ var splice = arrayProto.splice;
* @example * @example
* *
* var array = [1, 2, 3, 1, 2, 3]; * var array = [1, 2, 3, 1, 2, 3];
*
* _.pull(array, 2, 3); * _.pull(array, 2, 3);
* console.log(array); * console.log(array);
* // => [1, 1] * // => [1, 1]
*/ */
function pull() { function pull() {
var array = arguments[0]; var args = arguments,
array = args[0];
if (!(array && array.length)) { if (!(array && array.length)) {
return array; return array;
} }
var index = 0, var index = 0,
indexOf = baseIndexOf, indexOf = baseIndexOf,
length = arguments.length; length = args.length;
while (++index < length) { while (++index < length) {
var fromIndex = 0, var fromIndex = 0,
value = arguments[index]; value = args[index];
while ((fromIndex = indexOf(array, value, fromIndex)) > -1) { while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
splice.call(array, fromIndex, 1); splice.call(array, fromIndex, 1);

View File

@@ -18,7 +18,7 @@ import basePullAt from '../internal/basePullAt';
* @example * @example
* *
* var array = [5, 10, 15, 20]; * var array = [5, 10, 15, 20];
* var evens = _.pullAt(array, [1, 3]); * var evens = _.pullAt(array, 1, 3);
* *
* console.log(array); * console.log(array);
* // => [5, 15] * // => [5, 15]

View File

@@ -11,10 +11,14 @@ var splice = arrayProto.splice;
* and returns an array of the removed elements. The predicate is bound to * and returns an array of the removed elements. The predicate is bound to
* `thisArg` and invoked with three arguments; (value, index, array). * `thisArg` and invoked with three arguments; (value, index, array).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -25,14 +29,15 @@ var splice = arrayProto.splice;
* @category Array * @category Array
* @param {Array} array The array to modify. * @param {Array} array The array to modify.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new array of removed elements. * @returns {Array} Returns the new array of removed elements.
* @example * @example
* *
* var array = [1, 2, 3, 4]; * var array = [1, 2, 3, 4];
* var evens = _.remove(array, function(n) { return n % 2 == 0; }); * var evens = _.remove(array, function(n) {
* return n % 2 == 0;
* });
* *
* console.log(array); * console.log(array);
* // => [1, 3] * // => [1, 3]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -17,11 +17,11 @@ import baseUniq from '../internal/baseUniq';
* @returns {Array} Returns the new array of combined values. * @returns {Array} Returns the new array of combined values.
* @example * @example
* *
* _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); * _.union([1, 2], [4, 2], [2, 1]);
* // => [1, 2, 3, 5, 4] * // => [1, 2, 4]
*/ */
function union() { function union() {
return baseUniq(baseFlatten(arguments, false, true)); return baseUniq(baseFlatten(arguments, false, true, 0));
} }
export default union; export default union;

View File

@@ -11,10 +11,14 @@ import sortedUniq from '../internal/sortedUniq';
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked * uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
* with three arguments; (value, index, array). * with three arguments; (value, index, array).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -30,8 +34,6 @@ import sortedUniq from '../internal/sortedUniq';
* @param {Array} array The array to inspect. * @param {Array} array The array to inspect.
* @param {boolean} [isSorted] Specify the array is sorted. * @param {boolean} [isSorted] Specify the array is sorted.
* @param {Function|Object|string} [iteratee] The function invoked per iteration. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
* If a property name or object is provided it is used to create a "_.property"
* or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new duplicate-value-free array. * @returns {Array} Returns the new duplicate-value-free array.
* @example * @example
@@ -44,10 +46,12 @@ import sortedUniq from '../internal/sortedUniq';
* // => [1, 2] * // => [1, 2]
* *
* // using an iteratee function * // using an iteratee function
* _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math); * _.uniq([1, 2.5, 1.5, 2], function(n) {
* return this.floor(n);
* }, Math);
* // => [1, 2.5] * // => [1, 2.5]
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }, { 'x': 2 }] * // => [{ 'x': 1 }, { 'x': 2 }]
*/ */
@@ -56,8 +60,7 @@ function uniq(array, isSorted, iteratee, thisArg) {
if (!length) { if (!length) {
return []; return [];
} }
// Juggle arguments. if (isSorted != null && typeof isSorted != 'boolean') {
if (typeof isSorted != 'boolean' && isSorted != null) {
thisArg = iteratee; thisArg = iteratee;
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted; iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
isSorted = false; isSorted = false;

View File

@@ -18,8 +18,8 @@ import baseSlice from '../internal/baseSlice';
* @returns {Array} Returns the new array of filtered values. * @returns {Array} Returns the new array of filtered values.
* @example * @example
* *
* _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); * _.without([1, 2, 1, 3], 1, 2);
* // => [2, 3, 4] * // => [3]
*/ */
function without(array) { function without(array) {
return baseDifference(array, baseSlice(arguments, 1)); return baseDifference(array, baseSlice(arguments, 1));

View File

@@ -15,11 +15,8 @@ import isArray from '../lang/isArray';
* @returns {Array} Returns the new array of values. * @returns {Array} Returns the new array of values.
* @example * @example
* *
* _.xor([1, 2, 3], [5, 2, 1, 4]); * _.xor([1, 2], [4, 2]);
* // => [3, 5, 4] * // => [1, 4]
*
* _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
* // => [1, 4, 5]
*/ */
function xor() { function xor() {
var index = -1, var index = -1,

View File

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

View File

@@ -8,7 +8,7 @@ import lodash from './lodash';
* @memberOf _ * @memberOf _
* @category Chain * @category Chain
* @param {*} value The value to wrap. * @param {*} value The value to wrap.
* @returns {Object} Returns the new `lodash` object. * @returns {Object} Returns the new `lodash` wrapper instance.
* @example * @example
* *
* var users = [ * var users = [
@@ -19,7 +19,9 @@ import lodash from './lodash';
* *
* var youngest = _.chain(users) * var youngest = _.chain(users)
* .sortBy('age') * .sortBy('age')
* .map(function(chr) { return chr.user + ' is ' + chr.age; }) * .map(function(chr) {
* return chr.user + ' is ' + chr.age;
* })
* .first() * .first()
* .value(); * .value();
* // => 'pebbles is 1' * // => 'pebbles is 1'

2
chain/commit.js Normal file
View File

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

View File

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

@@ -14,7 +14,9 @@
* @example * @example
* *
* _([1, 2, 3]) * _([1, 2, 3])
* .tap(function(array) { array.pop(); }) * .tap(function(array) {
* array.pop();
* })
* .reverse() * .reverse()
* .value(); * .value();
* // => [2, 1] * // => [2, 1]

View File

@@ -12,7 +12,9 @@
* *
* _([1, 2, 3]) * _([1, 2, 3])
* .last() * .last()
* .thru(function(value) { return [value]; }) * .thru(function(value) {
* return [value];
* })
* .value(); * .value();
* // => [3] * // => [3]
*/ */

View File

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

32
chain/wrapperCommit.js Normal file
View File

@@ -0,0 +1,32 @@
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 baseLodash from '../internal/baseLodash';
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 baseLodash) {
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 * @name reverse
* @memberOf _ * @memberOf _
* @category Chain * @category Chain
* @returns {Object} Returns the new reversed `lodash` object. * @returns {Object} Returns the new reversed `lodash` wrapper instance.
* @example * @example
* *
* var array = [1, 2, 3]; * var array = [1, 2, 3];
@@ -25,7 +25,10 @@ import thru from './thru';
function wrapperReverse() { function wrapperReverse() {
var value = this.__wrapped__; var value = this.__wrapped__;
if (value instanceof LazyWrapper) { 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 this.thru(function(value) {
return value.reverse(); return value.reverse();

View File

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

View File

@@ -23,8 +23,8 @@ import indexBy from './collection/indexBy';
import inject from './collection/inject'; import inject from './collection/inject';
import invoke from './collection/invoke'; import invoke from './collection/invoke';
import map from './collection/map'; import map from './collection/map';
import max from './collection/max'; import max from './math/max';
import min from './collection/min'; import min from './math/min';
import partition from './collection/partition'; import partition from './collection/partition';
import pluck from './collection/pluck'; import pluck from './collection/pluck';
import reduce from './collection/reduce'; import reduce from './collection/reduce';
@@ -37,6 +37,8 @@ import size from './collection/size';
import some from './collection/some'; import some from './collection/some';
import sortBy from './collection/sortBy'; import sortBy from './collection/sortBy';
import sortByAll from './collection/sortByAll'; import sortByAll from './collection/sortByAll';
import sortByOrder from './collection/sortByOrder';
import sum from './math/sum';
import where from './collection/where'; import where from './collection/where';
export default { export default {
@@ -79,5 +81,7 @@ export default {
'some': some, 'some': some,
'sortBy': sortBy, 'sortBy': sortBy,
'sortByAll': sortByAll, 'sortByAll': sortByAll,
'sortByOrder': sortByOrder,
'sum': sum,
'where': where 'where': where
}; };

View File

@@ -17,8 +17,8 @@ import toIterable from '../internal/toIterable';
* @returns {Array} Returns the new array of picked elements. * @returns {Array} Returns the new array of picked elements.
* @example * @example
* *
* _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); * _.at(['a', 'b', 'c'], [0, 2]);
* // => ['a', 'c', 'e'] * // => ['a', 'c']
* *
* _.at(['fred', 'barney', 'pebbles'], 0, 2); * _.at(['fred', 'barney', 'pebbles'], 0, 2);
* // => ['fred', 'pebbles'] * // => ['fred', 'pebbles']

View File

@@ -13,10 +13,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* The `iteratee` is bound to `thisArg` and invoked with three arguments; * The `iteratee` is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection). * (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -25,16 +29,19 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object. * @returns {Object} Returns the composed aggregate object.
* @example * @example
* *
* _.countBy([4.3, 6.1, 6.4], function(n) { return Math.floor(n); }); * _.countBy([4.3, 6.1, 6.4], function(n) {
* return Math.floor(n);
* });
* // => { '4': 1, '6': 2 } * // => { '4': 1, '6': 2 }
* *
* _.countBy([4.3, 6.1, 6.4], function(n) { return this.floor(n); }, Math); * _.countBy([4.3, 6.1, 6.4], function(n) {
* return this.floor(n);
* }, Math);
* // => { '4': 1, '6': 2 } * // => { '4': 1, '6': 2 }
* *
* _.countBy(['one', 'two', 'three'], 'length'); * _.countBy(['one', 'two', 'three'], 'length');

View File

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

View File

@@ -8,10 +8,14 @@ import isArray from '../lang/isArray';
* `predicate` returns truthy for. The predicate is bound to `thisArg` and * `predicate` returns truthy for. The predicate is bound to `thisArg` and
* invoked with three arguments; (value, index|key, collection). * invoked with three arguments; (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -21,26 +25,31 @@ import isArray from '../lang/isArray';
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the new filtered array. * @returns {Array} Returns the new filtered array.
* @example * @example
* *
* var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; }); * _.filter([4, 5, 6], function(n) {
* // => [2, 4] * return n % 2 == 0;
* });
* // => [4, 6]
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': false }, * { 'user': 'barney', 'age': 36, 'active': true },
* { 'user': 'fred', 'age': 40, 'active': true } * { 'user': 'fred', 'age': 40, 'active': false }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.matches` callback shorthand
* _.pluck(_.filter(users, 'active'), 'user'); * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
* // => ['barney']
*
* // using the `_.matchesProperty` callback shorthand
* _.pluck(_.filter(users, 'active', false), 'user');
* // => ['fred'] * // => ['fred']
* *
* // using the "_.matches" callback shorthand * // using the `_.property` callback shorthand
* _.pluck(_.filter(users, { 'age': 36 }), 'user'); * _.pluck(_.filter(users, 'active'), 'user');
* // => ['barney'] * // => ['barney']
*/ */
function filter(collection, predicate, thisArg) { function filter(collection, predicate, thisArg) {

View File

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

View File

@@ -11,13 +11,14 @@ import baseFind from '../internal/baseFind';
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to search. * @param {Array|Object|string} collection The collection to search.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {*} Returns the matched element, else `undefined`. * @returns {*} Returns the matched element, else `undefined`.
* @example * @example
* *
* _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; }); * _.findLast([1, 2, 3, 4], function(n) {
* return n % 2 == 1;
* });
* // => 3 * // => 3
*/ */
function findLast(collection, predicate, thisArg) { function findLast(collection, predicate, thisArg) {

View File

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

View File

@@ -23,10 +23,14 @@ import isArray from '../lang/isArray';
* @returns {Array|Object|string} Returns `collection`. * @returns {Array|Object|string} Returns `collection`.
* @example * @example
* *
* _([1, 2, 3]).forEach(function(n) { console.log(n); }); * _([1, 2]).forEach(function(n) {
* console.log(n);
* }).value();
* // => logs each value from left to right and returns the array * // => 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); }); * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
* console.log(n, key);
* });
* // => logs each value-key pair and returns the object (iteration order is not guaranteed) * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
*/ */
function forEach(collection, iteratee, thisArg) { function forEach(collection, iteratee, thisArg) {

View File

@@ -17,7 +17,9 @@ import isArray from '../lang/isArray';
* @returns {Array|Object|string} Returns `collection`. * @returns {Array|Object|string} Returns `collection`.
* @example * @example
* *
* _([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(','); * _([1, 2]).forEachRight(function(n) {
* console.log(n);
* }).join(',');
* // => logs each value from right to left and returns the array * // => logs each value from right to left and returns the array
*/ */
function forEachRight(collection, iteratee, thisArg) { function forEachRight(collection, iteratee, thisArg) {

View File

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

View File

@@ -7,10 +7,14 @@ import createAggregator from '../internal/createAggregator';
* iteratee function is bound to `thisArg` and invoked with three arguments; * iteratee function is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection). * (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -19,8 +23,7 @@ import createAggregator from '../internal/createAggregator';
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Object} Returns the composed aggregate object. * @returns {Object} Returns the composed aggregate object.
* @example * @example
@@ -33,10 +36,14 @@ import createAggregator from '../internal/createAggregator';
* _.indexBy(keyData, 'dir'); * _.indexBy(keyData, 'dir');
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
* *
* _.indexBy(keyData, function(object) { return String.fromCharCode(object.code); }); * _.indexBy(keyData, function(object) {
* return String.fromCharCode(object.code);
* });
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
* *
* _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, String); * _.indexBy(keyData, function(object) {
* return this.fromCharCode(object.code);
* }, String);
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*/ */
var indexBy = createAggregator(function(result, value, key) { var indexBy = createAggregator(function(result, value, key) {

View File

@@ -8,37 +8,54 @@ import isArray from '../lang/isArray';
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
* arguments; (value, index|key, collection). * arguments; (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
* Many lodash methods are guarded to work as interatees for methods like
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
*
* The guarded methods are:
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
* `dropRight`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, `slice`,
* `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, `trimRight`,
* `trunc`, `random`, `range`, `sample`, `uniq`, and `words`
*
* @static * @static
* @memberOf _ * @memberOf _
* @alias collect * @alias collect
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee=_.identity] The function invoked * @param {Function|Object|string} [iteratee=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively. * create a `_.property` or `_.matches` style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new mapped array. * @returns {Array} Returns the new mapped array.
* @example * @example
* *
* _.map([1, 2, 3], function(n) { return n * 3; }); * function timesThree(n) {
* // => [3, 6, 9] * return n * 3;
* }
* *
* _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; }); * _.map([1, 2], timesThree);
* // => [3, 6, 9] (iteration order is not guaranteed) * // => [3, 6]
*
* _.map({ 'a': 1, 'b': 2 }, timesThree);
* // => [3, 6] (iteration order is not guaranteed)
* *
* var users = [ * var users = [
* { 'user': 'barney' }, * { 'user': 'barney' },
* { 'user': 'fred' } * { 'user': 'fred' }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.map(users, 'user'); * _.map(users, 'user');
* // => ['barney', 'fred'] * // => ['barney', 'fred']
*/ */

View File

@@ -1,49 +1,2 @@
import arrayMax from '../internal/arrayMax'; import max from '../math/max'
import createExtremum from '../internal/createExtremum';
/**
* Gets the maximum value of `collection`. If `collection` is empty or falsey
* `-Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* 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"
* 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
* object, else `false`.
*
* @static
* @memberOf _
* @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
*
* _.max([4, 2, 8, 6]);
* // => 8
*
* _.max([]);
* // => -Infinity
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* _.max(users, function(chr) { return chr.age; });
* // => { 'user': 'fred', 'age': 40 };
*
* // using the "_.property" callback shorthand
* _.max(users, 'age');
* // => { 'user': 'fred', 'age': 40 };
*/
var max = createExtremum(arrayMax);
export default max; export default max;

View File

@@ -1,49 +1,2 @@
import arrayMin from '../internal/arrayMin'; import min from '../math/min'
import createExtremum from '../internal/createExtremum';
/**
* Gets the minimum value of `collection`. If `collection` is empty or falsey
* `Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* 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"
* 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
* object, else `false`.
*
* @static
* @memberOf _
* @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
*
* _.min([4, 2, 8, 6]);
* // => 2
*
* _.min([]);
* // => Infinity
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* _.min(users, function(chr) { return chr.age; });
* // => { 'user': 'barney', 'age': 36 };
*
* // using the "_.property" callback shorthand
* _.min(users, 'age');
* // => { 'user': 'barney', 'age': 36 };
*/
var min = createExtremum(arrayMin, true);
export default min; export default min;

View File

@@ -6,10 +6,14 @@ import createAggregator from '../internal/createAggregator';
* contains elements `predicate` returns falsey for. The predicate is bound * contains elements `predicate` returns falsey for. The predicate is bound
* to `thisArg` and invoked with three arguments; (value, index|key, collection). * to `thisArg` and invoked with three arguments; (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -18,17 +22,20 @@ import createAggregator from '../internal/createAggregator';
* @category Collection * @category Collection
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [predicate=_.identity] The function invoked * @param {Function|Object|string} [predicate=_.identity] The function invoked
* per iteration. If a property name or object is provided it is used to * per iteration.
* create a "_.property" or "_.matches" style callback respectively.
* @param {*} [thisArg] The `this` binding of `predicate`. * @param {*} [thisArg] The `this` binding of `predicate`.
* @returns {Array} Returns the array of grouped elements. * @returns {Array} Returns the array of grouped elements.
* @example * @example
* *
* _.partition([1, 2, 3], function(n) { return n % 2; }); * _.partition([1, 2, 3], function(n) {
* return n % 2;
* });
* // => [[1, 3], [2]] * // => [[1, 3], [2]]
* *
* _.partition([1.2, 2.3, 3.4], function(n) { return this.floor(n) % 2; }, Math); * _.partition([1.2, 2.3, 3.4], function(n) {
* // => [[1, 3], [2]] * return this.floor(n) % 2;
* }, Math);
* // => [[1.2, 3.4], [2.3]]
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': false }, * { 'user': 'barney', 'age': 36, 'active': false },
@@ -36,12 +43,20 @@ import createAggregator from '../internal/createAggregator';
* { 'user': 'pebbles', 'age': 1, 'active': false } * { 'user': 'pebbles', 'age': 1, 'active': false }
* ]; * ];
* *
* // using the "_.matches" callback shorthand * var mapper = function(array) {
* _.map(_.partition(users, { 'age': 1 }), function(array) { return _.pluck(array, 'user'); }); * return _.pluck(array, 'user');
* };
*
* // using the `_.matches` callback shorthand
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
* // => [['pebbles'], ['barney', 'fred']] * // => [['pebbles'], ['barney', 'fred']]
* *
* // using the "_.property" callback shorthand * // using the `_.matchesProperty` callback shorthand
* _.map(_.partition(users, 'active'), function(array) { return _.pluck(array, 'user'); }); * _.map(_.partition(users, 'active', false), mapper);
* // => [['barney', 'pebbles'], ['fred']]
*
* // using the `_.property` callback shorthand
* _.map(_.partition(users, 'active'), mapper);
* // => [['fred'], ['barney', 'pebbles']] * // => [['fred'], ['barney', 'pebbles']]
*/ */
var partition = createAggregator(function(result, value, key) { var partition = createAggregator(function(result, value, key) {

View File

@@ -1,5 +1,5 @@
import baseProperty from '../internal/baseProperty';
import map from './map'; import map from './map';
import property from '../utility/property';
/** /**
* Gets the value of `key` from all elements in `collection`. * Gets the value of `key` from all elements in `collection`.
@@ -25,7 +25,7 @@ import property from '../utility/property';
* // => [36, 40] (iteration order is not guaranteed) * // => [36, 40] (iteration order is not guaranteed)
*/ */
function pluck(collection, key) { function pluck(collection, key) {
return map(collection, property(key)); return map(collection, baseProperty(key));
} }
export default pluck; 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; * value. The `iteratee` is bound to `thisArg`and invoked with four arguments;
* (accumulator, value, index|key, collection). * (accumulator, value, index|key, collection).
* *
* Many lodash methods are guarded to work as interatees for methods like
* `_.reduce`, `_.reduceRight`, and `_.transform`.
*
* The guarded methods are:
* `assign`, `defaults`, `merge`, and `sortAllBy`
*
* @static * @static
* @memberOf _ * @memberOf _
* @alias foldl, inject * @alias foldl, inject
@@ -23,14 +29,16 @@ import isArray from '../lang/isArray';
* @returns {*} Returns the accumulated value. * @returns {*} Returns the accumulated value.
* @example * @example
* *
* var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; }); * _.reduce([1, 2], function(sum, n) {
* // => 6 * return sum + n;
* });
* // => 3
* *
* var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) { * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
* result[key] = n * 3; * result[key] = n * 3;
* return result; * return result;
* }, {}); * }, {});
* // => { 'a': 3, 'b': 6, 'c': 9 } (iteration order is not guaranteed) * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
*/ */
function reduce(collection, iteratee, accumulator, thisArg) { function reduce(collection, iteratee, accumulator, thisArg) {
var func = isArray(collection) ? arrayReduce : baseReduce; var func = isArray(collection) ? arrayReduce : baseReduce;

View File

@@ -20,7 +20,10 @@ import isArray from '../lang/isArray';
* @example * @example
* *
* var array = [[0, 1], [2, 3], [4, 5]]; * var array = [[0, 1], [2, 3], [4, 5]];
* _.reduceRight(array, function(flattened, other) { return flattened.concat(other); }, []); *
* _.reduceRight(array, function(flattened, other) {
* return flattened.concat(other);
* }, []);
* // => [4, 5, 2, 3, 0, 1] * // => [4, 5, 2, 3, 0, 1]
*/ */
function reduceRight(collection, iteratee, accumulator, thisArg) { function reduceRight(collection, iteratee, accumulator, thisArg) {

View File

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

View File

@@ -2,8 +2,8 @@ import isLength from '../internal/isLength';
import keys from '../object/keys'; import keys from '../object/keys';
/** /**
* Gets the size of `collection` by returning `collection.length` for * Gets the size of `collection` by returning its length for array-like
* array-like values or the number of own enumerable properties for objects. * values or the number of own enumerable properties for objects.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -12,12 +12,12 @@ import keys from '../object/keys';
* @returns {number} Returns the size of `collection`. * @returns {number} Returns the size of `collection`.
* @example * @example
* *
* _.size([1, 2]); * _.size([1, 2, 3]);
* // => 2
*
* _.size({ 'one': 1, 'two': 2, 'three': 3 });
* // => 3 * // => 3
* *
* _.size({ 'a': 1, 'b': 2 });
* // => 2
*
* _.size('pebbles'); * _.size('pebbles');
* // => 7 * // => 7
*/ */

View File

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

View File

@@ -12,10 +12,14 @@ import isLength from '../internal/isLength';
* The `iteratee` is bound to `thisArg` and invoked with three arguments; * The `iteratee` is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection). * (value, index|key, collection).
* *
* If a property name is provided for `predicate` the created "_.property" * If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element. * style callback returns the property value of the given element.
* *
* If an object is provided for `predicate` the created "_.matches" style * If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given * callback returns `true` for elements that have the properties of the given
* object, else `false`. * object, else `false`.
* *
@@ -25,15 +29,19 @@ import isLength from '../internal/isLength';
* @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Object|string} collection The collection to iterate over.
* @param {Array|Function|Object|string} [iteratee=_.identity] The function * @param {Array|Function|Object|string} [iteratee=_.identity] The function
* invoked per iteration. If a property name or an object is provided it is * invoked per iteration. If a property name or an object is provided it is
* used to create a "_.property" or "_.matches" style callback respectively. * used to create a `_.property` or `_.matches` style callback respectively.
* @param {*} [thisArg] The `this` binding of `iteratee`. * @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {Array} Returns the new sorted array. * @returns {Array} Returns the new sorted array.
* @example * @example
* *
* _.sortBy([1, 2, 3], function(n) { return Math.sin(n); }); * _.sortBy([1, 2, 3], function(n) {
* return Math.sin(n);
* });
* // => [3, 1, 2] * // => [3, 1, 2]
* *
* _.sortBy([1, 2, 3], function(n) { return this.sin(n); }, Math); * _.sortBy([1, 2, 3], function(n) {
* return this.sin(n);
* }, Math);
* // => [3, 1, 2] * // => [3, 1, 2]
* *
* var users = [ * var users = [
@@ -42,13 +50,16 @@ import isLength from '../internal/isLength';
* { 'user': 'barney' } * { 'user': 'barney' }
* ]; * ];
* *
* // using the "_.property" callback shorthand * // using the `_.property` callback shorthand
* _.pluck(_.sortBy(users, 'user'), 'user'); * _.pluck(_.sortBy(users, 'user'), 'user');
* // => ['barney', 'fred', 'pebbles'] * // => ['barney', 'fred', 'pebbles']
*/ */
function sortBy(collection, iteratee, thisArg) { function sortBy(collection, iteratee, thisArg) {
if (collection == null) {
return [];
}
var index = -1, var index = -1,
length = collection ? collection.length : 0, length = collection.length,
result = isLength(length) ? Array(length) : []; result = isLength(length) ? Array(length) : [];
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {

View File

@@ -1,9 +1,6 @@
import baseEach from '../internal/baseEach';
import baseFlatten from '../internal/baseFlatten'; import baseFlatten from '../internal/baseFlatten';
import baseSortBy from '../internal/baseSortBy'; import baseSortByOrder from '../internal/baseSortByOrder';
import compareMultipleAscending from '../internal/compareMultipleAscending';
import isIterateeCall from '../internal/isIterateeCall'; import isIterateeCall from '../internal/isIterateeCall';
import isLength from '../internal/isLength';
/** /**
* This method is like `_.sortBy` except that it sorts by property names * This method is like `_.sortBy` except that it sorts by property names
@@ -29,25 +26,16 @@ import isLength from '../internal/isLength';
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]] * // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
*/ */
function sortByAll(collection) { function sortByAll(collection) {
var args = arguments; if (collection == null) {
if (args.length > 3 && isIterateeCall(args[1], args[2], args[3])) { return [];
}
var args = arguments,
guard = args[3];
if (guard && isIterateeCall(args[1], args[2], guard)) {
args = [collection, args[1]]; args = [collection, args[1]];
} }
var index = -1, return baseSortByOrder(collection, baseFlatten(args, false, false, 1), []);
length = collection ? collection.length : 0,
props = baseFlatten(args, false, false, 1),
result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value, key, collection) {
var length = props.length,
criteria = Array(length);
while (length--) {
criteria[length] = value == null ? undefined : value[props[length]];
}
result[++index] = { 'criteria': criteria, 'index': index, 'value': value };
});
return baseSortBy(result, compareMultipleAscending);
} }
export default sortByAll; export default sortByAll;

48
collection/sortByOrder.js Normal file
View File

@@ -0,0 +1,48 @@
import baseSortByOrder from '../internal/baseSortByOrder';
import isArray from '../lang/isArray';
import isIterateeCall from '../internal/isIterateeCall';
/**
* This method is like `_.sortByAll` except that it allows specifying the
* sort orders of the property names to sort by. A truthy value in `orders`
* will sort the corresponding property name in ascending order while a
* falsey value will sort it in descending order.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {string[]} props The property names to sort by.
* @param {boolean[]} orders The sort orders of `props`.
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
* @returns {Array} Returns the new sorted array.
* @example
*
* var users = [
* { 'user': 'barney', 'age': 26 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 30 }
* ];
*
* // sort by `user` in ascending order and by `age` in descending order
* _.map(_.sortByOrder(users, ['user', 'age'], [true, false]), _.values);
* // => [['barney', 36], ['barney', 26], ['fred', 40], ['fred', 30]]
*/
function sortByOrder(collection, props, orders, guard) {
if (collection == null) {
return [];
}
if (guard && isIterateeCall(props, orders, guard)) {
orders = null;
}
if (!isArray(props)) {
props = props == null ? [] : [props];
}
if (!isArray(orders)) {
orders = orders == null ? [] : [orders];
}
return baseSortByOrder(collection, props, orders);
}
export default sortByOrder;

2
collection/sum.js Normal file
View File

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

View File

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

View File

@@ -12,7 +12,9 @@ var nativeNow = isNative(nativeNow = Date.now) && nativeNow;
* @category Date * @category Date
* @example * @example
* *
* _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); * _.defer(function(stamp) {
* console.log(_.now() - stamp);
* }, _.now());
* // => logs the number of milliseconds it took for the deferred function to be invoked * // => logs the number of milliseconds it took for the deferred function to be invoked
*/ */
var now = nativeNow || function() { var now = nativeNow || function() {

View File

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

View File

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

View File

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

View File

@@ -21,7 +21,9 @@ import functions from '../object/functions';
* *
* var view = { * var view = {
* 'label': 'docs', * 'label': 'docs',
* 'onClick': function() { console.log('clicked ' + this.label); } * 'onClick': function() {
* console.log('clicked ' + this.label);
* }
* }; * };
* *
* _.bindAll(view); * _.bindAll(view);

View File

@@ -1,4 +1,3 @@
import isFunction from '../lang/isFunction';
import isObject from '../lang/isObject'; import isObject from '../lang/isObject';
import now from '../date/now'; import now from '../date/now';
@@ -27,7 +26,7 @@ var nativeMax = Math.max;
* @memberOf _ * @memberOf _
* @category Function * @category Function
* @param {Function} func The function to debounce. * @param {Function} func The function to debounce.
* @param {number} wait The number of milliseconds to delay. * @param {number} [wait=0] The number of milliseconds to delay.
* @param {Object} [options] The options object. * @param {Object} [options] The options object.
* @param {boolean} [options.leading=false] Specify invoking on the leading * @param {boolean} [options.leading=false] Specify invoking on the leading
* edge of the timeout. * edge of the timeout.
@@ -82,10 +81,10 @@ function debounce(func, wait, options) {
maxWait = false, maxWait = false,
trailing = true; trailing = true;
if (!isFunction(func)) { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
wait = wait < 0 ? 0 : wait; wait = wait < 0 ? 0 : (+wait || 0);
if (options === true) { if (options === true) {
var leading = true; var leading = true;
trailing = false; trailing = false;

View File

@@ -12,7 +12,9 @@ import baseDelay from '../internal/baseDelay';
* @returns {number} Returns the timer id. * @returns {number} Returns the timer id.
* @example * @example
* *
* _.defer(function(text) { console.log(text); }, 'deferred'); * _.defer(function(text) {
* console.log(text);
* }, 'deferred');
* // logs 'deferred' after one or more milliseconds * // logs 'deferred' after one or more milliseconds
*/ */
function defer(func) { function defer(func) {

View File

@@ -13,7 +13,9 @@ import baseDelay from '../internal/baseDelay';
* @returns {number} Returns the timer id. * @returns {number} Returns the timer id.
* @example * @example
* *
* _.delay(function(text) { console.log(text); }, 1000, 'later'); * _.delay(function(text) {
* console.log(text);
* }, 1000, 'later');
* // => logs 'later' after one second * // => logs 'later' after one second
*/ */
function delay(func, wait) { function delay(func, wait) {

View File

@@ -1,8 +1,4 @@
import arrayEvery from '../internal/arrayEvery'; import createComposer from '../internal/createComposer';
import isFunction from '../lang/isFunction';
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
/** /**
* Creates a function that returns the result of invoking the provided * Creates a function that returns the result of invoking the provided
@@ -16,37 +12,14 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* @returns {Function} Returns the new function. * @returns {Function} Returns the new function.
* @example * @example
* *
* function add(x, y) {
* return x + y;
* }
*
* function square(n) { * function square(n) {
* return n * n; * return n * n;
* } * }
* *
* var addSquare = _.flow(add, square); * var addSquare = _.flow(_.add, square);
* addSquare(1, 2); * addSquare(1, 2);
* // => 9 * // => 9
*/ */
function flow() { var flow = createComposer();
var funcs = arguments,
length = funcs.length;
if (!length) {
return function() {};
}
if (!arrayEvery(funcs, isFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function() {
var index = 0,
result = funcs[index].apply(this, arguments);
while (++index < length) {
result = funcs[index].call(this, result);
}
return result;
};
}
export default flow; export default flow;

View File

@@ -1,8 +1,4 @@
import arrayEvery from '../internal/arrayEvery'; import createComposer from '../internal/createComposer';
import isFunction from '../lang/isFunction';
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
/** /**
* This method is like `_.flow` except that it creates a function that * This method is like `_.flow` except that it creates a function that
@@ -16,37 +12,14 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* @returns {Function} Returns the new function. * @returns {Function} Returns the new function.
* @example * @example
* *
* function add(x, y) {
* return x + y;
* }
*
* function square(n) { * function square(n) {
* return n * n; * return n * n;
* } * }
* *
* var addSquare = _.flowRight(square, add); * var addSquare = _.flowRight(square, _.add);
* addSquare(1, 2); * addSquare(1, 2);
* // => 9 * // => 9
*/ */
function flowRight() { var flowRight = createComposer(true);
var funcs = arguments,
fromIndex = funcs.length - 1;
if (fromIndex < 0) {
return function() {};
}
if (!arrayEvery(funcs, isFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function() {
var index = fromIndex,
result = funcs[index].apply(this, arguments);
while (index--) {
result = funcs[index].call(this, result);
}
return result;
};
}
export default flowRight; export default flowRight;

View File

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

View File

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

View File

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

View File

@@ -27,7 +27,9 @@ var REARG_FLAG = 128;
* // => ['a', 'b', 'c'] * // => ['a', 'b', 'c']
* *
* var map = _.rearg(_.map, [1, 0]); * var map = _.rearg(_.map, [1, 0]);
* map(function(n) { return n * 3; }, [1, 2, 3]); * map(function(n) {
* return n * 3;
* }, [1, 2, 3]);
* // => [3, 6, 9] * // => [3, 6, 9]
*/ */
function rearg(func) { function rearg(func) {

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 debounce from './debounce';
import isFunction from '../lang/isFunction';
import isObject from '../lang/isObject'; import isObject from '../lang/isObject';
/** Used as the `TypeError` message for "Functions" methods. */ /** Used as the `TypeError` message for "Functions" methods. */
@@ -31,7 +30,7 @@ var debounceOptions = {
* @memberOf _ * @memberOf _
* @category Function * @category Function
* @param {Function} func The function to throttle. * @param {Function} func The function to throttle.
* @param {number} wait The number of milliseconds to throttle invocations to. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
* @param {Object} [options] The options object. * @param {Object} [options] The options object.
* @param {boolean} [options.leading=true] Specify invoking on the leading * @param {boolean} [options.leading=true] Specify invoking on the leading
* edge of the timeout. * edge of the timeout.
@@ -44,8 +43,9 @@ var debounceOptions = {
* jQuery(window).on('scroll', _.throttle(updatePosition, 100)); * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
* *
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false }) * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
* jQuery('.interactive').on('click', throttled); * 'trailing': false
* }));
* *
* // cancel a trailing throttled call * // cancel a trailing throttled call
* jQuery(window).on('popstate', throttled.cancel); * jQuery(window).on('popstate', throttled.cancel);
@@ -54,7 +54,7 @@ function throttle(func, wait, options) {
var leading = true, var leading = true,
trailing = true; trailing = true;
if (!isFunction(func)) { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
if (options === false) { if (options === false) {

View File

@@ -1,3 +1,6 @@
import baseCreate from './baseCreate';
import baseLodash from './baseLodash';
/** Used as references for `-Infinity` and `Infinity`. */ /** Used as references for `-Infinity` and `Infinity`. */
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY; var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
@@ -8,14 +11,17 @@ var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
* @param {*} value The value to wrap. * @param {*} value The value to wrap.
*/ */
function LazyWrapper(value) { function LazyWrapper(value) {
this.actions = null; this.__wrapped__ = value;
this.dir = 1; this.__actions__ = null;
this.dropCount = 0; this.__dir__ = 1;
this.filtered = false; this.__dropCount__ = 0;
this.iteratees = null; this.__filtered__ = false;
this.takeCount = POSITIVE_INFINITY; this.__iteratees__ = null;
this.views = null; this.__takeCount__ = POSITIVE_INFINITY;
this.wrapped = value; this.__views__ = null;
} }
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
export default LazyWrapper; export default LazyWrapper;

View File

@@ -1,3 +1,6 @@
import baseCreate from './baseCreate';
import baseLodash from './baseLodash';
/** /**
* The base constructor for creating `lodash` wrapper objects. * The base constructor for creating `lodash` wrapper objects.
* *
@@ -7,9 +10,12 @@
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
*/ */
function LodashWrapper(value, chainAll, actions) { function LodashWrapper(value, chainAll, actions) {
this.__wrapped__ = value;
this.__actions__ = actions || []; this.__actions__ = actions || [];
this.__chain__ = !!chainAll; this.__chain__ = !!chainAll;
this.__wrapped__ = value;
} }
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
LodashWrapper.prototype.constructor = LodashWrapper;
export default LodashWrapper; export default LodashWrapper;

View File

@@ -17,14 +17,14 @@ function baseAssign(object, source, customizer) {
return baseCopy(source, object, props); return baseCopy(source, object, props);
} }
var index = -1, var index = -1,
length = props.length length = props.length;
while (++index < length) { while (++index < length) {
var key = props[index], var key = props[index],
value = object[key], value = object[key],
result = customizer(value, source[key], key, object, source); result = customizer(value, source[key], key, object, source);
if ((result === result ? result !== value : value === value) || if ((result === result ? (result !== value) : (value === value)) ||
(typeof value == 'undefined' && !(key in object))) { (typeof value == 'undefined' && !(key in object))) {
object[key] = result; object[key] = result;
} }

View File

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

View File

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

View File

@@ -21,7 +21,7 @@ function baseDifference(array, values) {
var index = -1, var index = -1,
indexOf = baseIndexOf, indexOf = baseIndexOf,
isCommon = true, isCommon = true,
cache = isCommon && values.length >= 200 && createCache(values), cache = (isCommon && values.length >= 200) ? createCache(values) : null,
valuesLength = values.length; valuesLength = values.length;
if (cache) { if (cache) {
@@ -42,7 +42,7 @@ function baseDifference(array, values) {
} }
result.push(value); result.push(value);
} }
else if (indexOf(values, value) < 0) { else if (indexOf(values, value, 0) < 0) {
result.push(value); result.push(value);
} }
} }

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

@@ -9,13 +9,13 @@ import isObjectLike from './isObjectLike';
* *
* @private * @private
* @param {Array} array The array to flatten. * @param {Array} array The array to flatten.
* @param {boolean} [isDeep] Specify a deep flatten. * @param {boolean} isDeep Specify a deep flatten.
* @param {boolean} [isStrict] Restrict flattening to arrays and `arguments` objects. * @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
* @param {number} [fromIndex=0] The index to start from. * @param {number} fromIndex The index to start from.
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
*/ */
function baseFlatten(array, isDeep, isStrict, fromIndex) { function baseFlatten(array, isDeep, isStrict, fromIndex) {
var index = (fromIndex || 0) - 1, var index = fromIndex - 1,
length = array.length, length = array.length,
resIndex = -1, resIndex = -1,
result = []; result = [];
@@ -26,7 +26,7 @@ function baseFlatten(array, isDeep, isStrict, fromIndex) {
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) { if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
if (isDeep) { if (isDeep) {
// Recursively flatten arrays (susceptible to call stack limits). // Recursively flatten arrays (susceptible to call stack limits).
value = baseFlatten(value, isDeep, isStrict); value = baseFlatten(value, isDeep, isStrict, 0);
} }
var valIndex = -1, var valIndex = -1,
valLength = value.length; valLength = value.length;

View File

@@ -6,14 +6,14 @@ import indexOfNaN from './indexOfNaN';
* @private * @private
* @param {Array} array The array to search. * @param {Array} array The array to search.
* @param {*} value The value to search for. * @param {*} value The value to search for.
* @param {number} [fromIndex=0] The index to search from. * @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
*/ */
function baseIndexOf(array, value, fromIndex) { function baseIndexOf(array, value, fromIndex) {
if (value !== value) { if (value !== value) {
return indexOfNaN(array, fromIndex); return indexOfNaN(array, fromIndex);
} }
var index = (fromIndex || 0) - 1, var index = fromIndex - 1,
length = array.length; length = array.length;
while (++index < length) { while (++index < length) {

View File

@@ -0,0 +1,15 @@
/**
* The base implementation of `_.isFunction` without support for environments
* with incorrect `typeof` results.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
*/
function baseIsFunction(value) {
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
return typeof value == 'function' || false;
}
export default baseIsFunction;

View File

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

10
internal/baseLodash.js Normal file
View File

@@ -0,0 +1,10 @@
/**
* The function whose prototype all chaining wrappers inherit from.
*
* @private
*/
function baseLodash() {
// No operation performed.
}
export default baseLodash;

View File

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

View File

@@ -0,0 +1,24 @@
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;

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