diff --git a/README.md b/README.md
index 7c2b1729f..6d49f3441 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# lodash v3.2.0
+# lodash v3.3.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.
@@ -24,11 +24,11 @@ In Node.js/io.js:
var _ = require('lodash');
// or a method category
var array = require('lodash/array');
-// or a method
+// or a method (works great with browserify/webpack to create smaller builds)
var chunk = require('lodash/array/chunk');
```
-See the [package source](https://github.com/lodash/lodash/tree/3.2.0-npm) for more details.
+See the [package source](https://github.com/lodash/lodash/tree/3.3.0-npm) for more details.
**Note:**
Don’t assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.
@@ -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.2.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.2.0-amd) builds
- * ES modules for the [modern](https://github.com/lodash/lodash/tree/3.2.0-es) build
+ * AMD modules for [modern](https://github.com/lodash/lodash/tree/3.3.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.3.0-amd) builds
+ * ES modules for the [modern](https://github.com/lodash/lodash/tree/3.3.0-es) build
## Further Reading
@@ -69,23 +69,20 @@ lodash is also available in a variety of other builds & module formats.
* [_.curry](https://lodash.com/docs#curry) & [_.curryRight](https://lodash.com/docs#curryRight) for creating [curried](http://hughfdjackson.com/javascript/why-curry-helps/) functions
* [_.debounce](https://lodash.com/docs#debounce) & [_.throttle](https://lodash.com/docs#throttle) are cancelable & accept options for more control
* [_.fill](https://lodash.com/docs#fill) to fill arrays with values
- * [_.findIndex](https://lodash.com/docs#findIndex) & [_.findKey](https://lodash.com/docs#findKey) for finding indexes & keys
+ * [_.findKey](https://lodash.com/docs#findKey) for finding keys
* [_.flow](https://lodash.com/docs#flow) to complement [_.flowRight](https://lodash.com/docs#flowRight) (a.k.a `_.compose`)
* [_.forEach](https://lodash.com/docs#forEach) supports exiting early
* [_.forIn](https://lodash.com/docs#forIn) for iterating all enumerable properties
* [_.forOwn](https://lodash.com/docs#forOwn) for iterating own properties
* [_.includes](https://lodash.com/docs#includes) accepts a `fromIndex`
- * [_.isError](https://lodash.com/docs#isError) to check for error objects
+ * [_.inRange](https://lodash.com/docs#inRange) for checking whether a number is within a given range
* [_.isNative](https://lodash.com/docs#isNative) to check for native functions
* [_.isPlainObject](https://lodash.com/docs#isPlainObject) & [_.toPlainObject](https://lodash.com/docs#toPlainObject) to check for & convert to `Object` objects
* [_.isTypedArray](https://lodash.com/docs#isTypedArray) to check for typed arrays
- * [_.keysIn](https://lodash.com/docs#keysIn) & [_.valuesIn](https://lodash.com/docs#valuesIn) for getting keys & values of all enumerable properties
- * [_.mapValues](https://lodash.com/docs#mapValues) for [mapping](https://lodash.com/docs#map) values to an object
* [_.matches](https://lodash.com/docs#matches) supports deep object comparisons
* [_.matchesProperty](https://lodash.com/docs#matchesProperty) to complement [_.matches](https://lodash.com/docs#matches) & [_.property](https://lodash.com/docs#property)
* [_.merge](https://lodash.com/docs#merge) for a deep [_.extend](https://lodash.com/docs#extend)
* [_.parseInt](https://lodash.com/docs#parseInt) for consistent cross-environment behavior
- * [_.propertyOf](https://lodash.com/docs#propertyOf) to complement [_.property](https://lodash.com/docs#property)
* [_.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
* [_.runInContext](https://lodash.com/docs#runInContext) for collisionless mixins & easier mocking
@@ -96,6 +93,7 @@ lodash is also available in a variety of other builds & module formats.
* [_.template](https://lodash.com/docs#template) supports [*“imports”*](https://lodash.com/docs#templateSettings-imports) options & [ES template delimiters](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
* [_.transform](https://lodash.com/docs#transform) as a powerful alternative to [_.reduce](https://lodash.com/docs#reduce) for transforming objects
* [_.xor](https://lodash.com/docs#xor) to complement [_.difference](https://lodash.com/docs#difference), [_.intersection](https://lodash.com/docs#intersection), & [_.union](https://lodash.com/docs#union)
+ * [_.valuesIn](https://lodash.com/docs#valuesIn) for getting values of all enumerable properties
* [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), &
[more](https://lodash.com/docs "_.bindKey, _.curryRight, _.partialRight") support customizable argument placeholders
* [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), &
@@ -104,8 +102,8 @@ lodash is also available in a variety of other builds & module formats.
[more](https://lodash.com/docs "_.assign, _.cloneDeep, _.merge") accept callbacks
* [_.dropWhile](https://lodash.com/docs#dropWhile), [_.takeWhile](https://lodash.com/docs#takeWhile), &
[more](https://lodash.com/docs "_.drop, _.dropRightWhile, _.take, _.takeRightWhile") to complement [_.first](https://lodash.com/docs#first), [_.initial](https://lodash.com/docs#initial), [_.last](https://lodash.com/docs#last), & [_.rest](https://lodash.com/docs#rest)
- * [_.findLast](https://lodash.com/docs#findLast), [_.findLastIndex](https://lodash.com/docs#findLastIndex), &
- [more](https://lodash.com/docs "_.findLastKey, _.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.partialRight") right-associative methods
+ * [_.findLast](https://lodash.com/docs#findLast), [_.findLastKey](https://lodash.com/docs#findLastKey), &
+ [more](https://lodash.com/docs "_.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.partialRight") right-associative methods
* [_.includes](https://lodash.com/docs#includes), [_.toArray](https://lodash.com/docs#toArray), &
[more](https://lodash.com/docs "_.at, _.countBy, _.every, _.filter, _.find, _.findLast, _.forEach, _.forEachRight, _.groupBy, _.indexBy, _.invoke, _.map, _.max, _.min, _.partition, _.pluck, _.reduce, _.reduceRight, _.reject, _.shuffle, _.size, _.some, _.sortBy") accept strings
* [_#commit](https://lodash.com/docs#prototype-commit) & [_#plant](https://lodash.com/docs#prototype-plant) for working with chain sequences
diff --git a/array/difference.js b/array/difference.js
index 67ee055e9..504d4b5ad 100644
--- a/array/difference.js
+++ b/array/difference.js
@@ -20,7 +20,7 @@ var baseDifference = require('../internal/baseDifference'),
* @returns {Array} Returns the new array of filtered values.
* @example
*
- * _.difference([1, 2, 3], [5, 2, 10]);
+ * _.difference([1, 2, 3], [4, 2]);
* // => [1, 3]
*/
function difference() {
diff --git a/array/dropRightWhile.js b/array/dropRightWhile.js
index 7e0b455aa..1e12998a5 100644
--- a/array/dropRightWhile.js
+++ b/array/dropRightWhile.js
@@ -27,7 +27,9 @@ var baseCallback = require('../internal/baseCallback'),
* @returns {Array} Returns the slice of `array`.
* @example
*
- * _.dropRightWhile([1, 2, 3], function(n) { return n > 1; });
+ * _.dropRightWhile([1, 2, 3], function(n) {
+ * return n > 1;
+ * });
* // => [1]
*
* var users = [
diff --git a/array/dropWhile.js b/array/dropWhile.js
index 5123bc8cf..2c8809969 100644
--- a/array/dropWhile.js
+++ b/array/dropWhile.js
@@ -27,7 +27,9 @@ var baseCallback = require('../internal/baseCallback'),
* @returns {Array} Returns the slice of `array`.
* @example
*
- * _.dropWhile([1, 2, 3], function(n) { return n < 3; });
+ * _.dropWhile([1, 2, 3], function(n) {
+ * return n < 3;
+ * });
* // => [3]
*
* var users = [
diff --git a/array/findIndex.js b/array/findIndex.js
index f44b5d153..0c2ef3051 100644
--- a/array/findIndex.js
+++ b/array/findIndex.js
@@ -31,7 +31,9 @@ var baseCallback = require('../internal/baseCallback');
* { 'user': 'pebbles', 'active': true }
* ];
*
- * _.findIndex(users, function(chr) { return chr.user == 'barney'; });
+ * _.findIndex(users, function(chr) {
+ * return chr.user == 'barney';
+ * });
* // => 0
*
* // using the `_.matches` callback shorthand
diff --git a/array/findLastIndex.js b/array/findLastIndex.js
index 0d5ac4576..0acc46df5 100644
--- a/array/findLastIndex.js
+++ b/array/findLastIndex.js
@@ -31,7 +31,9 @@ var baseCallback = require('../internal/baseCallback');
* { 'user': 'pebbles', 'active': false }
* ];
*
- * _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; });
+ * _.findLastIndex(users, function(chr) {
+ * return chr.user == 'pebbles';
+ * });
* // => 2
*
* // using the `_.matches` callback shorthand
diff --git a/array/flatten.js b/array/flatten.js
index c0fabd036..6eb989a31 100644
--- a/array/flatten.js
+++ b/array/flatten.js
@@ -14,11 +14,11 @@ var baseFlatten = require('../internal/baseFlatten'),
* @returns {Array} Returns the new flattened array.
* @example
*
- * _.flatten([1, [2], [3, [[4]]]]);
- * // => [1, 2, 3, [[4]]];
+ * _.flatten([1, [2, 3, [4]]]);
+ * // => [1, 2, 3, [4]];
*
* // using `isDeep`
- * _.flatten([1, [2], [3, [[4]]]], true);
+ * _.flatten([1, [2, 3, [4]]], true);
* // => [1, 2, 3, 4];
*/
function flatten(array, isDeep, guard) {
diff --git a/array/flattenDeep.js b/array/flattenDeep.js
index a38bc708d..aa329b765 100644
--- a/array/flattenDeep.js
+++ b/array/flattenDeep.js
@@ -10,7 +10,7 @@ var baseFlatten = require('../internal/baseFlatten');
* @returns {Array} Returns the new flattened array.
* @example
*
- * _.flattenDeep([1, [2], [3, [[4]]]]);
+ * _.flattenDeep([1, [2, 3, [4]]]);
* // => [1, 2, 3, 4];
*/
function flattenDeep(array) {
diff --git a/array/indexOf.js b/array/indexOf.js
index afcdea40d..3708b79db 100644
--- a/array/indexOf.js
+++ b/array/indexOf.js
@@ -25,15 +25,15 @@ var nativeMax = Math.max;
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
- * _.indexOf([1, 2, 3, 1, 2, 3], 2);
- * // => 1
+ * _.indexOf([1, 2, 1, 2], 2);
+ * // => 2
*
* // using `fromIndex`
- * _.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
- * // => 4
+ * _.indexOf([1, 2, 1, 2], 2, 2);
+ * // => 3
*
* // performing a binary search
- * _.indexOf([4, 4, 5, 5, 6, 6], 5, true);
+ * _.indexOf([1, 1, 2, 2], 2, true);
* // => 2
*/
function indexOf(array, value, fromIndex) {
diff --git a/array/intersection.js b/array/intersection.js
index 9d25fabf2..f074cfadc 100644
--- a/array/intersection.js
+++ b/array/intersection.js
@@ -19,9 +19,8 @@ var baseIndexOf = require('../internal/baseIndexOf'),
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of shared values.
* @example
- *
- * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]);
- * // => [1, 2]
+ * _.intersection([1, 2], [4, 2], [2, 1]);
+ * // => [2]
*/
function intersection() {
var args = [],
diff --git a/array/lastIndexOf.js b/array/lastIndexOf.js
index e8daa53c0..8d6650b08 100644
--- a/array/lastIndexOf.js
+++ b/array/lastIndexOf.js
@@ -19,15 +19,15 @@ var nativeMax = Math.max,
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
- * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
- * // => 4
+ * _.lastIndexOf([1, 2, 1, 2], 2);
+ * // => 3
*
* // using `fromIndex`
- * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
+ * _.lastIndexOf([1, 2, 1, 2], 2, 2);
* // => 1
*
* // performing a binary search
- * _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true);
+ * _.lastIndexOf([1, 1, 2, 2], 2, true);
* // => 3
*/
function lastIndexOf(array, value, fromIndex) {
diff --git a/array/pull.js b/array/pull.js
index 70a118140..b92d7d27a 100644
--- a/array/pull.js
+++ b/array/pull.js
@@ -25,6 +25,7 @@ var splice = arrayProto.splice;
* @example
*
* var array = [1, 2, 3, 1, 2, 3];
+ *
* _.pull(array, 2, 3);
* console.log(array);
* // => [1, 1]
diff --git a/array/pullAt.js b/array/pullAt.js
index 01ca5d1f1..706e73cf9 100644
--- a/array/pullAt.js
+++ b/array/pullAt.js
@@ -18,7 +18,7 @@ var baseFlatten = require('../internal/baseFlatten'),
* @example
*
* var array = [5, 10, 15, 20];
- * var evens = _.pullAt(array, [1, 3]);
+ * var evens = _.pullAt(array, 1, 3);
*
* console.log(array);
* // => [5, 15]
diff --git a/array/remove.js b/array/remove.js
index ab545da2c..52fc526e5 100644
--- a/array/remove.js
+++ b/array/remove.js
@@ -35,7 +35,9 @@ var splice = arrayProto.splice;
* @example
*
* 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);
* // => [1, 3]
diff --git a/array/sortedIndex.js b/array/sortedIndex.js
index 9a0abe9e5..fdc5e305e 100644
--- a/array/sortedIndex.js
+++ b/array/sortedIndex.js
@@ -35,7 +35,7 @@ var baseCallback = require('../internal/baseCallback'),
* _.sortedIndex([30, 50], 40);
* // => 1
*
- * _.sortedIndex([4, 4, 5, 5, 6, 6], 5);
+ * _.sortedIndex([4, 4, 5, 5], 5);
* // => 2
*
* var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
diff --git a/array/sortedLastIndex.js b/array/sortedLastIndex.js
index 21d643ff4..6936d4e6c 100644
--- a/array/sortedLastIndex.js
+++ b/array/sortedLastIndex.js
@@ -19,7 +19,7 @@ var baseCallback = require('../internal/baseCallback'),
* into `array`.
* @example
*
- * _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5);
+ * _.sortedLastIndex([4, 4, 5, 5], 5);
* // => 4
*/
function sortedLastIndex(array, value, iteratee, thisArg) {
diff --git a/array/takeRightWhile.js b/array/takeRightWhile.js
index 65e6010a8..57bb0ef06 100644
--- a/array/takeRightWhile.js
+++ b/array/takeRightWhile.js
@@ -27,7 +27,9 @@ var baseCallback = require('../internal/baseCallback'),
* @returns {Array} Returns the slice of `array`.
* @example
*
- * _.takeRightWhile([1, 2, 3], function(n) { return n > 1; });
+ * _.takeRightWhile([1, 2, 3], function(n) {
+ * return n > 1;
+ * });
* // => [2, 3]
*
* var users = [
diff --git a/array/takeWhile.js b/array/takeWhile.js
index ede84b031..890e34a60 100644
--- a/array/takeWhile.js
+++ b/array/takeWhile.js
@@ -27,7 +27,9 @@ var baseCallback = require('../internal/baseCallback'),
* @returns {Array} Returns the slice of `array`.
* @example
*
- * _.takeWhile([1, 2, 3], function(n) { return n < 3; });
+ * _.takeWhile([1, 2, 3], function(n) {
+ * return n < 3;
+ * });
* // => [1, 2]
*
* var users = [
diff --git a/array/union.js b/array/union.js
index ff9e377d8..83f49e0cb 100644
--- a/array/union.js
+++ b/array/union.js
@@ -17,8 +17,8 @@ var baseFlatten = require('../internal/baseFlatten'),
* @returns {Array} Returns the new array of combined values.
* @example
*
- * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]);
- * // => [1, 2, 3, 5, 4]
+ * _.union([1, 2], [4, 2], [2, 1]);
+ * // => [1, 2, 4]
*/
function union() {
return baseUniq(baseFlatten(arguments, false, true));
diff --git a/array/uniq.js b/array/uniq.js
index 6d1462bc0..6b3032809 100644
--- a/array/uniq.js
+++ b/array/uniq.js
@@ -46,7 +46,9 @@ var baseCallback = require('../internal/baseCallback'),
* // => [1, 2]
*
* // 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]
*
* // using the `_.property` callback shorthand
@@ -58,8 +60,7 @@ function uniq(array, isSorted, iteratee, thisArg) {
if (!length) {
return [];
}
- // Juggle arguments.
- if (typeof isSorted != 'boolean' && isSorted != null) {
+ if (isSorted != null && typeof isSorted != 'boolean') {
thisArg = iteratee;
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
isSorted = false;
diff --git a/array/without.js b/array/without.js
index d33568884..e74c40396 100644
--- a/array/without.js
+++ b/array/without.js
@@ -18,8 +18,8 @@ var baseDifference = require('../internal/baseDifference'),
* @returns {Array} Returns the new array of filtered values.
* @example
*
- * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
- * // => [2, 3, 4]
+ * _.without([1, 2, 1, 3], 1, 2);
+ * // => [3]
*/
function without(array) {
return baseDifference(array, baseSlice(arguments, 1));
diff --git a/array/xor.js b/array/xor.js
index a1f31796d..fcdec8eb5 100644
--- a/array/xor.js
+++ b/array/xor.js
@@ -15,11 +15,8 @@ var baseDifference = require('../internal/baseDifference'),
* @returns {Array} Returns the new array of values.
* @example
*
- * _.xor([1, 2, 3], [5, 2, 1, 4]);
- * // => [3, 5, 4]
- *
- * _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
- * // => [1, 4, 5]
+ * _.xor([1, 2], [4, 2]);
+ * // => [1, 4]
*/
function xor() {
var index = -1,
diff --git a/chain/chain.js b/chain/chain.js
index 36cc3d37f..453ba1eb5 100644
--- a/chain/chain.js
+++ b/chain/chain.js
@@ -19,7 +19,9 @@ var lodash = require('./lodash');
*
* var youngest = _.chain(users)
* .sortBy('age')
- * .map(function(chr) { return chr.user + ' is ' + chr.age; })
+ * .map(function(chr) {
+ * return chr.user + ' is ' + chr.age;
+ * })
* .first()
* .value();
* // => 'pebbles is 1'
diff --git a/chain/lodash.js b/chain/lodash.js
index ad9087656..a2672a51d 100644
--- a/chain/lodash.js
+++ b/chain/lodash.js
@@ -1,5 +1,6 @@
var LazyWrapper = require('../internal/LazyWrapper'),
LodashWrapper = require('../internal/LodashWrapper'),
+ baseLodash = require('../internal/baseLodash'),
isArray = require('../lang/isArray'),
isObjectLike = require('../internal/isObjectLike'),
wrapperClone = require('../internal/wrapperClone');
@@ -82,11 +83,15 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* var wrapped = _([1, 2, 3]);
*
* // returns an unwrapped value
- * wrapped.reduce(function(sum, n) { return sum + n; });
+ * wrapped.reduce(function(sum, n) {
+ * return sum + n;
+ * });
* // => 6
*
* // returns a wrapped value
- * var squares = wrapped.map(function(n) { return n * n; });
+ * var squares = wrapped.map(function(n) {
+ * return n * n;
+ * });
*
* _.isArray(squares);
* // => false
@@ -106,4 +111,7 @@ function lodash(value) {
return new LodashWrapper(value);
}
+// Ensure wrappers are instances of `baseLodash`.
+lodash.prototype = baseLodash.prototype;
+
module.exports = lodash;
diff --git a/chain/tap.js b/chain/tap.js
index c41378591..3d0257ecf 100644
--- a/chain/tap.js
+++ b/chain/tap.js
@@ -14,7 +14,9 @@
* @example
*
* _([1, 2, 3])
- * .tap(function(array) { array.pop(); })
+ * .tap(function(array) {
+ * array.pop();
+ * })
* .reverse()
* .value();
* // => [2, 1]
diff --git a/chain/thru.js b/chain/thru.js
index 13e19a298..8ccc99696 100644
--- a/chain/thru.js
+++ b/chain/thru.js
@@ -12,7 +12,9 @@
*
* _([1, 2, 3])
* .last()
- * .thru(function(value) { return [value]; })
+ * .thru(function(value) {
+ * return [value];
+ * })
* .value();
* // => [3]
*/
diff --git a/chain/wrapperPlant.js b/chain/wrapperPlant.js
index 5b94c488a..a3de146b1 100644
--- a/chain/wrapperPlant.js
+++ b/chain/wrapperPlant.js
@@ -1,4 +1,4 @@
-var LodashWrapper = require('../internal/LodashWrapper'),
+var baseLodash = require('../internal/baseLodash'),
wrapperClone = require('../internal/wrapperClone');
/**
@@ -28,7 +28,7 @@ function wrapperPlant(value) {
var result,
parent = this;
- while (parent instanceof LodashWrapper) {
+ while (parent instanceof baseLodash) {
var clone = wrapperClone(parent);
if (result) {
previous.__wrapped__ = clone;
diff --git a/collection/at.js b/collection/at.js
index dd50050b2..48a714f6b 100644
--- a/collection/at.js
+++ b/collection/at.js
@@ -17,8 +17,8 @@ var baseAt = require('../internal/baseAt'),
* @returns {Array} Returns the new array of picked elements.
* @example
*
- * _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
- * // => ['a', 'c', 'e']
+ * _.at(['a', 'b', 'c'], [0, 2]);
+ * // => ['a', 'c']
*
* _.at(['fred', 'barney', 'pebbles'], 0, 2);
* // => ['fred', 'pebbles']
diff --git a/collection/countBy.js b/collection/countBy.js
index f0d743365..7702d7bf1 100644
--- a/collection/countBy.js
+++ b/collection/countBy.js
@@ -34,10 +34,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @returns {Object} Returns the composed aggregate object.
* @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 }
*
- * _.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 }
*
* _.countBy(['one', 'two', 'three'], 'length');
diff --git a/collection/filter.js b/collection/filter.js
index 320b903a6..673ae22b8 100644
--- a/collection/filter.js
+++ b/collection/filter.js
@@ -30,8 +30,10 @@ var arrayFilter = require('../internal/arrayFilter'),
* @returns {Array} Returns the new filtered array.
* @example
*
- * var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; });
- * // => [2, 4]
+ * _.filter([4, 5, 6], function(n) {
+ * return n % 2 == 0;
+ * });
+ * // => [4, 6]
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': true },
diff --git a/collection/find.js b/collection/find.js
index 497a3fb95..8e687d833 100644
--- a/collection/find.js
+++ b/collection/find.js
@@ -37,7 +37,9 @@ var baseCallback = require('../internal/baseCallback'),
* { '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'
*
* // using the `_.matches` callback shorthand
diff --git a/collection/findLast.js b/collection/findLast.js
index d7d0545b0..f66f6cc85 100644
--- a/collection/findLast.js
+++ b/collection/findLast.js
@@ -16,7 +16,9 @@ var baseCallback = require('../internal/baseCallback'),
* @returns {*} Returns the matched element, else `undefined`.
* @example
*
- * _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; });
+ * _.findLast([1, 2, 3, 4], function(n) {
+ * return n % 2 == 1;
+ * });
* // => 3
*/
function findLast(collection, predicate, thisArg) {
diff --git a/collection/forEach.js b/collection/forEach.js
index 929407205..38cf79672 100644
--- a/collection/forEach.js
+++ b/collection/forEach.js
@@ -23,10 +23,14 @@ var arrayEach = require('../internal/arrayEach'),
* @returns {Array|Object|string} Returns `collection`.
* @example
*
- * _([1, 2, 3]).forEach(function(n) { console.log(n); }).value();
+ * _([1, 2]).forEach(function(n) {
+ * console.log(n);
+ * }).value();
* // => logs each value from left to right and returns the array
*
- * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });
+ * _.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)
*/
function forEach(collection, iteratee, thisArg) {
diff --git a/collection/forEachRight.js b/collection/forEachRight.js
index 5fce75d98..56bb8ffe3 100644
--- a/collection/forEachRight.js
+++ b/collection/forEachRight.js
@@ -17,7 +17,9 @@ var arrayEachRight = require('../internal/arrayEachRight'),
* @returns {Array|Object|string} Returns `collection`.
* @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
*/
function forEachRight(collection, iteratee, thisArg) {
diff --git a/collection/groupBy.js b/collection/groupBy.js
index 2231c10e6..f2578b3f9 100644
--- a/collection/groupBy.js
+++ b/collection/groupBy.js
@@ -34,10 +34,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @returns {Object} Returns the composed aggregate object.
* @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] }
*
- * _.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] }
*
* // using the `_.property` callback shorthand
diff --git a/collection/indexBy.js b/collection/indexBy.js
index a9cbcda77..0cc42d5fe 100644
--- a/collection/indexBy.js
+++ b/collection/indexBy.js
@@ -36,10 +36,14 @@ var createAggregator = require('../internal/createAggregator');
* _.indexBy(keyData, 'dir');
* // => { '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 } }
*
- * _.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 } }
*/
var indexBy = createAggregator(function(result, value, key) {
diff --git a/collection/map.js b/collection/map.js
index 48e9f7a71..f918be61c 100644
--- a/collection/map.js
+++ b/collection/map.js
@@ -40,11 +40,15 @@ var arrayMap = require('../internal/arrayMap'),
* @returns {Array} Returns the new mapped array.
* @example
*
- * _.map([1, 2, 3], function(n) { return n * 3; });
- * // => [3, 6, 9]
+ * function timesThree(n) {
+ * return n * 3;
+ * }
*
- * _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; });
- * // => [3, 6, 9] (iteration order is not guaranteed)
+ * _.map([1, 2], timesThree);
+ * // => [3, 6]
+ *
+ * _.map({ 'a': 1, 'b': 2 }, timesThree);
+ * // => [3, 6] (iteration order is not guaranteed)
*
* var users = [
* { 'user': 'barney' },
diff --git a/collection/max.js b/collection/max.js
index 60a29a4c1..3fced4c10 100644
--- a/collection/max.js
+++ b/collection/max.js
@@ -39,7 +39,9 @@ var arrayMax = require('../internal/arrayMax'),
* { 'user': 'fred', 'age': 40 }
* ];
*
- * _.max(users, function(chr) { return chr.age; });
+ * _.max(users, function(chr) {
+ * return chr.age;
+ * });
* // => { 'user': 'fred', 'age': 40 };
*
* // using the `_.property` callback shorthand
diff --git a/collection/min.js b/collection/min.js
index f96cb612a..d5a9b6db5 100644
--- a/collection/min.js
+++ b/collection/min.js
@@ -39,7 +39,9 @@ var arrayMin = require('../internal/arrayMin'),
* { 'user': 'fred', 'age': 40 }
* ];
*
- * _.min(users, function(chr) { return chr.age; });
+ * _.min(users, function(chr) {
+ * return chr.age;
+ * });
* // => { 'user': 'barney', 'age': 36 };
*
* // using the `_.property` callback shorthand
diff --git a/collection/partition.js b/collection/partition.js
index fd4e3677f..2d97a924d 100644
--- a/collection/partition.js
+++ b/collection/partition.js
@@ -27,10 +27,14 @@ var createAggregator = require('../internal/createAggregator');
* @returns {Array} Returns the array of grouped elements.
* @example
*
- * _.partition([1, 2, 3], function(n) { return n % 2; });
+ * _.partition([1, 2, 3], function(n) {
+ * return n % 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) {
+ * return this.floor(n) % 2;
+ * }, Math);
* // => [[1, 3], [2]]
*
* var users = [
@@ -39,7 +43,9 @@ var createAggregator = require('../internal/createAggregator');
* { 'user': 'pebbles', 'age': 1, 'active': false }
* ];
*
- * var mapper = function(array) { return _.pluck(array, 'user'); };
+ * var mapper = function(array) {
+ * return _.pluck(array, 'user');
+ * };
*
* // using the `_.matches` callback shorthand
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
diff --git a/collection/reduce.js b/collection/reduce.js
index 0ddf678e6..f02fd9c8f 100644
--- a/collection/reduce.js
+++ b/collection/reduce.js
@@ -29,14 +29,16 @@ var arrayReduce = require('../internal/arrayReduce'),
* @returns {*} Returns the accumulated value.
* @example
*
- * var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; });
- * // => 6
+ * _.reduce([1, 2], function(sum, n) {
+ * 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;
* 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) {
var func = isArray(collection) ? arrayReduce : baseReduce;
diff --git a/collection/reduceRight.js b/collection/reduceRight.js
index 48329451c..d51763245 100644
--- a/collection/reduceRight.js
+++ b/collection/reduceRight.js
@@ -20,7 +20,10 @@ var arrayReduceRight = require('../internal/arrayReduceRight'),
* @example
*
* 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]
*/
function reduceRight(collection, iteratee, accumulator, thisArg) {
diff --git a/collection/reject.js b/collection/reject.js
index e2e894e9c..e783fc7dd 100644
--- a/collection/reject.js
+++ b/collection/reject.js
@@ -28,7 +28,9 @@ var arrayFilter = require('../internal/arrayFilter'),
* @returns {Array} Returns the new filtered array.
* @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]
*
* var users = [
diff --git a/collection/size.js b/collection/size.js
index 5c87062c7..78f937e75 100644
--- a/collection/size.js
+++ b/collection/size.js
@@ -12,12 +12,12 @@ var isLength = require('../internal/isLength'),
* @returns {number} Returns the size of `collection`.
* @example
*
- * _.size([1, 2]);
- * // => 2
- *
- * _.size({ 'one': 1, 'two': 2, 'three': 3 });
+ * _.size([1, 2, 3]);
* // => 3
*
+ * _.size({ 'a': 1, 'b': 2 });
+ * // => 2
+ *
* _.size('pebbles');
* // => 7
*/
diff --git a/collection/sortBy.js b/collection/sortBy.js
index 321e52b57..077c44108 100644
--- a/collection/sortBy.js
+++ b/collection/sortBy.js
@@ -34,10 +34,14 @@ var baseCallback = require('../internal/baseCallback'),
* @returns {Array} Returns the new sorted array.
* @example
*
- * _.sortBy([1, 2, 3], function(n) { return Math.sin(n); });
+ * _.sortBy([1, 2, 3], function(n) {
+ * return Math.sin(n);
+ * });
* // => [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]
*
* var users = [
diff --git a/date/now.js b/date/now.js
index bca560496..628225d2a 100644
--- a/date/now.js
+++ b/date/now.js
@@ -12,7 +12,9 @@ var nativeNow = isNative(nativeNow = Date.now) && nativeNow;
* @category Date
* @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
*/
var now = nativeNow || function() {
diff --git a/function/bindAll.js b/function/bindAll.js
index f864a86d5..82db5dc04 100644
--- a/function/bindAll.js
+++ b/function/bindAll.js
@@ -21,7 +21,9 @@ var baseBindAll = require('../internal/baseBindAll'),
*
* var view = {
* 'label': 'docs',
- * 'onClick': function() { console.log('clicked ' + this.label); }
+ * 'onClick': function() {
+ * console.log('clicked ' + this.label);
+ * }
* };
*
* _.bindAll(view);
diff --git a/function/defer.js b/function/defer.js
index a1376f49b..ed31c24e1 100644
--- a/function/defer.js
+++ b/function/defer.js
@@ -12,7 +12,9 @@ var baseDelay = require('../internal/baseDelay');
* @returns {number} Returns the timer id.
* @example
*
- * _.defer(function(text) { console.log(text); }, 'deferred');
+ * _.defer(function(text) {
+ * console.log(text);
+ * }, 'deferred');
* // logs 'deferred' after one or more milliseconds
*/
function defer(func) {
diff --git a/function/delay.js b/function/delay.js
index 022fadcf4..889e57778 100644
--- a/function/delay.js
+++ b/function/delay.js
@@ -13,7 +13,9 @@ var baseDelay = require('../internal/baseDelay');
* @returns {number} Returns the timer id.
* @example
*
- * _.delay(function(text) { console.log(text); }, 1000, 'later');
+ * _.delay(function(text) {
+ * console.log(text);
+ * }, 1000, 'later');
* // => logs 'later' after one second
*/
function delay(func, wait) {
diff --git a/function/flow.js b/function/flow.js
index 5d2fd7f00..aaeadce31 100644
--- a/function/flow.js
+++ b/function/flow.js
@@ -1,5 +1,5 @@
var arrayEvery = require('../internal/arrayEvery'),
- isFunction = require('../lang/isFunction');
+ baseIsFunction = require('../internal/baseIsFunction');
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
@@ -35,7 +35,7 @@ function flow() {
if (!length) {
return function() { return arguments[0]; };
}
- if (!arrayEvery(funcs, isFunction)) {
+ if (!arrayEvery(funcs, baseIsFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function() {
diff --git a/function/flowRight.js b/function/flowRight.js
index adeafaf2e..29c59c418 100644
--- a/function/flowRight.js
+++ b/function/flowRight.js
@@ -1,5 +1,5 @@
var arrayEvery = require('../internal/arrayEvery'),
- isFunction = require('../lang/isFunction');
+ baseIsFunction = require('../internal/baseIsFunction');
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
@@ -35,7 +35,7 @@ function flowRight() {
if (fromIndex < 0) {
return function() { return arguments[0]; };
}
- if (!arrayEvery(funcs, isFunction)) {
+ if (!arrayEvery(funcs, baseIsFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function() {
diff --git a/function/rearg.js b/function/rearg.js
index 6522b75f7..a1bcd5296 100644
--- a/function/rearg.js
+++ b/function/rearg.js
@@ -27,7 +27,9 @@ var REARG_FLAG = 128;
* // => ['a', 'b', 'c']
*
* 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]
*/
function rearg(func) {
diff --git a/function/throttle.js b/function/throttle.js
index 57ce634f4..10ea74123 100644
--- a/function/throttle.js
+++ b/function/throttle.js
@@ -43,8 +43,9 @@ var debounceOptions = {
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
*
* // 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', throttled);
+ * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
+ * 'trailing': false
+ * }));
*
* // cancel a trailing throttled call
* jQuery(window).on('popstate', throttled.cancel);
diff --git a/index.js b/index.js
index 8f556b7b1..ab760a0c8 100644
--- a/index.js
+++ b/index.js
@@ -1,6 +1,6 @@
/**
* @license
- * lodash 3.2.0 (Custom Build)
+ * lodash 3.3.0 (Custom Build)
* Build: `lodash modern -d -o ./index.js`
* Copyright 2012-2015 The Dojo Foundation
* Based on Underscore.js 1.7.0
@@ -13,7 +13,7 @@
var undefined;
/** Used as the semantic version number. */
- var VERSION = '3.2.0';
+ var VERSION = '3.3.0';
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
@@ -326,6 +326,20 @@
return -1;
}
+ /**
+ * 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;
+ }
+
/**
* The base implementation of `_.sortBy` and `_.sortByAll` which uses `comparer`
* to define the sort order of `array` and replaces criteria objects with their
@@ -850,11 +864,15 @@
* var wrapped = _([1, 2, 3]);
*
* // returns an unwrapped value
- * wrapped.reduce(function(sum, n) { return sum + n; });
+ * wrapped.reduce(function(sum, n) {
+ * return sum + n;
+ * });
* // => 6
*
* // returns a wrapped value
- * var squares = wrapped.map(function(n) { return n * n; });
+ * var squares = wrapped.map(function(n) {
+ * return n * n;
+ * });
*
* _.isArray(squares);
* // => false
@@ -874,6 +892,15 @@
return new LodashWrapper(value);
}
+ /**
+ * The function whose prototype all chaining wrappers inherit from.
+ *
+ * @private
+ */
+ function baseLodash() {
+ // No operation performed.
+ }
+
/**
* The base constructor for creating `lodash` wrapper objects.
*
@@ -2362,8 +2389,10 @@
* @returns {Object} Returns the destination object.
*/
function baseMerge(object, source, customizer, stackA, stackB) {
+ if (!isObject(object)) {
+ return object;
+ }
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
-
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
if (isObjectLike(srcValue)) {
stackA || (stackA = []);
@@ -3647,7 +3676,8 @@
} else {
prereq = type == 'string' && index in object;
}
- return prereq && object[index] === value;
+ var other = object[index];
+ return prereq && (value === value ? value === other : other !== other);
}
/**
@@ -4042,7 +4072,7 @@
* @returns {Array} Returns the new array of filtered values.
* @example
*
- * _.difference([1, 2, 3], [5, 2, 10]);
+ * _.difference([1, 2, 3], [4, 2]);
* // => [1, 3]
*/
function difference() {
@@ -4155,7 +4185,9 @@
* @returns {Array} Returns the slice of `array`.
* @example
*
- * _.dropRightWhile([1, 2, 3], function(n) { return n > 1; });
+ * _.dropRightWhile([1, 2, 3], function(n) {
+ * return n > 1;
+ * });
* // => [1]
*
* var users = [
@@ -4212,7 +4244,9 @@
* @returns {Array} Returns the slice of `array`.
* @example
*
- * _.dropWhile([1, 2, 3], function(n) { return n < 3; });
+ * _.dropWhile([1, 2, 3], function(n) {
+ * return n < 3;
+ * });
* // => [3]
*
* var users = [
@@ -4302,7 +4336,9 @@
* { 'user': 'pebbles', 'active': true }
* ];
*
- * _.findIndex(users, function(chr) { return chr.user == 'barney'; });
+ * _.findIndex(users, function(chr) {
+ * return chr.user == 'barney';
+ * });
* // => 0
*
* // using the `_.matches` callback shorthand
@@ -4361,7 +4397,9 @@
* { 'user': 'pebbles', 'active': false }
* ];
*
- * _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; });
+ * _.findLastIndex(users, function(chr) {
+ * return chr.user == 'pebbles';
+ * });
* // => 2
*
* // using the `_.matches` callback shorthand
@@ -4421,11 +4459,11 @@
* @returns {Array} Returns the new flattened array.
* @example
*
- * _.flatten([1, [2], [3, [[4]]]]);
- * // => [1, 2, 3, [[4]]];
+ * _.flatten([1, [2, 3, [4]]]);
+ * // => [1, 2, 3, [4]];
*
* // using `isDeep`
- * _.flatten([1, [2], [3, [[4]]]], true);
+ * _.flatten([1, [2, 3, [4]]], true);
* // => [1, 2, 3, 4];
*/
function flatten(array, isDeep, guard) {
@@ -4446,7 +4484,7 @@
* @returns {Array} Returns the new flattened array.
* @example
*
- * _.flattenDeep([1, [2], [3, [[4]]]]);
+ * _.flattenDeep([1, [2, 3, [4]]]);
* // => [1, 2, 3, 4];
*/
function flattenDeep(array) {
@@ -4475,15 +4513,15 @@
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
- * _.indexOf([1, 2, 3, 1, 2, 3], 2);
- * // => 1
+ * _.indexOf([1, 2, 1, 2], 2);
+ * // => 2
*
* // using `fromIndex`
- * _.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
- * // => 4
+ * _.indexOf([1, 2, 1, 2], 2, 2);
+ * // => 3
*
* // performing a binary search
- * _.indexOf([4, 4, 5, 5, 6, 6], 5, true);
+ * _.indexOf([1, 1, 2, 2], 2, true);
* // => 2
*/
function indexOf(array, value, fromIndex) {
@@ -4534,9 +4572,8 @@
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of shared values.
* @example
- *
- * _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]);
- * // => [1, 2]
+ * _.intersection([1, 2], [4, 2], [2, 1]);
+ * // => [2]
*/
function intersection() {
var args = [],
@@ -4612,15 +4649,15 @@
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
- * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
- * // => 4
+ * _.lastIndexOf([1, 2, 1, 2], 2);
+ * // => 3
*
* // using `fromIndex`
- * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
+ * _.lastIndexOf([1, 2, 1, 2], 2, 2);
* // => 1
*
* // performing a binary search
- * _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true);
+ * _.lastIndexOf([1, 1, 2, 2], 2, true);
* // => 3
*/
function lastIndexOf(array, value, fromIndex) {
@@ -4666,6 +4703,7 @@
* @example
*
* var array = [1, 2, 3, 1, 2, 3];
+ *
* _.pull(array, 2, 3);
* console.log(array);
* // => [1, 1]
@@ -4707,7 +4745,7 @@
* @example
*
* var array = [5, 10, 15, 20];
- * var evens = _.pullAt(array, [1, 3]);
+ * var evens = _.pullAt(array, 1, 3);
*
* console.log(array);
* // => [5, 15]
@@ -4748,7 +4786,9 @@
* @example
*
* 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);
* // => [1, 3]
@@ -4850,7 +4890,7 @@
* _.sortedIndex([30, 50], 40);
* // => 1
*
- * _.sortedIndex([4, 4, 5, 5, 6, 6], 5);
+ * _.sortedIndex([4, 4, 5, 5], 5);
* // => 2
*
* var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
@@ -4889,7 +4929,7 @@
* into `array`.
* @example
*
- * _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5);
+ * _.sortedLastIndex([4, 4, 5, 5], 5);
* // => 4
*/
function sortedLastIndex(array, value, iteratee, thisArg) {
@@ -4996,7 +5036,9 @@
* @returns {Array} Returns the slice of `array`.
* @example
*
- * _.takeRightWhile([1, 2, 3], function(n) { return n > 1; });
+ * _.takeRightWhile([1, 2, 3], function(n) {
+ * return n > 1;
+ * });
* // => [2, 3]
*
* var users = [
@@ -5053,7 +5095,9 @@
* @returns {Array} Returns the slice of `array`.
* @example
*
- * _.takeWhile([1, 2, 3], function(n) { return n < 3; });
+ * _.takeWhile([1, 2, 3], function(n) {
+ * return n < 3;
+ * });
* // => [1, 2]
*
* var users = [
@@ -5101,8 +5145,8 @@
* @returns {Array} Returns the new array of combined values.
* @example
*
- * _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]);
- * // => [1, 2, 3, 5, 4]
+ * _.union([1, 2], [4, 2], [2, 1]);
+ * // => [1, 2, 4]
*/
function union() {
return baseUniq(baseFlatten(arguments, false, true));
@@ -5151,7 +5195,9 @@
* // => [1, 2]
*
* // 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]
*
* // using the `_.property` callback shorthand
@@ -5163,8 +5209,7 @@
if (!length) {
return [];
}
- // Juggle arguments.
- if (typeof isSorted != 'boolean' && isSorted != null) {
+ if (isSorted != null && typeof isSorted != 'boolean') {
thisArg = iteratee;
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
isSorted = false;
@@ -5224,8 +5269,8 @@
* @returns {Array} Returns the new array of filtered values.
* @example
*
- * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
- * // => [2, 3, 4]
+ * _.without([1, 2, 1, 3], 1, 2);
+ * // => [3]
*/
function without(array) {
return baseDifference(array, baseSlice(arguments, 1));
@@ -5243,11 +5288,8 @@
* @returns {Array} Returns the new array of values.
* @example
*
- * _.xor([1, 2, 3], [5, 2, 1, 4]);
- * // => [3, 5, 4]
- *
- * _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
- * // => [1, 4, 5]
+ * _.xor([1, 2], [4, 2]);
+ * // => [1, 4]
*/
function xor() {
var index = -1,
@@ -5346,7 +5388,9 @@
*
* var youngest = _.chain(users)
* .sortBy('age')
- * .map(function(chr) { return chr.user + ' is ' + chr.age; })
+ * .map(function(chr) {
+ * return chr.user + ' is ' + chr.age;
+ * })
* .first()
* .value();
* // => 'pebbles is 1'
@@ -5373,7 +5417,9 @@
* @example
*
* _([1, 2, 3])
- * .tap(function(array) { array.pop(); })
+ * .tap(function(array) {
+ * array.pop();
+ * })
* .reverse()
* .value();
* // => [2, 1]
@@ -5397,7 +5443,9 @@
*
* _([1, 2, 3])
* .last()
- * .thru(function(value) { return [value]; })
+ * .thru(function(value) {
+ * return [value];
+ * })
* .value();
* // => [3]
*/
@@ -5490,7 +5538,7 @@
var result,
parent = this;
- while (parent instanceof LodashWrapper) {
+ while (parent instanceof baseLodash) {
var clone = wrapperClone(parent);
if (result) {
previous.__wrapped__ = clone;
@@ -5586,8 +5634,8 @@
* @returns {Array} Returns the new array of picked elements.
* @example
*
- * _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
- * // => ['a', 'c', 'e']
+ * _.at(['a', 'b', 'c'], [0, 2]);
+ * // => ['a', 'c']
*
* _.at(['fred', 'barney', 'pebbles'], 0, 2);
* // => ['fred', 'pebbles']
@@ -5600,57 +5648,6 @@
return baseAt(collection, baseFlatten(arguments, false, false, 1));
}
- /**
- * Checks if `value` is in `collection` using `SameValueZero` for equality
- * comparisons. If `fromIndex` is negative, it is used as the offset from
- * the end of `collection`.
- *
- * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
- * e.g. `===`, except that `NaN` matches `NaN`. See the
- * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
- * for more details.
- *
- * @static
- * @memberOf _
- * @alias contains, include
- * @category Collection
- * @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.
- * @returns {boolean} Returns `true` if a matching element is found, else `false`.
- * @example
- *
- * _.includes([1, 2, 3], 1);
- * // => true
- *
- * _.includes([1, 2, 3], 1, 2);
- * // => false
- *
- * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
- * // => true
- *
- * _.includes('pebbles', 'eb');
- * // => true
- */
- function includes(collection, target, fromIndex) {
- var length = collection ? collection.length : 0;
- if (!isLength(length)) {
- collection = values(collection);
- length = collection.length;
- }
- if (!length) {
- return false;
- }
- if (typeof fromIndex == 'number') {
- fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
- } else {
- fromIndex = 0;
- }
- return (typeof collection == 'string' || !isArray(collection) && isString(collection))
- ? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)
- : (getIndexOf(collection, target, fromIndex) > -1);
- }
-
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
@@ -5679,10 +5676,14 @@
* @returns {Object} Returns the composed aggregate object.
* @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 }
*
- * _.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 }
*
* _.countBy(['one', 'two', 'three'], 'length');
@@ -5775,8 +5776,10 @@
* @returns {Array} Returns the new filtered array.
* @example
*
- * var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; });
- * // => [2, 4]
+ * _.filter([4, 5, 6], function(n) {
+ * return n % 2 == 0;
+ * });
+ * // => [4, 6]
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': true },
@@ -5834,7 +5837,9 @@
* { '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'
*
* // using the `_.matches` callback shorthand
@@ -5872,7 +5877,9 @@
* @returns {*} Returns the matched element, else `undefined`.
* @example
*
- * _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; });
+ * _.findLast([1, 2, 3, 4], function(n) {
+ * return n % 2 == 1;
+ * });
* // => 3
*/
function findLast(collection, predicate, thisArg) {
@@ -5933,10 +5940,14 @@
* @returns {Array|Object|string} Returns `collection`.
* @example
*
- * _([1, 2, 3]).forEach(function(n) { console.log(n); }).value();
+ * _([1, 2]).forEach(function(n) {
+ * console.log(n);
+ * }).value();
* // => logs each value from left to right and returns the array
*
- * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });
+ * _.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)
*/
function forEach(collection, iteratee, thisArg) {
@@ -5959,7 +5970,9 @@
* @returns {Array|Object|string} Returns `collection`.
* @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
*/
function forEachRight(collection, iteratee, thisArg) {
@@ -5996,10 +6009,14 @@
* @returns {Object} Returns the composed aggregate object.
* @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] }
*
- * _.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] }
*
* // using the `_.property` callback shorthand
@@ -6014,6 +6031,57 @@
}
});
+ /**
+ * Checks if `value` is in `collection` using `SameValueZero` for equality
+ * comparisons. If `fromIndex` is negative, it is used as the offset from
+ * the end of `collection`.
+ *
+ * **Note:** `SameValueZero` comparisons are like strict equality comparisons,
+ * e.g. `===`, except that `NaN` matches `NaN`. See the
+ * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
+ * for more details.
+ *
+ * @static
+ * @memberOf _
+ * @alias contains, include
+ * @category Collection
+ * @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.
+ * @returns {boolean} Returns `true` if a matching element is found, else `false`.
+ * @example
+ *
+ * _.includes([1, 2, 3], 1);
+ * // => true
+ *
+ * _.includes([1, 2, 3], 1, 2);
+ * // => false
+ *
+ * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
+ * // => true
+ *
+ * _.includes('pebbles', 'eb');
+ * // => true
+ */
+ function includes(collection, target, fromIndex) {
+ var length = collection ? collection.length : 0;
+ if (!isLength(length)) {
+ collection = values(collection);
+ length = collection.length;
+ }
+ if (!length) {
+ return false;
+ }
+ if (typeof fromIndex == 'number') {
+ fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
+ } else {
+ fromIndex = 0;
+ }
+ return (typeof collection == 'string' || !isArray(collection) && isString(collection))
+ ? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)
+ : (getIndexOf(collection, target, fromIndex) > -1);
+ }
+
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through `iteratee`. The corresponding value
@@ -6050,10 +6118,14 @@
* _.indexBy(keyData, 'dir');
* // => { '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 } }
*
- * _.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 } }
*/
var indexBy = createAggregator(function(result, value, key) {
@@ -6123,11 +6195,15 @@
* @returns {Array} Returns the new mapped array.
* @example
*
- * _.map([1, 2, 3], function(n) { return n * 3; });
- * // => [3, 6, 9]
+ * function timesThree(n) {
+ * return n * 3;
+ * }
*
- * _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; });
- * // => [3, 6, 9] (iteration order is not guaranteed)
+ * _.map([1, 2], timesThree);
+ * // => [3, 6]
+ *
+ * _.map({ 'a': 1, 'b': 2 }, timesThree);
+ * // => [3, 6] (iteration order is not guaranteed)
*
* var users = [
* { 'user': 'barney' },
@@ -6182,7 +6258,9 @@
* { 'user': 'fred', 'age': 40 }
* ];
*
- * _.max(users, function(chr) { return chr.age; });
+ * _.max(users, function(chr) {
+ * return chr.age;
+ * });
* // => { 'user': 'fred', 'age': 40 };
*
* // using the `_.property` callback shorthand
@@ -6229,7 +6307,9 @@
* { 'user': 'fred', 'age': 40 }
* ];
*
- * _.min(users, function(chr) { return chr.age; });
+ * _.min(users, function(chr) {
+ * return chr.age;
+ * });
* // => { 'user': 'barney', 'age': 36 };
*
* // using the `_.property` callback shorthand
@@ -6265,10 +6345,14 @@
* @returns {Array} Returns the array of grouped elements.
* @example
*
- * _.partition([1, 2, 3], function(n) { return n % 2; });
+ * _.partition([1, 2, 3], function(n) {
+ * return n % 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) {
+ * return this.floor(n) % 2;
+ * }, Math);
* // => [[1, 3], [2]]
*
* var users = [
@@ -6277,7 +6361,9 @@
* { 'user': 'pebbles', 'age': 1, 'active': false }
* ];
*
- * var mapper = function(array) { return _.pluck(array, 'user'); };
+ * var mapper = function(array) {
+ * return _.pluck(array, 'user');
+ * };
*
* // using the `_.matches` callback shorthand
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
@@ -6347,14 +6433,16 @@
* @returns {*} Returns the accumulated value.
* @example
*
- * var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; });
- * // => 6
+ * _.reduce([1, 2], function(sum, n) {
+ * 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;
* 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) {
var func = isArray(collection) ? arrayReduce : baseReduce;
@@ -6377,7 +6465,10 @@
* @example
*
* 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]
*/
function reduceRight(collection, iteratee, accumulator, thisArg) {
@@ -6410,7 +6501,9 @@
* @returns {Array} Returns the new filtered array.
* @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]
*
* var users = [
@@ -6510,12 +6603,12 @@
* @returns {number} Returns the size of `collection`.
* @example
*
- * _.size([1, 2]);
- * // => 2
- *
- * _.size({ 'one': 1, 'two': 2, 'three': 3 });
+ * _.size([1, 2, 3]);
* // => 3
*
+ * _.size({ 'a': 1, 'b': 2 });
+ * // => 2
+ *
* _.size('pebbles');
* // => 7
*/
@@ -6610,10 +6703,14 @@
* @returns {Array} Returns the new sorted array.
* @example
*
- * _.sortBy([1, 2, 3], function(n) { return Math.sin(n); });
+ * _.sortBy([1, 2, 3], function(n) {
+ * return Math.sin(n);
+ * });
* // => [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]
*
* var users = [
@@ -6730,7 +6827,9 @@
* @category Date
* @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
*/
var now = nativeNow || function() {
@@ -6906,7 +7005,9 @@
*
* var view = {
* 'label': 'docs',
- * 'onClick': function() { console.log('clicked ' + this.label); }
+ * 'onClick': function() {
+ * console.log('clicked ' + this.label);
+ * }
* };
*
* _.bindAll(view);
@@ -7259,7 +7360,9 @@
* @returns {number} Returns the timer id.
* @example
*
- * _.defer(function(text) { console.log(text); }, 'deferred');
+ * _.defer(function(text) {
+ * console.log(text);
+ * }, 'deferred');
* // logs 'deferred' after one or more milliseconds
*/
function defer(func) {
@@ -7279,7 +7382,9 @@
* @returns {number} Returns the timer id.
* @example
*
- * _.delay(function(text) { console.log(text); }, 1000, 'later');
+ * _.delay(function(text) {
+ * console.log(text);
+ * }, 1000, 'later');
* // => logs 'later' after one second
*/
function delay(func, wait) {
@@ -7317,7 +7422,7 @@
if (!length) {
return function() { return arguments[0]; };
}
- if (!arrayEvery(funcs, isFunction)) {
+ if (!arrayEvery(funcs, baseIsFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function() {
@@ -7362,7 +7467,7 @@
if (fromIndex < 0) {
return function() { return arguments[0]; };
}
- if (!arrayEvery(funcs, isFunction)) {
+ if (!arrayEvery(funcs, baseIsFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function() {
@@ -7597,7 +7702,9 @@
* // => ['a', 'b', 'c']
*
* 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]
*/
function rearg(func) {
@@ -7676,8 +7783,9 @@
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
*
* // 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', throttled);
+ * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
+ * 'trailing': false
+ * }));
*
* // cancel a trailing throttled call
* jQuery(window).on('popstate', throttled.cancel);
@@ -7767,22 +7875,26 @@
* // => false
*
* // using a customizer callback
- * var body = _.clone(document.body, function(value) {
- * return _.isElement(value) ? value.cloneNode(false) : undefined;
+ * var el = _.clone(document.body, function(value) {
+ * if (_.isElement(value)) {
+ * return value.cloneNode(false);
+ * }
* });
*
- * body === document.body
+ * el === document.body
* // => false
- * body.nodeName
+ * el.nodeName
* // => BODY
- * body.childNodes.length;
+ * el.childNodes.length;
* // => 0
*/
function clone(value, isDeep, customizer, thisArg) {
- // Juggle arguments.
- if (typeof isDeep != 'boolean' && isDeep != null) {
+ if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
+ isDeep = false;
+ }
+ else if (typeof isDeep == 'function') {
thisArg = customizer;
- customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep;
+ customizer = isDeep;
isDeep = false;
}
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
@@ -7822,14 +7934,16 @@
*
* // using a customizer callback
* var el = _.cloneDeep(document.body, function(value) {
- * return _.isElement(value) ? value.cloneNode(true) : undefined;
+ * if (_.isElement(value)) {
+ * return value.cloneNode(true);
+ * }
* });
*
- * body === document.body
+ * el === document.body
* // => false
- * body.nodeName
+ * el.nodeName
* // => BODY
- * body.childNodes.length;
+ * el.childNodes.length;
* // => 20
*/
function cloneDeep(value, customizer, thisArg) {
@@ -7847,7 +7961,7 @@
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
- * (function() { return _.isArguments(arguments); })();
+ * _.isArguments(function() { return arguments; }());
* // => true
*
* _.isArguments([1, 2, 3]);
@@ -7871,7 +7985,7 @@
* _.isArray([1, 2, 3]);
* // => true
*
- * (function() { return _.isArray(arguments); })();
+ * _.isArray(function() { return arguments; }());
* // => false
*/
var isArray = nativeIsArray || function(value) {
@@ -8021,7 +8135,9 @@
* var other = ['hi', 'goodbye'];
*
* _.isEqual(array, other, function(value, other) {
- * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
+ * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
+ * return true;
+ * }
* });
* // => true
*/
@@ -8104,20 +8220,12 @@
* _.isFunction(/abc/);
* // => false
*/
- function isFunction(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;
- }
- // Fallback for environments that return incorrect `typeof` operator results.
- if (isFunction(/x/) || (Uint8Array && !isFunction(Uint8Array))) {
- isFunction = function(value) {
- // The use of `Object#toString` avoids issues with the `typeof` operator
- // in older versions of Chrome and Safari which return 'function' for regexes
- // and Safari 8 equivalents which return 'object' for typed array constructors.
- return objToString.call(value) == funcTag;
- };
- }
+ var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
+ // The use of `Object#toString` avoids issues with the `typeof` operator
+ // in older versions of Chrome and Safari which return 'function' for regexes
+ // and Safari 8 equivalents which return 'object' for typed array constructors.
+ return objToString.call(value) == funcTag;
+ };
/**
* Checks if `value` is the language type of `Object`.
@@ -8446,7 +8554,9 @@
* @returns {Array} Returns the converted array.
* @example
*
- * (function() { return _.toArray(arguments).slice(1); })(1, 2, 3);
+ * (function() {
+ * return _.toArray(arguments).slice(1);
+ * }(1, 2, 3));
* // => [2, 3]
*/
function toArray(value) {
@@ -8543,7 +8653,9 @@
* Shape.call(this);
* }
*
- * Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle });
+ * Circle.prototype = _.create(Shape.prototype, {
+ * 'constructor': Circle
+ * });
*
* var circle = new Circle;
* circle instanceof Circle;
@@ -8616,7 +8728,9 @@
* 'pebbles': { 'age': 1, 'active': true }
* };
*
- * _.findKey(users, function(chr) { return chr.age < 40; });
+ * _.findKey(users, function(chr) {
+ * return chr.age < 40;
+ * });
* // => 'barney' (iteration order is not guaranteed)
*
* // using the `_.matches` callback shorthand
@@ -8667,7 +8781,9 @@
* 'pebbles': { 'age': 1, 'active': true }
* };
*
- * _.findLastKey(users, function(chr) { return chr.age < 40; });
+ * _.findLastKey(users, function(chr) {
+ * return chr.age < 40;
+ * });
* // => returns `pebbles` assuming `_.findKey` returns `barney`
*
* // using the `_.matches` callback shorthand
@@ -8766,10 +8882,17 @@
* @returns {Object} Returns `object`.
* @example
*
- * _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
+ * function Foo() {
+ * this.a = 1;
+ * this.b = 2;
+ * }
+ *
+ * Foo.prototype.c = 3;
+ *
+ * _.forOwn(new Foo, function(value, key) {
* console.log(key);
* });
- * // => logs '0', '1', and 'length' (iteration order is not guaranteed)
+ * // => logs 'a' and 'b' (iteration order is not guaranteed)
*/
function forOwn(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
@@ -8791,10 +8914,17 @@
* @returns {Object} Returns `object`.
* @example
*
- * _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
+ * function Foo() {
+ * this.a = 1;
+ * this.b = 2;
+ * }
+ *
+ * Foo.prototype.c = 3;
+ *
+ * _.forOwnRight(new Foo, function(value, key) {
* console.log(key);
* });
- * // => logs 'length', '1', and '0' assuming `_.forOwn` logs '0', '1', and 'length'
+ * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
*/
function forOwnRight(object, iteratee, thisArg) {
iteratee = bindCallback(iteratee, thisArg, 3);
@@ -8814,7 +8944,7 @@
* @example
*
* _.functions(_);
- * // => ['all', 'any', 'bind', ...]
+ * // => ['after', 'ary', 'assign', ...]
*/
function functions(object) {
return baseFunctions(object, keysIn(object));
@@ -8832,7 +8962,9 @@
* @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
* @example
*
- * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
+ * var object = { 'a': 1, 'b': 2, 'c': 3 };
+ *
+ * _.has(object, 'b');
* // => true
*/
function has(object, key) {
@@ -8853,16 +8985,14 @@
* @returns {Object} Returns the new inverted object.
* @example
*
- * _.invert({ 'first': 'fred', 'second': 'barney' });
- * // => { 'fred': 'first', 'barney': 'second' }
+ * var object = { 'a': 1, 'b': 2, 'c': 1 };
*
- * // without `multiValue`
- * _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' });
- * // => { 'fred': 'third', 'barney': 'second' }
+ * _.invert(object);
+ * // => { '1': 'c', '2': 'b' }
*
* // with `multiValue`
- * _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }, true);
- * // => { 'fred': ['first', 'third'], 'barney': ['second'] }
+ * _.invert(object, true);
+ * // => { '1': ['a', 'c'], '2': ['b'] }
*/
function invert(object, multiValue, guard) {
if (guard && isIterateeCall(object, multiValue, guard)) {
@@ -9008,8 +9138,10 @@
* @returns {Object} Returns the new mapped object.
* @example
*
- * _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(n) { return n * 3; });
- * // => { 'a': 3, 'b': 6, 'c': 9 }
+ * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
+ * return n * 3;
+ * });
+ * // => { 'a': 3, 'b': 6 }
*
* var users = {
* 'fred': { 'user': 'fred', 'age': 40 },
@@ -9072,7 +9204,9 @@
* };
*
* _.merge(object, other, function(a, b) {
- * return _.isArray(a) ? a.concat(b) : undefined;
+ * if (_.isArray(a)) {
+ * return a.concat(b);
+ * }
* });
* // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
*/
@@ -9238,18 +9372,16 @@
* @returns {*} Returns the accumulated value.
* @example
*
- * var squares = _.transform([1, 2, 3, 4, 5, 6], function(result, n) {
- * n *= n;
- * if (n % 2) {
- * return result.push(n) < 3;
- * }
+ * _.transform([2, 3, 4], function(result, n) {
+ * result.push(n *= n);
+ * return n % 2 == 0;
* });
- * // => [1, 9, 25]
+ * // => [4, 9]
*
- * var mapped = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) {
+ * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
* result[key] = n * 3;
* });
- * // => { 'a': 3, 'b': 6, 'c': 9 }
+ * // => { 'a': 3, 'b': 6 }
*/
function transform(object, iteratee, accumulator, thisArg) {
var isArr = isArray(object) || isTypedArray(object);
@@ -9331,6 +9463,48 @@
/*------------------------------------------------------------------------*/
+ /**
+ * Checks if `n` is between `start` and up to but not including, `end`. If
+ * `end` is not specified it defaults to `start` with `start` becoming `0`.
+ *
+ * @static
+ * @memberOf _
+ * @category Number
+ * @param {number} n The number to check.
+ * @param {number} [start=0] The start of the range.
+ * @param {number} end The end of the range.
+ * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
+ * @example
+ *
+ * _.inRange(3, 2, 4);
+ * // => true
+ *
+ * _.inRange(4, 8);
+ * // => true
+ *
+ * _.inRange(4, 2);
+ * // => false
+ *
+ * _.inRange(2, 2);
+ * // => false
+ *
+ * _.inRange(1.2, 2);
+ * // => true
+ *
+ * _.inRange(5.2, 4);
+ * // => false
+ */
+ function inRange(value, start, end) {
+ start = +start || 0;
+ if (typeof end === 'undefined') {
+ end = start;
+ start = 0;
+ } else {
+ end = +end || 0;
+ }
+ return value >= start && value < end;
+ }
+
/**
* Produces a random number between `min` and `max` (inclusive). If only one
* argument is provided a number between `0` and the given number is returned.
@@ -9550,7 +9724,7 @@
}
/**
- * Converts `string` to kebab case (a.k.a. spinal case).
+ * Converts `string` to kebab case.
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for
* more details.
*
@@ -10149,13 +10323,21 @@
* _.trunc('hi-diddly-ho there, neighborino', 24);
* // => 'hi-diddly-ho there, n...'
*
- * _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' });
+ * _.trunc('hi-diddly-ho there, neighborino', {
+ * 'length': 24,
+ * 'separator': ' '
+ * });
* // => 'hi-diddly-ho there,...'
*
- * _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ });
+ * _.trunc('hi-diddly-ho there, neighborino', {
+ * 'length': 24,
+ * 'separator': /,? +/
+ * });
* //=> 'hi-diddly-ho there...'
*
- * _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' });
+ * _.trunc('hi-diddly-ho there, neighborino', {
+ * 'omission': ' [...]'
+ * });
* // => 'hi-diddly-ho there, neig [...]'
*/
function trunc(string, options, guard) {
@@ -10283,9 +10465,16 @@
* elements = [];
* }
*/
- function attempt(func) {
+ function attempt() {
+ var length = arguments.length,
+ func = arguments[0];
+
try {
- return func.apply(undefined, baseSlice(arguments, 1));
+ var args = Array(length ? length - 1 : 0);
+ while (--length > 0) {
+ args[length - 1] = arguments[length];
+ }
+ return func.apply(undefined, args);
} catch(e) {
return isError(e) ? e : new Error(e);
}
@@ -10320,7 +10509,9 @@
* return callback(func, thisArg);
* }
* return function(object) {
- * return match[2] == 'gt' ? object[match[1]] > match[3] : object[match[1]] < match[3];
+ * return match[2] == 'gt'
+ * ? object[match[1]] > match[3]
+ * : object[match[1]] < match[3];
* };
* });
*
@@ -10348,6 +10539,7 @@
*
* var object = { 'user': 'fred' };
* var getter = _.constant(object);
+ *
* getter() === object;
* // => true
*/
@@ -10368,6 +10560,7 @@
* @example
*
* var object = { 'user': 'fred' };
+ *
* _.identity(object) === object;
* // => true
*/
@@ -10538,7 +10731,8 @@
}
/**
- * A no-operation function.
+ * A no-operation function which returns `undefined` regardless of the
+ * arguments it receives.
*
* @static
* @memberOf _
@@ -10546,6 +10740,7 @@
* @example
*
* var object = { 'user': 'fred' };
+ *
* _.noop(object) === undefined;
* // => true
*/
@@ -10591,11 +10786,11 @@
* @returns {Function} Returns the new function.
* @example
*
- * var object = { 'user': 'fred', 'age': 40, 'active': true };
- * _.map(['active', 'user'], _.propertyOf(object));
- * // => [true, 'fred']
- *
* var object = { 'a': 3, 'b': 1, 'c': 2 };
+ *
+ * _.map(['a', 'c'], _.propertyOf(object));
+ * // => [3, 2]
+ *
* _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
* // => ['b', 'c', 'a']
*/
@@ -10607,8 +10802,9 @@
/**
* Creates an array of numbers (positive and/or negative) progressing from
- * `start` up to, but not including, `end`. If `start` is less than `end` a
- * zero-length range is created unless a negative `step` is specified.
+ * `start` up to, but not including, `end`. If `end` is not specified it
+ * defaults to `start` with `start` becoming `0`. If `start` is less than
+ * `end` a zero-length range is created unless a negative `step` is specified.
*
* @static
* @memberOf _
@@ -10680,10 +10876,14 @@
* var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
* // => [3, 6, 4]
*
- * _.times(3, function(n) { mage.castSpell(n); });
+ * _.times(3, function(n) {
+ * mage.castSpell(n);
+ * });
* // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2` respectively
*
- * _.times(3, function(n) { this.cast(n); }, mage);
+ * _.times(3, function(n) {
+ * this.cast(n);
+ * }, mage);
* // => also invokes `mage.castSpell(n)` three times
*/
function times(n, iteratee, thisArg) {
@@ -10731,11 +10931,13 @@
/*------------------------------------------------------------------------*/
- // Ensure `new LodashWrapper` is an instance of `lodash`.
- LodashWrapper.prototype = baseCreate(lodash.prototype);
+ // Ensure wrappers are instances of `baseLodash`.
+ lodash.prototype = baseLodash.prototype;
- // Ensure `new LazyWraper` is an instance of `LodashWrapper`
- LazyWrapper.prototype = baseCreate(LodashWrapper.prototype);
+ LodashWrapper.prototype = baseCreate(baseLodash.prototype);
+ LodashWrapper.prototype.constructor = LodashWrapper;
+
+ LazyWrapper.prototype = baseCreate(baseLodash.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
// Add functions to the `Map` cache.
@@ -10893,6 +11095,7 @@
lodash.identity = identity;
lodash.includes = includes;
lodash.indexOf = indexOf;
+ lodash.inRange = inRange;
lodash.isArguments = isArguments;
lodash.isArray = isArray;
lodash.isBoolean = isBoolean;
@@ -11164,7 +11367,7 @@
LazyWrapper.prototype.reverse = lazyReverse;
LazyWrapper.prototype.value = lazyValue;
- // Add chaining functions to the lodash wrapper.
+ // Add chaining functions to the `lodash` wrapper.
lodash.prototype.chain = wrapperChain;
lodash.prototype.commit = wrapperCommit;
lodash.prototype.plant = wrapperPlant;
@@ -11172,7 +11375,7 @@
lodash.prototype.toString = wrapperToString;
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
- // Add function aliases to the lodash wrapper.
+ // Add function aliases to the `lodash` wrapper.
lodash.prototype.collect = lodash.prototype.map;
lodash.prototype.head = lodash.prototype.first;
lodash.prototype.select = lodash.prototype.filter;
diff --git a/internal/LazyWrapper.js b/internal/LazyWrapper.js
index b0374b4bb..4c3709734 100644
--- a/internal/LazyWrapper.js
+++ b/internal/LazyWrapper.js
@@ -1,3 +1,6 @@
+var baseCreate = require('./baseCreate'),
+ baseLodash = require('./baseLodash');
+
/** Used as references for `-Infinity` and `Infinity`. */
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
@@ -18,4 +21,7 @@ function LazyWrapper(value) {
this.__views__ = null;
}
+LazyWrapper.prototype = baseCreate(baseLodash.prototype);
+LazyWrapper.prototype.constructor = LazyWrapper;
+
module.exports = LazyWrapper;
diff --git a/internal/LodashWrapper.js b/internal/LodashWrapper.js
index faedb1aea..ab06bc761 100644
--- a/internal/LodashWrapper.js
+++ b/internal/LodashWrapper.js
@@ -1,3 +1,6 @@
+var baseCreate = require('./baseCreate'),
+ baseLodash = require('./baseLodash');
+
/**
* The base constructor for creating `lodash` wrapper objects.
*
@@ -12,4 +15,7 @@ function LodashWrapper(value, chainAll, actions) {
this.__chain__ = !!chainAll;
}
+LodashWrapper.prototype = baseCreate(baseLodash.prototype);
+LodashWrapper.prototype.constructor = LodashWrapper;
+
module.exports = LodashWrapper;
diff --git a/internal/baseIsFunction.js b/internal/baseIsFunction.js
new file mode 100644
index 000000000..cd92db30f
--- /dev/null
+++ b/internal/baseIsFunction.js
@@ -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;
+}
+
+module.exports = baseIsFunction;
diff --git a/internal/baseLodash.js b/internal/baseLodash.js
new file mode 100644
index 000000000..15b79d3f7
--- /dev/null
+++ b/internal/baseLodash.js
@@ -0,0 +1,10 @@
+/**
+ * The function whose prototype all chaining wrappers inherit from.
+ *
+ * @private
+ */
+function baseLodash() {
+ // No operation performed.
+}
+
+module.exports = baseLodash;
diff --git a/internal/baseMerge.js b/internal/baseMerge.js
index ddd36bf14..22f19b70a 100644
--- a/internal/baseMerge.js
+++ b/internal/baseMerge.js
@@ -3,6 +3,7 @@ var arrayEach = require('./arrayEach'),
baseMergeDeep = require('./baseMergeDeep'),
isArray = require('../lang/isArray'),
isLength = require('./isLength'),
+ isObject = require('../lang/isObject'),
isObjectLike = require('./isObjectLike'),
isTypedArray = require('../lang/isTypedArray');
@@ -19,8 +20,10 @@ var arrayEach = require('./arrayEach'),
* @returns {Object} Returns the destination object.
*/
function baseMerge(object, source, customizer, stackA, stackB) {
+ if (!isObject(object)) {
+ return object;
+ }
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
-
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
if (isObjectLike(srcValue)) {
stackA || (stackA = []);
diff --git a/internal/isIterateeCall.js b/internal/isIterateeCall.js
index 53d327e58..d8244bb85 100644
--- a/internal/isIterateeCall.js
+++ b/internal/isIterateeCall.js
@@ -22,7 +22,8 @@ function isIterateeCall(value, index, object) {
} else {
prereq = type == 'string' && index in object;
}
- return prereq && object[index] === value;
+ var other = object[index];
+ return prereq && (value === value ? value === other : other !== other);
}
module.exports = isIterateeCall;
diff --git a/lang/clone.js b/lang/clone.js
index 12f639c9f..eca0a2f14 100644
--- a/lang/clone.js
+++ b/lang/clone.js
@@ -40,22 +40,26 @@ var baseClone = require('../internal/baseClone'),
* // => false
*
* // using a customizer callback
- * var body = _.clone(document.body, function(value) {
- * return _.isElement(value) ? value.cloneNode(false) : undefined;
+ * var el = _.clone(document.body, function(value) {
+ * if (_.isElement(value)) {
+ * return value.cloneNode(false);
+ * }
* });
*
- * body === document.body
+ * el === document.body
* // => false
- * body.nodeName
+ * el.nodeName
* // => BODY
- * body.childNodes.length;
+ * el.childNodes.length;
* // => 0
*/
function clone(value, isDeep, customizer, thisArg) {
- // Juggle arguments.
- if (typeof isDeep != 'boolean' && isDeep != null) {
+ if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
+ isDeep = false;
+ }
+ else if (typeof isDeep == 'function') {
thisArg = customizer;
- customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep;
+ customizer = isDeep;
isDeep = false;
}
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
diff --git a/lang/cloneDeep.js b/lang/cloneDeep.js
index 87181aa61..b6e3c44ad 100644
--- a/lang/cloneDeep.js
+++ b/lang/cloneDeep.js
@@ -34,14 +34,16 @@ var baseClone = require('../internal/baseClone'),
*
* // using a customizer callback
* var el = _.cloneDeep(document.body, function(value) {
- * return _.isElement(value) ? value.cloneNode(true) : undefined;
+ * if (_.isElement(value)) {
+ * return value.cloneNode(true);
+ * }
* });
*
- * body === document.body
+ * el === document.body
* // => false
- * body.nodeName
+ * el.nodeName
* // => BODY
- * body.childNodes.length;
+ * el.childNodes.length;
* // => 20
*/
function cloneDeep(value, customizer, thisArg) {
diff --git a/lang/isArguments.js b/lang/isArguments.js
index 7cd66b068..653c91819 100644
--- a/lang/isArguments.js
+++ b/lang/isArguments.js
@@ -24,7 +24,7 @@ var objToString = objectProto.toString;
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
- * (function() { return _.isArguments(arguments); })();
+ * _.isArguments(function() { return arguments; }());
* // => true
*
* _.isArguments([1, 2, 3]);
diff --git a/lang/isArray.js b/lang/isArray.js
index 947acac44..e67daa713 100644
--- a/lang/isArray.js
+++ b/lang/isArray.js
@@ -31,7 +31,7 @@ var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray;
* _.isArray([1, 2, 3]);
* // => true
*
- * (function() { return _.isArray(arguments); })();
+ * _.isArray(function() { return arguments; }());
* // => false
*/
var isArray = nativeIsArray || function(value) {
diff --git a/lang/isEqual.js b/lang/isEqual.js
index b8c0f3c7e..3be9b0b68 100644
--- a/lang/isEqual.js
+++ b/lang/isEqual.js
@@ -39,7 +39,9 @@ var baseIsEqual = require('../internal/baseIsEqual'),
* var other = ['hi', 'goodbye'];
*
* _.isEqual(array, other, function(value, other) {
- * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
+ * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
+ * return true;
+ * }
* });
* // => true
*/
diff --git a/lang/isFunction.js b/lang/isFunction.js
index 176e95dc2..7a4190a08 100644
--- a/lang/isFunction.js
+++ b/lang/isFunction.js
@@ -1,4 +1,5 @@
-var isNative = require('./isNative');
+var baseIsFunction = require('../internal/baseIsFunction'),
+ isNative = require('./isNative');
/** `Object#toString` result references. */
var funcTag = '[object Function]';
@@ -32,19 +33,11 @@ var Uint8Array = isNative(Uint8Array = global.Uint8Array) && Uint8Array;
* _.isFunction(/abc/);
* // => false
*/
-function isFunction(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;
-}
-// Fallback for environments that return incorrect `typeof` operator results.
-if (isFunction(/x/) || (Uint8Array && !isFunction(Uint8Array))) {
- isFunction = function(value) {
- // The use of `Object#toString` avoids issues with the `typeof` operator
- // in older versions of Chrome and Safari which return 'function' for regexes
- // and Safari 8 equivalents which return 'object' for typed array constructors.
- return objToString.call(value) == funcTag;
- };
-}
+var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
+ // The use of `Object#toString` avoids issues with the `typeof` operator
+ // in older versions of Chrome and Safari which return 'function' for regexes
+ // and Safari 8 equivalents which return 'object' for typed array constructors.
+ return objToString.call(value) == funcTag;
+};
module.exports = isFunction;
diff --git a/lang/toArray.js b/lang/toArray.js
index b906bd8f0..271833c61 100644
--- a/lang/toArray.js
+++ b/lang/toArray.js
@@ -12,7 +12,9 @@ var arrayCopy = require('../internal/arrayCopy'),
* @returns {Array} Returns the converted array.
* @example
*
- * (function() { return _.toArray(arguments).slice(1); })(1, 2, 3);
+ * (function() {
+ * return _.toArray(arguments).slice(1);
+ * }(1, 2, 3));
* // => [2, 3]
*/
function toArray(value) {
diff --git a/number.js b/number.js
index eb46420d1..afab9d995 100644
--- a/number.js
+++ b/number.js
@@ -1,3 +1,4 @@
module.exports = {
+ 'inRange': require('./number/inRange'),
'random': require('./number/random')
};
diff --git a/number/inRange.js b/number/inRange.js
new file mode 100644
index 000000000..52f348e3d
--- /dev/null
+++ b/number/inRange.js
@@ -0,0 +1,43 @@
+/**
+ * Checks if `n` is between `start` and up to but not including, `end`. If
+ * `end` is not specified it defaults to `start` with `start` becoming `0`.
+ *
+ * @static
+ * @memberOf _
+ * @category Number
+ * @param {number} n The number to check.
+ * @param {number} [start=0] The start of the range.
+ * @param {number} end The end of the range.
+ * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
+ * @example
+ *
+ * _.inRange(3, 2, 4);
+ * // => true
+ *
+ * _.inRange(4, 8);
+ * // => true
+ *
+ * _.inRange(4, 2);
+ * // => false
+ *
+ * _.inRange(2, 2);
+ * // => false
+ *
+ * _.inRange(1.2, 2);
+ * // => true
+ *
+ * _.inRange(5.2, 4);
+ * // => false
+ */
+function inRange(value, start, end) {
+ start = +start || 0;
+ if (typeof end === 'undefined') {
+ end = start;
+ start = 0;
+ } else {
+ end = +end || 0;
+ }
+ return value >= start && value < end;
+}
+
+module.exports = inRange;
diff --git a/object/create.js b/object/create.js
index 9e3243de7..afb4df7c9 100644
--- a/object/create.js
+++ b/object/create.js
@@ -26,7 +26,9 @@ var baseCopy = require('../internal/baseCopy'),
* Shape.call(this);
* }
*
- * Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle });
+ * Circle.prototype = _.create(Shape.prototype, {
+ * 'constructor': Circle
+ * });
*
* var circle = new Circle;
* circle instanceof Circle;
diff --git a/object/findKey.js b/object/findKey.js
index 4aea35a7a..6ef567ed5 100644
--- a/object/findKey.js
+++ b/object/findKey.js
@@ -33,7 +33,9 @@ var baseCallback = require('../internal/baseCallback'),
* 'pebbles': { 'age': 1, 'active': true }
* };
*
- * _.findKey(users, function(chr) { return chr.age < 40; });
+ * _.findKey(users, function(chr) {
+ * return chr.age < 40;
+ * });
* // => 'barney' (iteration order is not guaranteed)
*
* // using the `_.matches` callback shorthand
diff --git a/object/findLastKey.js b/object/findLastKey.js
index 37063afd5..e867fc505 100644
--- a/object/findLastKey.js
+++ b/object/findLastKey.js
@@ -33,7 +33,9 @@ var baseCallback = require('../internal/baseCallback'),
* 'pebbles': { 'age': 1, 'active': true }
* };
*
- * _.findLastKey(users, function(chr) { return chr.age < 40; });
+ * _.findLastKey(users, function(chr) {
+ * return chr.age < 40;
+ * });
* // => returns `pebbles` assuming `_.findKey` returns `barney`
*
* // using the `_.matches` callback shorthand
diff --git a/object/forOwn.js b/object/forOwn.js
index b98faa66d..a4dcf026e 100644
--- a/object/forOwn.js
+++ b/object/forOwn.js
@@ -16,10 +16,17 @@ var baseForOwn = require('../internal/baseForOwn'),
* @returns {Object} Returns `object`.
* @example
*
- * _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
+ * function Foo() {
+ * this.a = 1;
+ * this.b = 2;
+ * }
+ *
+ * Foo.prototype.c = 3;
+ *
+ * _.forOwn(new Foo, function(value, key) {
* console.log(key);
* });
- * // => logs '0', '1', and 'length' (iteration order is not guaranteed)
+ * // => logs 'a' and 'b' (iteration order is not guaranteed)
*/
function forOwn(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
diff --git a/object/forOwnRight.js b/object/forOwnRight.js
index 069083b7c..d48f88e48 100644
--- a/object/forOwnRight.js
+++ b/object/forOwnRight.js
@@ -15,10 +15,17 @@ var baseForRight = require('../internal/baseForRight'),
* @returns {Object} Returns `object`.
* @example
*
- * _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
+ * function Foo() {
+ * this.a = 1;
+ * this.b = 2;
+ * }
+ *
+ * Foo.prototype.c = 3;
+ *
+ * _.forOwnRight(new Foo, function(value, key) {
* console.log(key);
* });
- * // => logs 'length', '1', and '0' assuming `_.forOwn` logs '0', '1', and 'length'
+ * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
*/
function forOwnRight(object, iteratee, thisArg) {
iteratee = bindCallback(iteratee, thisArg, 3);
diff --git a/object/functions.js b/object/functions.js
index c2d89f1a2..10799becd 100644
--- a/object/functions.js
+++ b/object/functions.js
@@ -14,7 +14,7 @@ var baseFunctions = require('../internal/baseFunctions'),
* @example
*
* _.functions(_);
- * // => ['all', 'any', 'bind', ...]
+ * // => ['after', 'ary', 'assign', ...]
*/
function functions(object) {
return baseFunctions(object, keysIn(object));
diff --git a/object/has.js b/object/has.js
index 08cdb5d66..50eaa7ef3 100644
--- a/object/has.js
+++ b/object/has.js
@@ -16,7 +16,9 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
* @example
*
- * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
+ * var object = { 'a': 1, 'b': 2, 'c': 3 };
+ *
+ * _.has(object, 'b');
* // => true
*/
function has(object, key) {
diff --git a/object/invert.js b/object/invert.js
index 6100ca304..de02c08e8 100644
--- a/object/invert.js
+++ b/object/invert.js
@@ -21,16 +21,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* @returns {Object} Returns the new inverted object.
* @example
*
- * _.invert({ 'first': 'fred', 'second': 'barney' });
- * // => { 'fred': 'first', 'barney': 'second' }
+ * var object = { 'a': 1, 'b': 2, 'c': 1 };
*
- * // without `multiValue`
- * _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' });
- * // => { 'fred': 'third', 'barney': 'second' }
+ * _.invert(object);
+ * // => { '1': 'c', '2': 'b' }
*
* // with `multiValue`
- * _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }, true);
- * // => { 'fred': ['first', 'third'], 'barney': ['second'] }
+ * _.invert(object, true);
+ * // => { '1': ['a', 'c'], '2': ['b'] }
*/
function invert(object, multiValue, guard) {
if (guard && isIterateeCall(object, multiValue, guard)) {
diff --git a/object/mapValues.js b/object/mapValues.js
index b7e1e5c93..edde5da5e 100644
--- a/object/mapValues.js
+++ b/object/mapValues.js
@@ -28,8 +28,10 @@ var baseCallback = require('../internal/baseCallback'),
* @returns {Object} Returns the new mapped object.
* @example
*
- * _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(n) { return n * 3; });
- * // => { 'a': 3, 'b': 6, 'c': 9 }
+ * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
+ * return n * 3;
+ * });
+ * // => { 'a': 3, 'b': 6 }
*
* var users = {
* 'fred': { 'user': 'fred', 'age': 40 },
diff --git a/object/merge.js b/object/merge.js
index ba1d8f24f..eade105b0 100644
--- a/object/merge.js
+++ b/object/merge.js
@@ -43,7 +43,9 @@ var baseMerge = require('../internal/baseMerge'),
* };
*
* _.merge(object, other, function(a, b) {
- * return _.isArray(a) ? a.concat(b) : undefined;
+ * if (_.isArray(a)) {
+ * return a.concat(b);
+ * }
* });
* // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
*/
diff --git a/object/transform.js b/object/transform.js
index c31b8f05f..8b7007327 100644
--- a/object/transform.js
+++ b/object/transform.js
@@ -25,18 +25,16 @@ var arrayEach = require('../internal/arrayEach'),
* @returns {*} Returns the accumulated value.
* @example
*
- * var squares = _.transform([1, 2, 3, 4, 5, 6], function(result, n) {
- * n *= n;
- * if (n % 2) {
- * return result.push(n) < 3;
- * }
+ * _.transform([2, 3, 4], function(result, n) {
+ * result.push(n *= n);
+ * return n % 2 == 0;
* });
- * // => [1, 9, 25]
+ * // => [4, 9]
*
- * var mapped = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) {
+ * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
* result[key] = n * 3;
* });
- * // => { 'a': 3, 'b': 6, 'c': 9 }
+ * // => { 'a': 3, 'b': 6 }
*/
function transform(object, iteratee, accumulator, thisArg) {
var isArr = isArray(object) || isTypedArray(object);
diff --git a/package.json b/package.json
index e009e2b36..faf0a17a3 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "lodash",
- "version": "3.2.0",
+ "version": "3.3.0",
"description": "The modern build of lodash modular utilities.",
"homepage": "https://lodash.com/",
"icon": "https://lodash.com/icon.svg",
diff --git a/string/kebabCase.js b/string/kebabCase.js
index 82bbd3d46..a65f65ade 100644
--- a/string/kebabCase.js
+++ b/string/kebabCase.js
@@ -1,7 +1,7 @@
var createCompounder = require('../internal/createCompounder');
/**
- * Converts `string` to kebab case (a.k.a. spinal case).
+ * Converts `string` to kebab case.
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for
* more details.
*
diff --git a/string/trunc.js b/string/trunc.js
index cc0160acd..4a2afe8bb 100644
--- a/string/trunc.js
+++ b/string/trunc.js
@@ -33,13 +33,21 @@ var reFlags = /\w*$/;
* _.trunc('hi-diddly-ho there, neighborino', 24);
* // => 'hi-diddly-ho there, n...'
*
- * _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' });
+ * _.trunc('hi-diddly-ho there, neighborino', {
+ * 'length': 24,
+ * 'separator': ' '
+ * });
* // => 'hi-diddly-ho there,...'
*
- * _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ });
+ * _.trunc('hi-diddly-ho there, neighborino', {
+ * 'length': 24,
+ * 'separator': /,? +/
+ * });
* //=> 'hi-diddly-ho there...'
*
- * _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' });
+ * _.trunc('hi-diddly-ho there, neighborino', {
+ * 'omission': ' [...]'
+ * });
* // => 'hi-diddly-ho there, neig [...]'
*/
function trunc(string, options, guard) {
diff --git a/utility/attempt.js b/utility/attempt.js
index 997a930bb..a0ac0af6d 100644
--- a/utility/attempt.js
+++ b/utility/attempt.js
@@ -1,5 +1,4 @@
-var baseSlice = require('../internal/baseSlice'),
- isError = require('../lang/isError');
+var isError = require('../lang/isError');
/**
* Attempts to invoke `func`, returning either the result or the caught error
@@ -21,9 +20,16 @@ var baseSlice = require('../internal/baseSlice'),
* elements = [];
* }
*/
-function attempt(func) {
+function attempt() {
+ var length = arguments.length,
+ func = arguments[0];
+
try {
- return func.apply(undefined, baseSlice(arguments, 1));
+ var args = Array(length ? length - 1 : 0);
+ while (--length > 0) {
+ args[length - 1] = arguments[length];
+ }
+ return func.apply(undefined, args);
} catch(e) {
return isError(e) ? e : new Error(e);
}
diff --git a/utility/callback.js b/utility/callback.js
index 756ccbea0..d864d46c5 100644
--- a/utility/callback.js
+++ b/utility/callback.js
@@ -32,7 +32,9 @@ var baseCallback = require('../internal/baseCallback'),
* return callback(func, thisArg);
* }
* return function(object) {
- * return match[2] == 'gt' ? object[match[1]] > match[3] : object[match[1]] < match[3];
+ * return match[2] == 'gt'
+ * ? object[match[1]] > match[3]
+ * : object[match[1]] < match[3];
* };
* });
*
diff --git a/utility/constant.js b/utility/constant.js
index 4d2408d7b..6919b7632 100644
--- a/utility/constant.js
+++ b/utility/constant.js
@@ -10,6 +10,7 @@
*
* var object = { 'user': 'fred' };
* var getter = _.constant(object);
+ *
* getter() === object;
* // => true
*/
diff --git a/utility/identity.js b/utility/identity.js
index 9b7b3f3ed..3a1d1d4c9 100644
--- a/utility/identity.js
+++ b/utility/identity.js
@@ -9,6 +9,7 @@
* @example
*
* var object = { 'user': 'fred' };
+ *
* _.identity(object) === object;
* // => true
*/
diff --git a/utility/noop.js b/utility/noop.js
index da5164f6e..344adea0c 100644
--- a/utility/noop.js
+++ b/utility/noop.js
@@ -1,5 +1,6 @@
/**
- * A no-operation function.
+ * A no-operation function which returns `undefined` regardless of the
+ * arguments it receives.
*
* @static
* @memberOf _
@@ -7,6 +8,7 @@
* @example
*
* var object = { 'user': 'fred' };
+ *
* _.noop(object) === undefined;
* // => true
*/
diff --git a/utility/propertyOf.js b/utility/propertyOf.js
index d784fd487..62bb825c6 100644
--- a/utility/propertyOf.js
+++ b/utility/propertyOf.js
@@ -9,11 +9,11 @@
* @returns {Function} Returns the new function.
* @example
*
- * var object = { 'user': 'fred', 'age': 40, 'active': true };
- * _.map(['active', 'user'], _.propertyOf(object));
- * // => [true, 'fred']
- *
* var object = { 'a': 3, 'b': 1, 'c': 2 };
+ *
+ * _.map(['a', 'c'], _.propertyOf(object));
+ * // => [3, 2]
+ *
* _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
* // => ['b', 'c', 'a']
*/
diff --git a/utility/range.js b/utility/range.js
index d4ac09d8e..27bb71382 100644
--- a/utility/range.js
+++ b/utility/range.js
@@ -8,8 +8,9 @@ var nativeMax = Math.max;
/**
* Creates an array of numbers (positive and/or negative) progressing from
- * `start` up to, but not including, `end`. If `start` is less than `end` a
- * zero-length range is created unless a negative `step` is specified.
+ * `start` up to, but not including, `end`. If `end` is not specified it
+ * defaults to `start` with `start` becoming `0`. If `start` is less than
+ * `end` a zero-length range is created unless a negative `step` is specified.
*
* @static
* @memberOf _
diff --git a/utility/times.js b/utility/times.js
index d901f61f7..8279a0682 100644
--- a/utility/times.js
+++ b/utility/times.js
@@ -24,10 +24,14 @@ var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1;
* var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
* // => [3, 6, 4]
*
- * _.times(3, function(n) { mage.castSpell(n); });
+ * _.times(3, function(n) {
+ * mage.castSpell(n);
+ * });
* // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2` respectively
*
- * _.times(3, function(n) { this.cast(n); }, mage);
+ * _.times(3, function(n) {
+ * this.cast(n);
+ * }, mage);
* // => also invokes `mage.castSpell(n)` three times
*/
function times(n, iteratee, thisArg) {