Compare commits

...

2 Commits

Author SHA1 Message Date
jdalton
d58549ce0b Bump to v3.6.0. 2015-03-25 08:35:37 -07:00
jdalton
06f6ffa303 Bump to v3.5.0. 2015-03-08 19:07:13 -07:00
208 changed files with 2391 additions and 1905 deletions

View File

@@ -1,4 +1,4 @@
# lodash v3.4.0
# lodash v3.6.0
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules.
@@ -28,7 +28,7 @@ var array = require('lodash/array');
var chunk = require('lodash/array/chunk');
```
See the [package source](https://github.com/lodash/lodash/tree/3.4.0-npm) for more details.
See the [package source](https://github.com/lodash/lodash/tree/3.6.0-npm) for more details.
**Note:**<br>
Dont assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br>
@@ -39,8 +39,8 @@ Install [n_](https://www.npmjs.com/package/n_) for a REPL that includes lodash b
lodash is also available in a variety of other builds & module formats.
* npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.4.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.4.0-amd) builds
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.4.0-es) build
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.6.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.6.0-amd) builds
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.6.0-es) build
## Further Reading
@@ -51,7 +51,7 @@ lodash is also available in a variety of other builds & module formats.
* [Roadmap](https://github.com/lodash/lodash/wiki/Roadmap)
* [More Resources](https://github.com/lodash/lodash/wiki/Resources)
## Features *not* in Underscore
## Features
* ~100% [code coverage](https://coveralls.io/r/lodash)
* Follows [semantic versioning](http://semver.org/) for releases
@@ -85,10 +85,10 @@ lodash is also available in a variety of other builds & module formats.
* [_.parseInt](https://lodash.com/docs#parseInt) for consistent cross-environment behavior
* [_.pull](https://lodash.com/docs#pull), [_.pullAt](https://lodash.com/docs#pullAt), & [_.remove](https://lodash.com/docs#remove) for mutating arrays
* [_.random](https://lodash.com/docs#random) supports returning floating-point numbers
* [_.restParam](https://lodash.com/docs#restParam) & [_.spread](https://lodash.com/docs#spread) for applying rest parameters & spreading arguments to functions
* [_.runInContext](https://lodash.com/docs#runInContext) for collisionless mixins & easier mocking
* [_.slice](https://lodash.com/docs#slice) for creating subsets of array-like values
* [_.sortByAll](https://lodash.com/docs#sortByAll) & [_.sortByOrder](https://lodash.com/docs#sortByOrder) for sorting by multiple properties & orders
* [_.spread](https://lodash.com/docs#spread) for creating a function to spread an array of arguments to another
* [_.sum](https://lodash.com/docs#sum) to get the sum of values
* [_.support](https://lodash.com/docs#support) for flagging environment features
* [_.template](https://lodash.com/docs#template) supports [*“imports”*](https://lodash.com/docs#templateSettings-imports) options & [ES template delimiters](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
@@ -112,5 +112,5 @@ lodash is also available in a variety of other builds & module formats.
## Support
Tested in Chrome 40-41, Firefox 35-36, IE 6-11, Opera 26-27, Safari 5-8, io.js 1.4.3, Node.js 0.8.28, 0.10.36, & 0.12.0, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5.
Tested in Chrome 40-41, Firefox 35-36, IE 6-11, Opera 27-28, Safari 5-8, io.js 1.6.2, Node.js 0.8.28, 0.10.36, & 0.12.0, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5.
Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Special thanks to [Sauce Labs](https://saucelabs.com/) for providing automated browser testing.

View File

@@ -1,16 +1,16 @@
var baseDifference = require('../internal/baseDifference'),
baseFlatten = require('../internal/baseFlatten'),
isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray');
isArray = require('../lang/isArray'),
restParam = require('../function/restParam');
/**
* Creates an array excluding all values of the provided arrays using
* `SameValueZero` for equality comparisons.
*
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
* e.g. `===`, except that `NaN` matches `NaN`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _
@@ -23,18 +23,10 @@ var baseDifference = require('../internal/baseDifference'),
* _.difference([1, 2, 3], [4, 2]);
* // => [1, 3]
*/
function difference() {
var args = arguments,
index = -1,
length = args.length;
while (++index < length) {
var value = args[index];
if (isArray(value) || isArguments(value)) {
break;
}
}
return baseDifference(value, baseFlatten(args, false, true, ++index));
}
var difference = restParam(function(array, values) {
return (isArray(array) || isArguments(array))
? baseDifference(array, baseFlatten(values, false, true))
: [];
});
module.exports = difference;

View File

@@ -1,10 +1,10 @@
var baseCallback = require('../internal/baseCallback'),
baseSlice = require('../internal/baseSlice');
baseWhile = require('../internal/baseWhile');
/**
* Creates a slice of `array` excluding elements dropped from the end.
* Elements are dropped until `predicate` returns falsey. The predicate is
* bound to `thisArg` and invoked with three arguments; (value, index, array).
* bound to `thisArg` and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
@@ -51,13 +51,9 @@ var baseCallback = require('../internal/baseCallback'),
* // => ['barney', 'fred', 'pebbles']
*/
function dropRightWhile(array, predicate, thisArg) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
predicate = baseCallback(predicate, thisArg, 3);
while (length-- && predicate(array[length], length, array)) {}
return baseSlice(array, 0, length + 1);
return (array && array.length)
? baseWhile(array, baseCallback(predicate, thisArg, 3), true, true)
: [];
}
module.exports = dropRightWhile;

View File

@@ -1,10 +1,10 @@
var baseCallback = require('../internal/baseCallback'),
baseSlice = require('../internal/baseSlice');
baseWhile = require('../internal/baseWhile');
/**
* Creates a slice of `array` excluding elements dropped from the beginning.
* Elements are dropped until `predicate` returns falsey. The predicate is
* bound to `thisArg` and invoked with three arguments; (value, index, array).
* bound to `thisArg` and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
@@ -51,14 +51,9 @@ var baseCallback = require('../internal/baseCallback'),
* // => ['barney', 'fred', 'pebbles']
*/
function dropWhile(array, predicate, thisArg) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
var index = -1;
predicate = baseCallback(predicate, thisArg, 3);
while (++index < length && predicate(array[index], index, array)) {}
return baseSlice(array, index);
return (array && array.length)
? baseWhile(array, baseCallback(predicate, thisArg, 3), true)
: [];
}
module.exports = dropWhile;

View File

@@ -15,6 +15,19 @@ var baseFill = require('../internal/baseFill'),
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns `array`.
* @example
*
* var array = [1, 2, 3];
*
* _.fill(array, 'a');
* console.log(array);
* // => ['a', 'a', 'a']
*
* _.fill(Array(3), 2);
* // => [2, 2, 2]
*
* _.fill([4, 6, 8], '*', 1, 2);
* // => [4, '*', 8]
*/
function fill(array, value, start, end) {
var length = array ? array.length : 0;

View File

@@ -1,8 +1,8 @@
var baseCallback = require('../internal/baseCallback');
var createFindIndex = require('../internal/createFindIndex');
/**
* This method is like `_.find` except that it returns the index of the first
* element `predicate` returns truthy for, instead of the element itself.
* element `predicate` returns truthy for instead of the element itself.
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
@@ -48,17 +48,6 @@ var baseCallback = require('../internal/baseCallback');
* _.findIndex(users, 'active');
* // => 2
*/
function findIndex(array, predicate, thisArg) {
var index = -1,
length = array ? array.length : 0;
predicate = baseCallback(predicate, thisArg, 3);
while (++index < length) {
if (predicate(array[index], index, array)) {
return index;
}
}
return -1;
}
var findIndex = createFindIndex();
module.exports = findIndex;

View File

@@ -1,4 +1,4 @@
var baseCallback = require('../internal/baseCallback');
var createFindIndex = require('../internal/createFindIndex');
/**
* This method is like `_.findIndex` except that it iterates over elements
@@ -48,15 +48,6 @@ var baseCallback = require('../internal/baseCallback');
* _.findLastIndex(users, 'active');
* // => 0
*/
function findLastIndex(array, predicate, thisArg) {
var length = array ? array.length : 0;
predicate = baseCallback(predicate, thisArg, 3);
while (length--) {
if (predicate(array[length], length, array)) {
return length;
}
}
return -1;
}
var findLastIndex = createFindIndex(true);
module.exports = findLastIndex;

View File

@@ -15,18 +15,18 @@ var baseFlatten = require('../internal/baseFlatten'),
* @example
*
* _.flatten([1, [2, 3, [4]]]);
* // => [1, 2, 3, [4]];
* // => [1, 2, 3, [4]]
*
* // using `isDeep`
* _.flatten([1, [2, 3, [4]]], true);
* // => [1, 2, 3, 4];
* // => [1, 2, 3, 4]
*/
function flatten(array, isDeep, guard) {
var length = array ? array.length : 0;
if (guard && isIterateeCall(array, isDeep, guard)) {
isDeep = false;
}
return length ? baseFlatten(array, isDeep, false, 0) : [];
return length ? baseFlatten(array, isDeep) : [];
}
module.exports = flatten;

View File

@@ -11,11 +11,11 @@ var baseFlatten = require('../internal/baseFlatten');
* @example
*
* _.flattenDeep([1, [2, 3, [4]]]);
* // => [1, 2, 3, 4];
* // => [1, 2, 3, 4]
*/
function flattenDeep(array) {
var length = array ? array.length : 0;
return length ? baseFlatten(array, true, false, 0) : [];
return length ? baseFlatten(array, true) : [];
}
module.exports = flattenDeep;

View File

@@ -10,10 +10,9 @@ var nativeMax = Math.max;
* it is used as the offset from the end of `array`. If `array` is sorted
* providing `true` for `fromIndex` performs a faster binary search.
*
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
* e.g. `===`, except that `NaN` matches `NaN`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _
@@ -47,7 +46,10 @@ function indexOf(array, value, fromIndex) {
var index = binaryIndex(array, value),
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 || 0);
}

View File

@@ -8,10 +8,9 @@ var baseIndexOf = require('../internal/baseIndexOf'),
* Creates an array of unique values in all provided arrays using `SameValueZero`
* for equality comparisons.
*
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
* e.g. `===`, except that `NaN` matches `NaN`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _

View File

@@ -41,7 +41,10 @@ function lastIndexOf(array, value, fromIndex) {
} else if (fromIndex) {
index = binaryIndex(array, value, true) - 1;
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) {
return indexOfNaN(array, index, true);

View File

@@ -11,10 +11,10 @@ var splice = arrayProto.splice;
* comparisons.
*
* **Notes:**
* - Unlike `_.without`, this method mutates `array`.
* - `SameValueZero` comparisons are like strict equality comparisons, e.g. `===`,
* except that `NaN` matches `NaN`. See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* - Unlike `_.without`, this method mutates `array`
* - [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except
* that `NaN` matches `NaN`
*
* @static
* @memberOf _

View File

@@ -1,5 +1,14 @@
var baseFlatten = require('../internal/baseFlatten'),
basePullAt = require('../internal/basePullAt');
var baseAt = require('../internal/baseAt'),
baseCompareAscending = require('../internal/baseCompareAscending'),
baseFlatten = require('../internal/baseFlatten'),
isIndex = require('../internal/isIndex'),
restParam = require('../function/restParam');
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var splice = arrayProto.splice;
/**
* Removes elements from `array` corresponding to the given indexes and returns
@@ -26,8 +35,22 @@ var baseFlatten = require('../internal/baseFlatten'),
* console.log(evens);
* // => [10, 20]
*/
function pullAt(array) {
return basePullAt(array || [], baseFlatten(arguments, false, false, 1));
}
var pullAt = restParam(function(array, indexes) {
array || (array = []);
indexes = baseFlatten(indexes);
var length = indexes.length,
result = baseAt(array, indexes);
indexes.sort(baseCompareAscending);
while (length--) {
var index = parseFloat(indexes[length]);
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);
}
}
return result;
});
module.exports = pullAt;

View File

@@ -9,7 +9,7 @@ var splice = arrayProto.splice;
/**
* Removes all elements from `array` that `predicate` returns truthy for
* and returns an array of the removed elements. The predicate is bound to
* `thisArg` and invoked with three arguments; (value, index, array).
* `thisArg` and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.

View File

@@ -1,6 +1,4 @@
var baseCallback = require('../internal/baseCallback'),
binaryIndex = require('../internal/binaryIndex'),
binaryIndexBy = require('../internal/binaryIndexBy');
var createSortedIndex = require('../internal/createSortedIndex');
/**
* Uses a binary search to determine the lowest index at which `value` should
@@ -9,14 +7,14 @@ var baseCallback = require('../internal/baseCallback'),
* to compute their sort ranking. The iteratee is bound to `thisArg` and
* invoked with one argument; (value).
*
* If a property name is provided for `predicate` the created `_.property`
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
@@ -50,10 +48,6 @@ var baseCallback = require('../internal/baseCallback'),
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
* // => 1
*/
function sortedIndex(array, value, iteratee, thisArg) {
return iteratee == null
? binaryIndex(array, value)
: binaryIndexBy(array, value, baseCallback(iteratee, thisArg, 1));
}
var sortedIndex = createSortedIndex();
module.exports = sortedIndex;

View File

@@ -1,6 +1,4 @@
var baseCallback = require('../internal/baseCallback'),
binaryIndex = require('../internal/binaryIndex'),
binaryIndexBy = require('../internal/binaryIndexBy');
var createSortedIndex = require('../internal/createSortedIndex');
/**
* This method is like `_.sortedIndex` except that it returns the highest
@@ -22,10 +20,6 @@ var baseCallback = require('../internal/baseCallback'),
* _.sortedLastIndex([4, 4, 5, 5], 5);
* // => 4
*/
function sortedLastIndex(array, value, iteratee, thisArg) {
return iteratee == null
? binaryIndex(array, value, true)
: binaryIndexBy(array, value, baseCallback(iteratee, thisArg, 1), true);
}
var sortedLastIndex = createSortedIndex(true);
module.exports = sortedLastIndex;

View File

@@ -1,10 +1,10 @@
var baseCallback = require('../internal/baseCallback'),
baseSlice = require('../internal/baseSlice');
baseWhile = require('../internal/baseWhile');
/**
* Creates a slice of `array` with elements taken from the end. Elements are
* taken until `predicate` returns falsey. The predicate is bound to `thisArg`
* and invoked with three arguments; (value, index, array).
* and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
@@ -51,13 +51,9 @@ var baseCallback = require('../internal/baseCallback'),
* // => []
*/
function takeRightWhile(array, predicate, thisArg) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
predicate = baseCallback(predicate, thisArg, 3);
while (length-- && predicate(array[length], length, array)) {}
return baseSlice(array, length + 1);
return (array && array.length)
? baseWhile(array, baseCallback(predicate, thisArg, 3), false, true)
: [];
}
module.exports = takeRightWhile;

View File

@@ -1,10 +1,10 @@
var baseCallback = require('../internal/baseCallback'),
baseSlice = require('../internal/baseSlice');
baseWhile = require('../internal/baseWhile');
/**
* Creates a slice of `array` with elements taken from the beginning. Elements
* are taken until `predicate` returns falsey. The predicate is bound to
* `thisArg` and invoked with three arguments; (value, index, array).
* `thisArg` and invoked with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
@@ -51,14 +51,9 @@ var baseCallback = require('../internal/baseCallback'),
* // => []
*/
function takeWhile(array, predicate, thisArg) {
var length = array ? array.length : 0;
if (!length) {
return [];
}
var index = -1;
predicate = baseCallback(predicate, thisArg, 3);
while (++index < length && predicate(array[index], index, array)) {}
return baseSlice(array, 0, index);
return (array && array.length)
? baseWhile(array, baseCallback(predicate, thisArg, 3))
: [];
}
module.exports = takeWhile;

View File

@@ -1,14 +1,14 @@
var baseFlatten = require('../internal/baseFlatten'),
baseUniq = require('../internal/baseUniq');
baseUniq = require('../internal/baseUniq'),
restParam = require('../function/restParam');
/**
* Creates an array of unique values, in order, of the provided arrays using
* `SameValueZero` for equality comparisons.
*
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
* e.g. `===`, except that `NaN` matches `NaN`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _
@@ -20,8 +20,8 @@ var baseFlatten = require('../internal/baseFlatten'),
* _.union([1, 2], [4, 2], [2, 1]);
* // => [1, 2, 4]
*/
function union() {
return baseUniq(baseFlatten(arguments, false, true, 0));
}
var union = restParam(function(arrays) {
return baseUniq(baseFlatten(arrays, false, true));
});
module.exports = union;

View File

@@ -9,23 +9,22 @@ var baseCallback = require('../internal/baseCallback'),
* search algorithm for sorted arrays. If an iteratee function is provided it
* is invoked for each value in the array to generate the criterion by which
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
* with three arguments; (value, index, array).
* with three arguments: (value, index, array).
*
* If a property name is provided for `predicate` the created `_.property`
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
* e.g. `===`, except that `NaN` matches `NaN`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _

View File

@@ -1,14 +1,15 @@
var baseDifference = require('../internal/baseDifference'),
baseSlice = require('../internal/baseSlice');
isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray'),
restParam = require('../function/restParam');
/**
* Creates an array excluding all provided values using `SameValueZero` for
* equality comparisons.
*
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
* e.g. `===`, except that `NaN` matches `NaN`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _
@@ -21,8 +22,10 @@ var baseDifference = require('../internal/baseDifference'),
* _.without([1, 2, 1, 3], 1, 2);
* // => [3]
*/
function without(array) {
return baseDifference(array, baseSlice(arguments, 1));
}
var without = restParam(function(array, values) {
return (isArray(array) || isArguments(array))
? baseDifference(array, values)
: [];
});
module.exports = without;

View File

@@ -4,9 +4,8 @@ var baseDifference = require('../internal/baseDifference'),
isArray = require('../lang/isArray');
/**
* Creates an array that is the symmetric difference of the provided arrays.
* See [Wikipedia](https://en.wikipedia.org/wiki/Symmetric_difference) for
* more details.
* Creates an array that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
* of the provided arrays.
*
* @static
* @memberOf _

View File

@@ -1,4 +1,5 @@
var unzip = require('./unzip');
var restParam = require('../function/restParam'),
unzip = require('./unzip');
/**
* Creates an array of grouped elements, the first of which contains the first
@@ -15,14 +16,6 @@ var unzip = require('./unzip');
* _.zip(['fred', 'barney'], [30, 40], [true, false]);
* // => [['fred', 30, true], ['barney', 40, false]]
*/
function zip() {
var length = arguments.length,
array = Array(length);
while (length--) {
array[length] = arguments[length];
}
return unzip(array);
}
var zip = restParam(unzip);
module.exports = zip;

View File

@@ -1,9 +1,10 @@
var isArray = require('../lang/isArray');
/**
* Creates an object composed from arrays of property names and values. Provide
* either a single two dimensional array, e.g. `[[key1, value1], [key2, value2]]`
* or two arrays, one of property names and one of corresponding values.
* The inverse of `_.pairs`; this method returns an object composed from arrays
* of property names and values. Provide either a single two dimensional array,
* e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
* and one of corresponding values.
*
* @static
* @memberOf _
@@ -14,6 +15,9 @@ var isArray = require('../lang/isArray');
* @returns {Object} Returns the new object.
* @example
*
* _.zipObject([['fred', 30], ['barney', 40]]);
* // => { 'fred': 30, 'barney': 40 }
*
* _.zipObject(['fred', 'barney'], [30, 40]);
* // => { 'fred': 30, 'barney': 40 }
*/

View File

@@ -27,9 +27,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* Chaining is supported in custom builds as long as the `_#value` method is
* directly or indirectly included in the build.
*
* In addition to lodash methods, wrappers also have the following `Array` methods:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
* and `unshift`
* In addition to lodash methods, wrappers have `Array` and `String` methods.
*
* The wrapper `Array` methods are:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
* `splice`, and `unshift`
*
* The wrapper `String` methods are:
* `replace` and `split`
*
* The wrapper methods that support shortcut fusion are:
* `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,

View File

@@ -10,13 +10,14 @@
* @returns {*} Returns the result of `interceptor`.
* @example
*
* _([1, 2, 3])
* .last()
* _(' abc ')
* .chain()
* .trim()
* .thru(function(value) {
* return [value];
* })
* .value();
* // => [3]
* // => ['abc']
*/
function thru(value, interceptor, thisArg) {
return interceptor.call(thisArg, value);

View File

@@ -1,6 +1,7 @@
var baseAt = require('../internal/baseAt'),
baseFlatten = require('../internal/baseFlatten'),
isLength = require('../internal/isLength'),
restParam = require('../function/restParam'),
toIterable = require('../internal/toIterable');
/**
@@ -20,15 +21,15 @@ var baseAt = require('../internal/baseAt'),
* _.at(['a', 'b', 'c'], [0, 2]);
* // => ['a', 'c']
*
* _.at(['fred', 'barney', 'pebbles'], 0, 2);
* // => ['fred', 'pebbles']
* _.at(['barney', 'fred', 'pebbles'], 0, 2);
* // => ['barney', 'pebbles']
*/
function at(collection) {
var at = restParam(function(collection, props) {
var length = collection ? collection.length : 0;
if (isLength(length)) {
collection = toIterable(collection);
}
return baseAt(collection, baseFlatten(arguments, false, false, 1));
}
return baseAt(collection, baseFlatten(props));
});
module.exports = at;

View File

@@ -10,17 +10,17 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
* of each key is the number of times the key was returned by `iteratee`.
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*

View File

@@ -1,11 +1,12 @@
var arrayEvery = require('../internal/arrayEvery'),
baseCallback = require('../internal/baseCallback'),
baseEvery = require('../internal/baseEvery'),
isArray = require('../lang/isArray');
isArray = require('../lang/isArray'),
isIterateeCall = require('../internal/isIterateeCall');
/**
* Checks if `predicate` returns truthy for **all** elements of `collection`.
* The predicate is bound to `thisArg` and invoked with three arguments;
* The predicate is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
@@ -53,6 +54,9 @@ var arrayEvery = require('../internal/arrayEvery'),
*/
function every(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayEvery : baseEvery;
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null;
}
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
predicate = baseCallback(predicate, thisArg, 3);
}

View File

@@ -6,7 +6,7 @@ var arrayFilter = require('../internal/arrayFilter'),
/**
* Iterates over elements of `collection`, returning an array of all elements
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
* invoked with three arguments; (value, index|key, collection).
* invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.

View File

@@ -1,13 +1,10 @@
var baseCallback = require('../internal/baseCallback'),
baseEach = require('../internal/baseEach'),
baseFind = require('../internal/baseFind'),
findIndex = require('../array/findIndex'),
isArray = require('../lang/isArray');
var baseEach = require('../internal/baseEach'),
createFind = require('../internal/createFind');
/**
* Iterates over elements of `collection`, returning the first element
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
* invoked with three arguments; (value, index|key, collection).
* invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
@@ -54,13 +51,6 @@ var baseCallback = require('../internal/baseCallback'),
* _.result(_.find(users, 'active'), 'user');
* // => 'barney'
*/
function find(collection, predicate, thisArg) {
if (isArray(collection)) {
var index = findIndex(collection, predicate, thisArg);
return index > -1 ? collection[index] : undefined;
}
predicate = baseCallback(predicate, thisArg, 3);
return baseFind(collection, predicate, baseEach);
}
var find = createFind(baseEach);
module.exports = find;

View File

@@ -1,6 +1,5 @@
var baseCallback = require('../internal/baseCallback'),
baseEachRight = require('../internal/baseEachRight'),
baseFind = require('../internal/baseFind');
var baseEachRight = require('../internal/baseEachRight'),
createFind = require('../internal/createFind');
/**
* This method is like `_.find` except that it iterates over elements of
@@ -21,9 +20,6 @@ var baseCallback = require('../internal/baseCallback'),
* });
* // => 3
*/
function findLast(collection, predicate, thisArg) {
predicate = baseCallback(predicate, thisArg, 3);
return baseFind(collection, predicate, baseEachRight);
}
var findLast = createFind(baseEachRight, true);
module.exports = findLast;

View File

@@ -1,11 +1,10 @@
var arrayEach = require('../internal/arrayEach'),
baseEach = require('../internal/baseEach'),
bindCallback = require('../internal/bindCallback'),
isArray = require('../lang/isArray');
createForEach = require('../internal/createForEach');
/**
* Iterates over elements of `collection` invoking `iteratee` for each element.
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection). Iterator functions may exit iteration early
* by explicitly returning `false`.
*
@@ -33,10 +32,6 @@ var arrayEach = require('../internal/arrayEach'),
* });
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
*/
function forEach(collection, iteratee, thisArg) {
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
? arrayEach(collection, iteratee)
: baseEach(collection, bindCallback(iteratee, thisArg, 3));
}
var forEach = createForEach(arrayEach, baseEach);
module.exports = forEach;

View File

@@ -1,7 +1,6 @@
var arrayEachRight = require('../internal/arrayEachRight'),
baseEachRight = require('../internal/baseEachRight'),
bindCallback = require('../internal/bindCallback'),
isArray = require('../lang/isArray');
createForEach = require('../internal/createForEach');
/**
* This method is like `_.forEach` except that it iterates over elements of
@@ -19,13 +18,9 @@ var arrayEachRight = require('../internal/arrayEachRight'),
*
* _([1, 2]).forEachRight(function(n) {
* console.log(n);
* }).join(',');
* }).value();
* // => logs each value from right to left and returns the array
*/
function forEachRight(collection, iteratee, thisArg) {
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
? arrayEachRight(collection, iteratee)
: baseEachRight(collection, bindCallback(iteratee, thisArg, 3));
}
var forEachRight = createForEach(arrayEachRight, baseEachRight);
module.exports = forEachRight;

View File

@@ -10,17 +10,17 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
* of each key is an array of the elements responsible for generating the key.
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*

View File

@@ -1,5 +1,6 @@
var baseIndexOf = require('../internal/baseIndexOf'),
isArray = require('../lang/isArray'),
isIterateeCall = require('../internal/isIterateeCall'),
isLength = require('../internal/isLength'),
isString = require('../lang/isString'),
values = require('../object/values');
@@ -12,10 +13,9 @@ var nativeMax = Math.max;
* comparisons. If `fromIndex` is negative, it is used as the offset from
* the end of `collection`.
*
* **Note:** `SameValueZero` comparisons are like strict equality comparisons,
* e.g. `===`, except that `NaN` matches `NaN`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* for more details.
* **Note:** [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
* comparisons are like strict equality comparisons, e.g. `===`, except that
* `NaN` matches `NaN`.
*
* @static
* @memberOf _
@@ -24,6 +24,7 @@ var nativeMax = Math.max;
* @param {Array|Object|string} collection The collection to search.
* @param {*} target The value to search for.
* @param {number} [fromIndex=0] The index to search from.
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
* @returns {boolean} Returns `true` if a matching element is found, else `false`.
* @example
*
@@ -39,7 +40,7 @@ var nativeMax = Math.max;
* _.includes('pebbles', 'eb');
* // => true
*/
function includes(collection, target, fromIndex) {
function includes(collection, target, fromIndex, guard) {
var length = collection ? collection.length : 0;
if (!isLength(length)) {
collection = values(collection);
@@ -48,10 +49,10 @@ function includes(collection, target, fromIndex) {
if (!length) {
return false;
}
if (typeof fromIndex == 'number') {
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
} else {
if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
fromIndex = 0;
} else {
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
}
return (typeof collection == 'string' || !isArray(collection) && isString(collection))
? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)

View File

@@ -4,17 +4,17 @@ var createAggregator = require('../internal/createAggregator');
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
* of each key is the last element responsible for generating the key. The
* iteratee function is bound to `thisArg` and invoked with three arguments;
* iteratee function is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*

View File

@@ -1,5 +1,6 @@
var baseInvoke = require('../internal/baseInvoke'),
baseSlice = require('../internal/baseSlice');
var baseEach = require('../internal/baseEach'),
isLength = require('../internal/isLength'),
restParam = require('../function/restParam');
/**
* Invokes the method named by `methodName` on each element in `collection`,
@@ -23,8 +24,17 @@ var baseInvoke = require('../internal/baseInvoke'),
* _.invoke([123, 456], String.prototype.split, '');
* // => [['1', '2', '3'], ['4', '5', '6']]
*/
function invoke(collection, methodName) {
return baseInvoke(collection, methodName, baseSlice(arguments, 2));
}
var invoke = restParam(function(collection, methodName, args) {
var index = -1,
isFunc = typeof methodName == 'function',
length = collection ? collection.length : 0,
result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value) {
var func = isFunc ? methodName : (value != null && value[methodName]);
result[++index] = func ? func.apply(value, args) : undefined;
});
return result;
});
module.exports = invoke;

View File

@@ -6,16 +6,16 @@ var arrayMap = require('../internal/arrayMap'),
/**
* Creates an array of values by running each element in `collection` through
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
* arguments; (value, index|key, collection).
* arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
@@ -24,9 +24,9 @@ var arrayMap = require('../internal/arrayMap'),
*
* 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`
* `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`,
* `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`,
* `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, `uniq`, and `words`
*
* @static
* @memberOf _

View File

@@ -4,7 +4,7 @@ var createAggregator = require('../internal/createAggregator');
* Creates an array of elements split into two groups, the first of which
* contains elements `predicate` returns truthy for, while the second of which
* contains elements `predicate` returns falsey for. The predicate is bound
* to `thisArg` and invoked with three arguments; (value, index|key, collection).
* to `thisArg` and invoked with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.

View File

@@ -1,22 +1,20 @@
var arrayReduce = require('../internal/arrayReduce'),
baseCallback = require('../internal/baseCallback'),
baseEach = require('../internal/baseEach'),
baseReduce = require('../internal/baseReduce'),
isArray = require('../lang/isArray');
createReduce = require('../internal/createReduce');
/**
* Reduces `collection` to a value which is the accumulated result of running
* each element in `collection` through `iteratee`, where each successive
* invocation is supplied the return value of the previous. If `accumulator`
* is not provided the first element of `collection` is used as the initial
* value. The `iteratee` is bound to `thisArg`and invoked with four arguments;
* value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
* (accumulator, value, index|key, collection).
*
* Many lodash methods are guarded to work as interatees for methods like
* `_.reduce`, `_.reduceRight`, and `_.transform`.
*
* The guarded methods are:
* `assign`, `defaults`, `merge`, and `sortAllBy`
* `assign`, `defaults`, `includes`, `merge`, `sortByAll`, and `sortByOrder`
*
* @static
* @memberOf _
@@ -40,9 +38,6 @@ var arrayReduce = require('../internal/arrayReduce'),
* }, {});
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
*/
function reduce(collection, iteratee, accumulator, thisArg) {
var func = isArray(collection) ? arrayReduce : baseReduce;
return func(collection, baseCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEach);
}
var reduce = createReduce(arrayReduce, baseEach);
module.exports = reduce;

View File

@@ -1,8 +1,6 @@
var arrayReduceRight = require('../internal/arrayReduceRight'),
baseCallback = require('../internal/baseCallback'),
baseEachRight = require('../internal/baseEachRight'),
baseReduce = require('../internal/baseReduce'),
isArray = require('../lang/isArray');
createReduce = require('../internal/createReduce');
/**
* This method is like `_.reduce` except that it iterates over elements of
@@ -26,9 +24,6 @@ var arrayReduceRight = require('../internal/arrayReduceRight'),
* }, []);
* // => [4, 5, 2, 3, 0, 1]
*/
function reduceRight(collection, iteratee, accumulator, thisArg) {
var func = isArray(collection) ? arrayReduceRight : baseReduce;
return func(collection, baseCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEachRight);
}
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
module.exports = reduceRight;

View File

@@ -2,9 +2,8 @@ var baseRandom = require('../internal/baseRandom'),
toIterable = require('../internal/toIterable');
/**
* Creates an array of shuffled values, using a version of the Fisher-Yates
* shuffle. See [Wikipedia](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle)
* for more details.
* Creates an array of shuffled values, using a version of the
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
*
* @static
* @memberOf _

View File

@@ -1,13 +1,14 @@
var arraySome = require('../internal/arraySome'),
baseCallback = require('../internal/baseCallback'),
baseSome = require('../internal/baseSome'),
isArray = require('../lang/isArray');
isArray = require('../lang/isArray'),
isIterateeCall = require('../internal/isIterateeCall');
/**
* Checks if `predicate` returns truthy for **any** element of `collection`.
* The function returns as soon as it finds a passing value and does not iterate
* over the entire collection. The predicate is bound to `thisArg` and invoked
* with three arguments; (value, index|key, collection).
* with three arguments: (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
@@ -54,6 +55,9 @@ var arraySome = require('../internal/arraySome'),
*/
function some(collection, predicate, thisArg) {
var func = isArray(collection) ? arraySome : baseSome;
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
predicate = null;
}
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
predicate = baseCallback(predicate, thisArg, 3);
}

View File

@@ -9,17 +9,17 @@ var baseCallback = require('../internal/baseCallback'),
* Creates an array of elements, sorted in ascending order by the results of
* running each element in a collection through `iteratee`. This method performs
* a stable sort, that is, it preserves the original sort order of equal elements.
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
* (value, index|key, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* If a property name is provided for `iteratee` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* If an object is provided for `iteratee` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*

View File

@@ -25,17 +25,24 @@ var baseFlatten = require('../internal/baseFlatten'),
* _.map(_.sortByAll(users, ['user', 'age']), _.values);
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
*/
function sortByAll(collection) {
function sortByAll() {
var args = arguments,
collection = args[0],
guard = args[3],
index = 0,
length = args.length - 1;
if (collection == null) {
return [];
}
var args = arguments,
guard = args[3];
if (guard && isIterateeCall(args[1], args[2], guard)) {
args = [collection, args[1]];
var props = Array(length);
while (index < length) {
props[index] = args[++index];
}
return baseSortByOrder(collection, baseFlatten(args, false, false, 1), []);
if (guard && isIterateeCall(args[1], args[2], guard)) {
props = args[1];
}
return baseSortByOrder(collection, baseFlatten(props), []);
}
module.exports = sortByAll;

View File

@@ -14,13 +14,14 @@ var baseSortByOrder = require('../internal/baseSortByOrder'),
* @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': 36 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 26 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 30 }
* ];
*

View File

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

View File

@@ -2,7 +2,7 @@ var createWrapper = require('../internal/createWrapper'),
isIterateeCall = require('../internal/isIterateeCall');
/** Used to compose bitmasks for wrapper metadata. */
var ARY_FLAG = 256;
var ARY_FLAG = 128;
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;

View File

@@ -1,6 +1,6 @@
var baseSlice = require('../internal/baseSlice'),
createWrapper = require('../internal/createWrapper'),
replaceHolders = require('../internal/replaceHolders');
var createWrapper = require('../internal/createWrapper'),
replaceHolders = require('../internal/replaceHolders'),
restParam = require('./restParam');
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
@@ -22,7 +22,7 @@ var BIND_FLAG = 1,
* @category Function
* @param {Function} func The function to bind.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} [args] The arguments to be partially applied.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
@@ -41,16 +41,14 @@ var BIND_FLAG = 1,
* bound('hi');
* // => 'hi fred!'
*/
function bind(func, thisArg) {
var bind = restParam(function(func, thisArg, partials) {
var bitmask = BIND_FLAG;
if (arguments.length > 2) {
var partials = baseSlice(arguments, 2),
holders = replaceHolders(partials, bind.placeholder);
if (partials.length) {
var holders = replaceHolders(partials, bind.placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(func, bitmask, thisArg, partials, holders);
}
});
// Assign default placeholders.
bind.placeholder = {};

View File

@@ -1,6 +1,10 @@
var baseBindAll = require('../internal/baseBindAll'),
baseFlatten = require('../internal/baseFlatten'),
functions = require('../object/functions');
var baseFlatten = require('../internal/baseFlatten'),
createWrapper = require('../internal/createWrapper'),
functions = require('../object/functions'),
restParam = require('./restParam');
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1;
/**
* Binds methods of an object to the object itself, overwriting the existing
@@ -30,12 +34,17 @@ var baseBindAll = require('../internal/baseBindAll'),
* jQuery('#docs').on('click', view.onClick);
* // => logs 'clicked docs' when the element is clicked
*/
function bindAll(object) {
return baseBindAll(object,
arguments.length > 1
? baseFlatten(arguments, false, false, 1)
: functions(object)
);
}
var bindAll = restParam(function(object, methodNames) {
methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
var index = -1,
length = methodNames.length;
while (++index < length) {
var key = methodNames[index];
object[key] = createWrapper(object[key], BIND_FLAG, object);
}
return object;
});
module.exports = bindAll;

View File

@@ -1,6 +1,6 @@
var baseSlice = require('../internal/baseSlice'),
createWrapper = require('../internal/createWrapper'),
replaceHolders = require('../internal/replaceHolders');
var createWrapper = require('../internal/createWrapper'),
replaceHolders = require('../internal/replaceHolders'),
restParam = require('./restParam');
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
@@ -24,7 +24,7 @@ var BIND_FLAG = 1,
* @category Function
* @param {Object} object The object the method belongs to.
* @param {string} key The key of the method.
* @param {...*} [args] The arguments to be partially applied.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
@@ -51,16 +51,14 @@ var BIND_FLAG = 1,
* bound('hi');
* // => 'hiya fred!'
*/
function bindKey(object, key) {
var bindKey = restParam(function(object, key, partials) {
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
if (arguments.length > 2) {
var partials = baseSlice(arguments, 2),
holders = replaceHolders(partials, bindKey.placeholder);
if (partials.length) {
var holders = replaceHolders(partials, bindKey.placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(key, bitmask, object, partials, holders);
}
});
// Assign default placeholders.
bindKey.placeholder = {};

View File

@@ -1,5 +1,4 @@
var createWrapper = require('../internal/createWrapper'),
isIterateeCall = require('../internal/isIterateeCall');
var createCurry = require('../internal/createCurry');
/** Used to compose bitmasks for wrapper metadata. */
var CURRY_FLAG = 8;
@@ -44,14 +43,7 @@ var CURRY_FLAG = 8;
* curried(1)(_, 3)(2);
* // => [1, 2, 3]
*/
function curry(func, arity, guard) {
if (guard && isIterateeCall(func, arity, guard)) {
arity = null;
}
var result = createWrapper(func, CURRY_FLAG, null, null, null, null, null, arity);
result.placeholder = curry.placeholder;
return result;
}
var curry = createCurry(CURRY_FLAG);
// Assign default placeholders.
curry.placeholder = {};

View File

@@ -1,5 +1,4 @@
var createWrapper = require('../internal/createWrapper'),
isIterateeCall = require('../internal/isIterateeCall');
var createCurry = require('../internal/createCurry');
/** Used to compose bitmasks for wrapper metadata. */
var CURRY_RIGHT_FLAG = 16;
@@ -41,14 +40,7 @@ var CURRY_RIGHT_FLAG = 16;
* curried(3)(1, _)(2);
* // => [1, 2, 3]
*/
function curryRight(func, arity, guard) {
if (guard && isIterateeCall(func, arity, guard)) {
arity = null;
}
var result = createWrapper(func, CURRY_RIGHT_FLAG, null, null, null, null, null, arity);
result.placeholder = curryRight.placeholder;
return result;
}
var curryRight = createCurry(CURRY_RIGHT_FLAG);
// Assign default placeholders.
curryRight.placeholder = {};

View File

@@ -1,4 +1,5 @@
var baseDelay = require('../internal/baseDelay');
var baseDelay = require('../internal/baseDelay'),
restParam = require('./restParam');
/**
* Defers invoking the `func` until the current call stack has cleared. Any
@@ -17,8 +18,8 @@ var baseDelay = require('../internal/baseDelay');
* }, 'deferred');
* // logs 'deferred' after one or more milliseconds
*/
function defer(func) {
return baseDelay(func, 1, arguments, 1);
}
var defer = restParam(function(func, args) {
return baseDelay(func, 1, args);
});
module.exports = defer;

View File

@@ -1,4 +1,5 @@
var baseDelay = require('../internal/baseDelay');
var baseDelay = require('../internal/baseDelay'),
restParam = require('./restParam');
/**
* Invokes `func` after `wait` milliseconds. Any additional arguments are
@@ -18,8 +19,8 @@ var baseDelay = require('../internal/baseDelay');
* }, 1000, 'later');
* // => logs 'later' after one second
*/
function delay(func, wait) {
return baseDelay(func, wait, arguments, 2);
}
var delay = restParam(function(func, wait, args) {
return baseDelay(func, wait, args);
});
module.exports = delay;

View File

@@ -1,4 +1,4 @@
var createComposer = require('../internal/createComposer');
var createFlow = require('../internal/createFlow');
/**
* Creates a function that returns the result of invoking the provided
@@ -20,6 +20,6 @@ var createComposer = require('../internal/createComposer');
* addSquare(1, 2);
* // => 9
*/
var flow = createComposer();
var flow = createFlow();
module.exports = flow;

View File

@@ -1,4 +1,4 @@
var createComposer = require('../internal/createComposer');
var createFlow = require('../internal/createFlow');
/**
* This method is like `_.flow` except that it creates a function that
@@ -20,6 +20,6 @@ var createComposer = require('../internal/createComposer');
* addSquare(1, 2);
* // => 9
*/
var flowRight = createComposer(true);
var flowRight = createFlow(true);
module.exports = flowRight;

View File

@@ -13,10 +13,8 @@ var FUNC_ERROR_TEXT = 'Expected a function';
*
* **Note:** The cache is exposed as the `cache` property on the memoized
* function. Its creation may be customized by replacing the `_.memoize.Cache`
* constructor with one whose instances implement the ES `Map` method interface
* of `get`, `has`, and `set`. See the
* [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
* for more details.
* constructor with one whose instances implement the [`Map`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-map-prototype-object)
* method interface of `get`, `has`, and `set`.
*
* @static
* @memberOf _

View File

@@ -3,7 +3,7 @@ var before = require('./before');
/**
* Creates a function that is restricted to invoking `func` once. Repeat calls
* to the function return the value of the first call. The `func` is invoked
* with the `this` binding of the created function.
* with the `this` binding and arguments of the created function.
*
* @static
* @memberOf _

View File

@@ -1,6 +1,4 @@
var baseSlice = require('../internal/baseSlice'),
createWrapper = require('../internal/createWrapper'),
replaceHolders = require('../internal/replaceHolders');
var createPartial = require('../internal/createPartial');
/** Used to compose bitmasks for wrapper metadata. */
var PARTIAL_FLAG = 32;
@@ -20,7 +18,7 @@ var PARTIAL_FLAG = 32;
* @memberOf _
* @category Function
* @param {Function} func The function to partially apply arguments to.
* @param {...*} [args] The arguments to be partially applied.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
@@ -37,12 +35,7 @@ var PARTIAL_FLAG = 32;
* greetFred('hi');
* // => 'hi fred'
*/
function partial(func) {
var partials = baseSlice(arguments, 1),
holders = replaceHolders(partials, partial.placeholder);
return createWrapper(func, PARTIAL_FLAG, null, partials, holders);
}
var partial = createPartial(PARTIAL_FLAG);
// Assign default placeholders.
partial.placeholder = {};

View File

@@ -1,6 +1,4 @@
var baseSlice = require('../internal/baseSlice'),
createWrapper = require('../internal/createWrapper'),
replaceHolders = require('../internal/replaceHolders');
var createPartial = require('../internal/createPartial');
/** Used to compose bitmasks for wrapper metadata. */
var PARTIAL_RIGHT_FLAG = 64;
@@ -19,7 +17,7 @@ var PARTIAL_RIGHT_FLAG = 64;
* @memberOf _
* @category Function
* @param {Function} func The function to partially apply arguments to.
* @param {...*} [args] The arguments to be partially applied.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
@@ -36,12 +34,7 @@ var PARTIAL_RIGHT_FLAG = 64;
* sayHelloTo('fred');
* // => 'hello fred'
*/
function partialRight(func) {
var partials = baseSlice(arguments, 1),
holders = replaceHolders(partials, partialRight.placeholder);
return createWrapper(func, PARTIAL_RIGHT_FLAG, null, partials, holders);
}
var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
// Assign default placeholders.
partialRight.placeholder = {};

View File

@@ -1,8 +1,9 @@
var baseFlatten = require('../internal/baseFlatten'),
createWrapper = require('../internal/createWrapper');
createWrapper = require('../internal/createWrapper'),
restParam = require('./restParam');
/** Used to compose bitmasks for wrapper metadata. */
var REARG_FLAG = 128;
var REARG_FLAG = 256;
/**
* Creates a function that invokes `func` with arguments arranged according
@@ -32,9 +33,8 @@ var REARG_FLAG = 128;
* }, [1, 2, 3]);
* // => [3, 6, 9]
*/
function rearg(func) {
var indexes = baseFlatten(arguments, false, false, 1);
return createWrapper(func, REARG_FLAG, null, null, null, indexes);
}
var rearg = restParam(function(func, indexes) {
return createWrapper(func, REARG_FLAG, null, null, null, baseFlatten(indexes));
});
module.exports = rearg;

58
function/restParam.js Normal file
View File

@@ -0,0 +1,58 @@
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* Creates a function that invokes `func` with the `this` binding of the
* created function and arguments from `start` and beyond provided as an array.
*
* **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to apply a rest parameter to.
* @param {number} [start=func.length-1] The start position of the rest parameter.
* @returns {Function} Returns the new function.
* @example
*
* var say = _.restParam(function(what, names) {
* return what + ' ' + _.initial(names).join(', ') +
* (_.size(names) > 1 ? ', & ' : '') + _.last(names);
* });
*
* say('hello', 'fred', 'barney', 'pebbles');
* // => 'hello fred, barney, & pebbles'
*/
function restParam(func, start) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
start = nativeMax(typeof start == 'undefined' ? (func.length - 1) : (+start || 0), 0);
return function() {
var args = arguments,
index = -1,
length = nativeMax(args.length - start, 0),
rest = Array(length);
while (++index < length) {
rest[index] = args[start + index];
}
switch (start) {
case 0: return func.call(this, rest);
case 1: return func.call(this, args[0], rest);
case 2: return func.call(this, args[0], args[1], rest);
}
var otherArgs = Array(start + 1);
index = -1;
while (++index < start) {
otherArgs[index] = args[index];
}
otherArgs[start] = rest;
return func.apply(this, otherArgs);
};
}
module.exports = restParam;

View File

@@ -2,23 +2,24 @@
var FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a function that invokes `func` with the `this` binding of the
* created function and the array of arguments provided to the created
* function much like [Function#apply](http://es5.github.io/#x15.3.4.3).
* Creates a function that invokes `func` with the `this` binding of the created
* function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
*
* **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to spread arguments over.
* @returns {*} Returns the new function.
* @returns {Function} Returns the new function.
* @example
*
* var spread = _.spread(function(who, what) {
* var say = _.spread(function(who, what) {
* return who + ' says ' + what;
* });
*
* spread(['Fred', 'hello']);
* // => 'Fred says hello'
* say(['fred', 'hello']);
* // => 'fred says hello'
*
* // with a Promise
* var numbers = Promise.all([

1956
index.js

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/**
* A specialized version of `_.forEach` for arrays without support for callback
* shorthands or `this` binding.
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.

View File

@@ -1,6 +1,6 @@
/**
* A specialized version of `_.forEachRight` for arrays without support for
* callback shorthands or `this` binding.
* callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.

View File

@@ -1,6 +1,6 @@
/**
* A specialized version of `_.every` for arrays without support for callback
* shorthands or `this` binding.
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.

View File

@@ -1,6 +1,6 @@
/**
* A specialized version of `_.filter` for arrays without support for callback
* shorthands or `this` binding.
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.

View File

@@ -1,6 +1,6 @@
/**
* A specialized version of `_.map` for arrays without support for callback
* shorthands or `this` binding.
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.

View File

@@ -1,6 +1,6 @@
/**
* A specialized version of `_.reduce` for arrays without support for callback
* shorthands or `this` binding.
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.

View File

@@ -1,6 +1,6 @@
/**
* A specialized version of `_.reduceRight` for arrays without support for
* callback shorthands or `this` binding.
* callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.

View File

@@ -1,6 +1,6 @@
/**
* A specialized version of `_.some` for arrays without support for callback
* shorthands or `this` binding.
* shorthands and `this` binding.
*
* @private
* @param {Array} array The array to iterate over.

18
internal/arraySum.js Normal file
View File

@@ -0,0 +1,18 @@
/**
* A specialized version of `_.sum` for arrays without support for iteratees.
*
* @private
* @param {Array} array The array to iterate over.
* @returns {number} Returns the sum.
*/
function arraySum(array) {
var length = array.length,
result = 0;
while (length--) {
result += +array[length] || 0;
}
return result;
}
module.exports = arraySum;

View File

@@ -24,7 +24,7 @@ function baseAssign(object, source, customizer) {
value = object[key],
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))) {
object[key] = result;
}

View File

@@ -1,26 +0,0 @@
var createWrapper = require('./createWrapper');
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1;
/**
* The base implementation of `_.bindAll` without support for individual
* method name arguments.
*
* @private
* @param {Object} object The object to bind and assign the bound methods to.
* @param {string[]} methodNames The object method names to bind.
* @returns {Object} Returns `object`.
*/
function baseBindAll(object, methodNames) {
var index = -1,
length = methodNames.length;
while (++index < length) {
var key = methodNames[index];
object[key] = createWrapper(object[key], BIND_FLAG, object);
}
return object;
}
module.exports = baseBindAll;

View File

@@ -2,8 +2,7 @@ var baseMatches = require('./baseMatches'),
baseMatchesProperty = require('./baseMatchesProperty'),
baseProperty = require('./baseProperty'),
bindCallback = require('./bindCallback'),
identity = require('../utility/identity'),
isBindable = require('./isBindable');
identity = require('../utility/identity');
/**
* The base implementation of `_.callback` which supports specifying the
@@ -18,9 +17,9 @@ var baseMatches = require('./baseMatches'),
function baseCallback(func, thisArg, argCount) {
var type = typeof func;
if (type == 'function') {
return (typeof thisArg != 'undefined' && isBindable(func))
? bindCallback(func, thisArg, argCount)
: func;
return typeof thisArg == 'undefined'
? func
: bindCallback(func, thisArg, argCount);
}
if (func == null) {
return identity;

View File

@@ -54,9 +54,8 @@ cloneableTags[weakMapTag] = false;
var objectProto = Object.prototype;
/**
* Used to resolve the `toStringTag` of values.
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
* for more details.
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
* of values.
*/
var objToString = objectProto.toString;

View File

@@ -1,5 +1,3 @@
var baseSlice = require('./baseSlice');
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
@@ -10,14 +8,14 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* @private
* @param {Function} func The function to delay.
* @param {number} wait The number of milliseconds to delay invocation.
* @param {Object} args The `arguments` object to slice and provide to `func`.
* @param {Object} args The arguments provide to `func`.
* @returns {number} Returns the timer id.
*/
function baseDelay(func, wait, args, fromIndex) {
function baseDelay(func, wait, args) {
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);
return setTimeout(function() { func.apply(undefined, args); }, wait);
}
module.exports = baseDelay;

View File

@@ -1,6 +1,5 @@
var baseForOwn = require('./baseForOwn'),
isLength = require('./isLength'),
toObject = require('./toObject');
createBaseEach = require('./createBaseEach');
/**
* The base implementation of `_.forEach` without support for callback
@@ -11,20 +10,6 @@ var baseForOwn = require('./baseForOwn'),
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object|string} Returns `collection`.
*/
function baseEach(collection, iteratee) {
var length = collection ? collection.length : 0;
if (!isLength(length)) {
return baseForOwn(collection, iteratee);
}
var index = -1,
iterable = toObject(collection);
while (++index < length) {
if (iteratee(iterable[index], index, iterable) === false) {
break;
}
}
return collection;
}
var baseEach = createBaseEach(baseForOwn);
module.exports = baseEach;

View File

@@ -1,6 +1,5 @@
var baseForOwnRight = require('./baseForOwnRight'),
isLength = require('./isLength'),
toObject = require('./toObject');
createBaseEach = require('./createBaseEach');
/**
* The base implementation of `_.forEachRight` without support for callback
@@ -11,18 +10,6 @@ var baseForOwnRight = require('./baseForOwnRight'),
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object|string} Returns `collection`.
*/
function baseEachRight(collection, iteratee) {
var length = collection ? collection.length : 0;
if (!isLength(length)) {
return baseForOwnRight(collection, iteratee);
}
var iterable = toObject(collection);
while (length--) {
if (iteratee(iterable[length], length, iterable) === false) {
break;
}
}
return collection;
}
var baseEachRight = createBaseEach(baseForOwnRight, true);
module.exports = baseEachRight;

View File

@@ -2,7 +2,7 @@ var baseEach = require('./baseEach');
/**
* The base implementation of `_.every` without support for callback
* shorthands or `this` binding.
* shorthands and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.

View File

@@ -19,7 +19,7 @@ function baseFill(array, value, start, end) {
if (end < 0) {
end += length;
}
length = start > end ? 0 : end >>> 0;
length = start > end ? 0 : (end >>> 0);
start >>>= 0;
while (start < length) {

View File

@@ -2,7 +2,7 @@ var baseEach = require('./baseEach');
/**
* The base implementation of `_.filter` without support for callback
* shorthands or `this` binding.
* shorthands and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.

23
internal/baseFindIndex.js Normal file
View File

@@ -0,0 +1,23 @@
/**
* The base implementation of `_.findIndex` and `_.findLastIndex` without
* support for callback shorthands and `this` binding.
*
* @private
* @param {Array} array The array to search.
* @param {Function} predicate The function invoked per iteration.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function baseFindIndex(array, predicate, fromRight) {
var length = array.length,
index = fromRight ? length : -1;
while ((fromRight ? index-- : ++index < length)) {
if (predicate(array[index], index, array)) {
return index;
}
}
return -1;
}
module.exports = baseFindIndex;

View File

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

View File

@@ -1,4 +1,4 @@
var toObject = require('./toObject');
var createBaseFor = require('./createBaseFor');
/**
* The base implementation of `baseForIn` and `baseForOwn` which iterates
@@ -12,19 +12,6 @@ var toObject = require('./toObject');
* @param {Function} keysFunc The function to get the keys of `object`.
* @returns {Object} Returns `object`.
*/
function baseFor(object, iteratee, keysFunc) {
var index = -1,
iterable = toObject(object),
props = keysFunc(object),
length = props.length;
while (++index < length) {
var key = props[index];
if (iteratee(iterable[key], key, iterable) === false) {
break;
}
}
return object;
}
var baseFor = createBaseFor();
module.exports = baseFor;

View File

@@ -1,4 +1,4 @@
var toObject = require('./toObject');
var createBaseFor = require('./createBaseFor');
/**
* This function is like `baseFor` except that it iterates over properties
@@ -10,18 +10,6 @@ var toObject = require('./toObject');
* @param {Function} keysFunc The function to get the keys of `object`.
* @returns {Object} Returns `object`.
*/
function baseForRight(object, iteratee, keysFunc) {
var iterable = toObject(object),
props = keysFunc(object),
length = props.length;
while (length--) {
var key = props[length];
if (iteratee(iterable[key], key, iterable) === false) {
break;
}
}
return object;
}
var baseForRight = createBaseFor(true);
module.exports = baseForRight;

View File

@@ -1,28 +0,0 @@
var baseEach = require('./baseEach'),
isLength = require('./isLength');
/**
* The base implementation of `_.invoke` which requires additional arguments
* to be provided as an array of arguments rather than individually.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|string} methodName The name of the method to invoke or
* the function invoked per iteration.
* @param {Array} [args] The arguments to invoke the method with.
* @returns {Array} Returns the array of results.
*/
function baseInvoke(collection, methodName, args) {
var index = -1,
isFunc = typeof methodName == 'function',
length = collection ? collection.length : 0,
result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value) {
var func = isFunc ? methodName : (value != null && value[methodName]);
result[++index] = func ? func.apply(value, args) : undefined;
});
return result;
}
module.exports = baseInvoke;

View File

@@ -8,12 +8,12 @@ var baseIsEqualDeep = require('./baseIsEqualDeep');
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @param {Function} [customizer] The function to customize comparing values.
* @param {boolean} [isWhere] Specify performing partial comparisons.
* @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA] Tracks traversed `value` objects.
* @param {Array} [stackB] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/
function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) {
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
// Exit early for identical values.
if (value === other) {
// Treat `+0` vs. `-0` as not equal.
@@ -28,7 +28,7 @@ function baseIsEqual(value, other, customizer, isWhere, stackA, stackB) {
// Return `false` unless both values are `NaN`.
return value !== value && other !== other;
}
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isWhere, stackA, stackB);
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
}
module.exports = baseIsEqual;

View File

@@ -7,6 +7,7 @@ var equalArrays = require('./equalArrays'),
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
arrayTag = '[object Array]',
funcTag = '[object Function]',
objectTag = '[object Object]';
/** Used for native method references. */
@@ -16,9 +17,8 @@ var objectProto = Object.prototype;
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Used to resolve the `toStringTag` of values.
* See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
* for more details.
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
* of values.
*/
var objToString = objectProto.toString;
@@ -32,12 +32,12 @@ var objToString = objectProto.toString;
* @param {Object} other The other object to compare.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Function} [customizer] The function to customize comparing objects.
* @param {boolean} [isWhere] Specify performing partial comparisons.
* @param {boolean} [isLoose] Specify performing partial comparisons.
* @param {Array} [stackA=[]] Tracks traversed `value` objects.
* @param {Array} [stackB=[]] Tracks traversed `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function baseIsEqualDeep(object, other, equalFunc, customizer, isWhere, stackA, stackB) {
function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
var objIsArr = isArray(object),
othIsArr = isArray(other),
objTag = arrayTag,
@@ -59,21 +59,27 @@ function baseIsEqualDeep(object, other, equalFunc, customizer, isWhere, stackA,
othIsArr = isTypedArray(other);
}
}
var objIsObj = objTag == objectTag,
othIsObj = othTag == objectTag,
var objIsObj = (objTag == objectTag || (isLoose && objTag == funcTag)),
othIsObj = (othTag == objectTag || (isLoose && othTag == funcTag)),
isSameTag = objTag == othTag;
if (isSameTag && !(objIsArr || objIsObj)) {
return equalByTag(object, other, objTag);
}
var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (isLoose) {
if (!isSameTag && !(objIsObj && othIsObj)) {
return false;
}
} else {
var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (valWrapped || othWrapped) {
return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isWhere, stackA, stackB);
}
if (!isSameTag) {
return false;
if (valWrapped || othWrapped) {
return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
}
if (!isSameTag) {
return false;
}
}
// Assume cyclic values are equal.
// For more information on detecting circular references see https://es5.github.io/#JO.
@@ -90,7 +96,7 @@ function baseIsEqualDeep(object, other, equalFunc, customizer, isWhere, stackA,
stackA.push(object);
stackB.push(other);
var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isWhere, stackA, stackB);
var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
stackA.pop();
stackB.pop();

View File

@@ -1,14 +1,8 @@
var baseIsEqual = require('./baseIsEqual');
/** Used for native method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* The base implementation of `_.isMatch` without support for callback
* shorthands or `this` binding.
* shorthands and `this` binding.
*
* @private
* @param {Object} object The object to inspect.
@@ -19,30 +13,27 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/
function baseIsMatch(object, props, values, strictCompareFlags, customizer) {
var length = props.length;
if (object == null) {
return !length;
}
var index = -1,
length = props.length,
noCustomizer = !customizer;
while (++index < length) {
if ((noCustomizer && strictCompareFlags[index])
? values[index] !== object[props[index]]
: !hasOwnProperty.call(object, props[index])
: !(props[index] in object)
) {
return false;
}
}
index = -1;
while (++index < length) {
var key = props[index];
if (noCustomizer && strictCompareFlags[index]) {
var result = hasOwnProperty.call(object, key);
} else {
var objValue = object[key],
srcValue = values[index];
var key = props[index],
objValue = object[key],
srcValue = values[index];
if (noCustomizer && strictCompareFlags[index]) {
var result = typeof objValue != 'undefined' || (key in object);
} else {
result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (typeof result == 'undefined') {
result = baseIsEqual(srcValue, objValue, customizer, true);

View File

@@ -2,7 +2,7 @@ var baseEach = require('./baseEach');
/**
* The base implementation of `_.map` without support for callback shorthands
* or `this` binding.
* and `this` binding.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.

View File

@@ -1,12 +1,8 @@
var baseIsMatch = require('./baseIsMatch'),
constant = require('../utility/constant'),
isStrictComparable = require('./isStrictComparable'),
keys = require('../object/keys');
/** Used for native method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
keys = require('../object/keys'),
toObject = require('./toObject');
/**
* The base implementation of `_.matches` which does not clone `source`.
@@ -19,13 +15,17 @@ function baseMatches(source) {
var props = keys(source),
length = props.length;
if (!length) {
return constant(true);
}
if (length == 1) {
var key = props[0],
value = source[key];
if (isStrictComparable(value)) {
return function(object) {
return object != null && object[key] === value && hasOwnProperty.call(object, key);
return object != null && object[key] === value &&
(typeof value != 'undefined' || (key in toObject(object)));
};
}
}
@@ -38,7 +38,7 @@ function baseMatches(source) {
strictCompareFlags[length] = isStrictComparable(value);
}
return function(object) {
return baseIsMatch(object, props, values, strictCompareFlags);
return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags);
};
}

View File

@@ -1,5 +1,6 @@
var baseIsEqual = require('./baseIsEqual'),
isStrictComparable = require('./isStrictComparable');
isStrictComparable = require('./isStrictComparable'),
toObject = require('./toObject');
/**
* The base implementation of `_.matchesProperty` which does not coerce `key`
@@ -13,7 +14,8 @@ var baseIsEqual = require('./baseIsEqual'),
function baseMatchesProperty(key, value) {
if (isStrictComparable(value)) {
return function(object) {
return object != null && object[key] === value;
return object != null && object[key] === value &&
(typeof value != 'undefined' || (key in toObject(object)));
};
}
return function(object) {

View File

@@ -38,7 +38,7 @@ function baseMerge(object, source, customizer, stackA, stackB) {
result = srcValue;
}
if ((isSrcArr || typeof result != 'undefined') &&
(isCommon || (result === result ? result !== value : value === value))) {
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
}
});

View File

@@ -40,7 +40,7 @@ function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stack
if (isLength(srcValue.length) && (isArray(srcValue) || isTypedArray(srcValue))) {
result = isArray(value)
? value
: (value ? arrayCopy(value) : []);
: ((value && value.length) ? arrayCopy(value) : []);
}
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
result = isArguments(value)
@@ -59,7 +59,7 @@ function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stack
if (isCommon) {
// Recursively merge objects and arrays (susceptible to call stack limits).
object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
} else if (result === result ? result !== value : value === value) {
} else if (result === result ? (result !== value) : (value === value)) {
object[key] = result;
}
}

View File

@@ -1,35 +0,0 @@
var baseAt = require('./baseAt'),
baseCompareAscending = require('./baseCompareAscending'),
isIndex = require('./isIndex');
/** Used for native method references. */
var arrayProto = Array.prototype;
/** Native method references. */
var splice = arrayProto.splice;
/**
* The base implementation of `_.pullAt` without support for individual
* index arguments.
*
* @private
* @param {Array} array The array to modify.
* @param {number[]} indexes The indexes of elements to remove.
* @returns {Array} Returns the new array of removed elements.
*/
function basePullAt(array, indexes) {
var length = indexes.length,
result = baseAt(array, indexes);
indexes.sort(baseCompareAscending);
while (length--) {
var index = parseFloat(indexes[length]);
if (index != previous && isIndex(index)) {
var previous = index;
splice.call(array, index, 1);
}
}
return result;
}
module.exports = basePullAt;

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