diff --git a/README.md b/README.md index 94679ea2e..448f953f3 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 [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules. diff --git a/array/difference.js b/array/difference.js index dcb0b4b91..ae5f3184f 100644 --- a/array/difference.js +++ b/array/difference.js @@ -17,7 +17,7 @@ define(['../internal/baseDifference', '../internal/baseFlatten', '../lang/isArgu * @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 6bdd70a52..9f20459b7 100644 --- a/array/dropRightWhile.js +++ b/array/dropRightWhile.js @@ -26,7 +26,9 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb * @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 8b177811e..7148f4ffb 100644 --- a/array/dropWhile.js +++ b/array/dropWhile.js @@ -26,7 +26,9 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb * @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 bb734db9a..7edf0a794 100644 --- a/array/findIndex.js +++ b/array/findIndex.js @@ -31,7 +31,9 @@ define(['../internal/baseCallback'], function(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 91304de19..22dc8c661 100644 --- a/array/findLastIndex.js +++ b/array/findLastIndex.js @@ -31,7 +31,9 @@ define(['../internal/baseCallback'], function(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 286414a83..ca549bf0c 100644 --- a/array/flatten.js +++ b/array/flatten.js @@ -13,11 +13,11 @@ define(['../internal/baseFlatten', '../internal/isIterateeCall'], function(baseF * @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 967fb65e5..297f424fe 100644 --- a/array/flattenDeep.js +++ b/array/flattenDeep.js @@ -10,7 +10,7 @@ define(['../internal/baseFlatten'], function(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 1ceffb735..547abc4b8 100644 --- a/array/indexOf.js +++ b/array/indexOf.js @@ -24,15 +24,15 @@ define(['../internal/baseIndexOf', '../internal/binaryIndex'], function(baseInde * @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 2073df5bb..31d19e671 100644 --- a/array/intersection.js +++ b/array/intersection.js @@ -15,9 +15,8 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea * @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 1f34ca6f3..ce911e2ba 100644 --- a/array/lastIndexOf.js +++ b/array/lastIndexOf.js @@ -18,15 +18,15 @@ define(['../internal/binaryIndex', '../internal/indexOfNaN'], function(binaryInd * @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 4867801f5..07cc4c468 100644 --- a/array/pull.js +++ b/array/pull.js @@ -25,6 +25,7 @@ define(['../internal/baseIndexOf'], function(baseIndexOf) { * @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 62566ddc0..48b79401f 100644 --- a/array/pullAt.js +++ b/array/pullAt.js @@ -17,7 +17,7 @@ define(['../internal/baseFlatten', '../internal/basePullAt'], function(baseFlatt * @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 3d9555bcc..5a5f33182 100644 --- a/array/remove.js +++ b/array/remove.js @@ -35,7 +35,9 @@ define(['../internal/baseCallback'], function(baseCallback) { * @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 4bab5863a..51f6c67fc 100644 --- a/array/sortedIndex.js +++ b/array/sortedIndex.js @@ -33,7 +33,7 @@ define(['../internal/baseCallback', '../internal/binaryIndex', '../internal/bina * _.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 31af81d74..1628dc8bc 100644 --- a/array/sortedLastIndex.js +++ b/array/sortedLastIndex.js @@ -17,7 +17,7 @@ define(['../internal/baseCallback', '../internal/binaryIndex', '../internal/bina * 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 9099c4e66..dbcef3d5a 100644 --- a/array/takeRightWhile.js +++ b/array/takeRightWhile.js @@ -26,7 +26,9 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb * @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 8de596609..e4fe044f1 100644 --- a/array/takeWhile.js +++ b/array/takeWhile.js @@ -26,7 +26,9 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb * @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 c1fe6ce2f..56b11a823 100644 --- a/array/union.js +++ b/array/union.js @@ -16,8 +16,8 @@ define(['../internal/baseFlatten', '../internal/baseUniq'], function(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 d0b04f0e4..13626f167 100644 --- a/array/uniq.js +++ b/array/uniq.js @@ -43,7 +43,9 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera * // => [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 @@ -55,8 +57,7 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera 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 c86f1f9d7..9da8d5466 100644 --- a/array/without.js +++ b/array/without.js @@ -17,8 +17,8 @@ define(['../internal/baseDifference', '../internal/baseSlice'], function(baseDif * @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 2831a0e00..fa3e7e058 100644 --- a/array/xor.js +++ b/array/xor.js @@ -12,11 +12,8 @@ define(['../internal/baseDifference', '../internal/baseUniq', '../lang/isArgumen * @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 73133a18b..81004d830 100644 --- a/chain/chain.js +++ b/chain/chain.js @@ -19,7 +19,9 @@ define(['./lodash'], function(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 bf913d344..6e5814934 100644 --- a/chain/lodash.js +++ b/chain/lodash.js @@ -1,4 +1,4 @@ -define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../lang/isArray', '../internal/isObjectLike', '../internal/wrapperClone'], function(LazyWrapper, LodashWrapper, isArray, isObjectLike, wrapperClone) { +define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../internal/baseLodash', '../lang/isArray', '../internal/isObjectLike', '../internal/wrapperClone'], function(LazyWrapper, LodashWrapper, baseLodash, isArray, isObjectLike, wrapperClone) { /** Used for native method references. */ var objectProto = Object.prototype; @@ -78,11 +78,15 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../lang/isArray * 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 @@ -102,5 +106,8 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../lang/isArray return new LodashWrapper(value); } + // Ensure wrappers are instances of `baseLodash`. + lodash.prototype = baseLodash.prototype; + return lodash; }); diff --git a/chain/tap.js b/chain/tap.js index 09fc2da0f..ebccd6a8b 100644 --- a/chain/tap.js +++ b/chain/tap.js @@ -16,7 +16,9 @@ define([], function() { * @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 8d52665e0..d597635a2 100644 --- a/chain/thru.js +++ b/chain/thru.js @@ -14,7 +14,9 @@ define([], function() { * * _([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 032cb1a13..51d2168ab 100644 --- a/chain/wrapperPlant.js +++ b/chain/wrapperPlant.js @@ -1,4 +1,4 @@ -define(['../internal/LodashWrapper', '../internal/wrapperClone'], function(LodashWrapper, wrapperClone) { +define(['../internal/baseLodash', '../internal/wrapperClone'], function(baseLodash, wrapperClone) { /** * Creates a clone of the chained sequence planting `value` as the wrapped value. @@ -27,7 +27,7 @@ define(['../internal/LodashWrapper', '../internal/wrapperClone'], function(Lodas 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 f4bcfe6b7..f8bdba9aa 100644 --- a/collection/at.js +++ b/collection/at.js @@ -14,8 +14,8 @@ define(['../internal/baseAt', '../internal/baseFlatten', '../internal/isLength', * @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 95416e280..840ad72a0 100644 --- a/collection/countBy.js +++ b/collection/countBy.js @@ -34,10 +34,14 @@ define(['../internal/createAggregator'], function(createAggregator) { * @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 7aa14b250..8c24e6b66 100644 --- a/collection/filter.js +++ b/collection/filter.js @@ -27,8 +27,10 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base * @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 ddd55172e..63592a95c 100644 --- a/collection/find.js +++ b/collection/find.js @@ -36,7 +36,9 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseFin * { '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 6cda73313..80add0958 100644 --- a/collection/findLast.js +++ b/collection/findLast.js @@ -14,7 +14,9 @@ define(['../internal/baseCallback', '../internal/baseEachRight', '../internal/ba * @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 42b034ef8..a03c8a883 100644 --- a/collection/forEach.js +++ b/collection/forEach.js @@ -20,10 +20,14 @@ define(['../internal/arrayEach', '../internal/baseEach', '../internal/bindCallba * @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 aeb96ea1e..0233ef977 100644 --- a/collection/forEachRight.js +++ b/collection/forEachRight.js @@ -14,7 +14,9 @@ define(['../internal/arrayEachRight', '../internal/baseEachRight', '../internal/ * @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 cf462b61b..fbda007b4 100644 --- a/collection/groupBy.js +++ b/collection/groupBy.js @@ -34,10 +34,14 @@ define(['../internal/createAggregator'], function(createAggregator) { * @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 cb5d89874..8ffad8124 100644 --- a/collection/indexBy.js +++ b/collection/indexBy.js @@ -36,10 +36,14 @@ define(['../internal/createAggregator'], function(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 3e895ef3a..78e1d836c 100644 --- a/collection/map.js +++ b/collection/map.js @@ -37,11 +37,15 @@ define(['../internal/arrayMap', '../internal/baseCallback', '../internal/baseMap * @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 42faded9c..fd6254e88 100644 --- a/collection/max.js +++ b/collection/max.js @@ -38,7 +38,9 @@ define(['../internal/arrayMax', '../internal/createExtremum'], function(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 27576b2c2..9fb229991 100644 --- a/collection/min.js +++ b/collection/min.js @@ -38,7 +38,9 @@ define(['../internal/arrayMin', '../internal/createExtremum'], function(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 4618eceed..5cc4bd709 100644 --- a/collection/partition.js +++ b/collection/partition.js @@ -27,10 +27,14 @@ define(['../internal/createAggregator'], function(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 @@ define(['../internal/createAggregator'], function(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 f035c7768..947d99c80 100644 --- a/collection/reduce.js +++ b/collection/reduce.js @@ -25,14 +25,16 @@ define(['../internal/arrayReduce', '../internal/baseCallback', '../internal/base * @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 a39519349..e64b4d815 100644 --- a/collection/reduceRight.js +++ b/collection/reduceRight.js @@ -16,7 +16,10 @@ define(['../internal/arrayReduceRight', '../internal/baseCallback', '../internal * @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 249d897ce..c0d8cab92 100644 --- a/collection/reject.js +++ b/collection/reject.js @@ -25,7 +25,9 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base * @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 45bbab042..6168ad92d 100644 --- a/collection/size.js +++ b/collection/size.js @@ -11,12 +11,12 @@ define(['../internal/isLength', '../object/keys'], function(isLength, keys) { * @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 cd70f8ccd..f41ae3a76 100644 --- a/collection/sortBy.js +++ b/collection/sortBy.js @@ -29,10 +29,14 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseSor * @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 b0c63cb88..3599d302d 100644 --- a/date/now.js +++ b/date/now.js @@ -12,7 +12,9 @@ define(['../lang/isNative'], function(isNative) { * @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 580dc38ce..ae7582483 100644 --- a/function/bindAll.js +++ b/function/bindAll.js @@ -19,7 +19,9 @@ define(['../internal/baseBindAll', '../internal/baseFlatten', '../object/functio * * 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 701499569..281ccaf49 100644 --- a/function/defer.js +++ b/function/defer.js @@ -12,7 +12,9 @@ define(['../internal/baseDelay'], function(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 95b1fb2f5..e7431ed10 100644 --- a/function/delay.js +++ b/function/delay.js @@ -13,7 +13,9 @@ define(['../internal/baseDelay'], function(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 faacd7f37..f19e0f00e 100644 --- a/function/flow.js +++ b/function/flow.js @@ -1,4 +1,4 @@ -define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, isFunction) { +define(['../internal/arrayEvery', '../internal/baseIsFunction'], function(arrayEvery, baseIsFunction) { /** Used as the `TypeError` message for "Functions" methods. */ var FUNC_ERROR_TEXT = 'Expected a function'; @@ -34,7 +34,7 @@ define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, is 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 834508202..632b25981 100644 --- a/function/flowRight.js +++ b/function/flowRight.js @@ -1,4 +1,4 @@ -define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, isFunction) { +define(['../internal/arrayEvery', '../internal/baseIsFunction'], function(arrayEvery, baseIsFunction) { /** Used as the `TypeError` message for "Functions" methods. */ var FUNC_ERROR_TEXT = 'Expected a function'; @@ -34,7 +34,7 @@ define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, is 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 e4f5473f2..630fb2c00 100644 --- a/function/rearg.js +++ b/function/rearg.js @@ -26,7 +26,9 @@ define(['../internal/baseFlatten', '../internal/createWrapper'], function(baseFl * // => ['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 589519fa9..97ac15e83 100644 --- a/function/throttle.js +++ b/function/throttle.js @@ -42,8 +42,9 @@ define(['./debounce', '../lang/isObject'], function(debounce, isObject) { * 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/internal/LazyWrapper.js b/internal/LazyWrapper.js index 552e24a31..c564a9f89 100644 --- a/internal/LazyWrapper.js +++ b/internal/LazyWrapper.js @@ -1,4 +1,4 @@ -define([], function() { +define(['./baseCreate', './baseLodash'], function(baseCreate, baseLodash) { /** Used as references for `-Infinity` and `Infinity`. */ var POSITIVE_INFINITY = Number.POSITIVE_INFINITY; @@ -20,5 +20,8 @@ define([], function() { this.__views__ = null; } + LazyWrapper.prototype = baseCreate(baseLodash.prototype); + LazyWrapper.prototype.constructor = LazyWrapper; + return LazyWrapper; }); diff --git a/internal/LodashWrapper.js b/internal/LodashWrapper.js index 80f7dc0bf..d03a968a9 100644 --- a/internal/LodashWrapper.js +++ b/internal/LodashWrapper.js @@ -1,4 +1,4 @@ -define([], function() { +define(['./baseCreate', './baseLodash'], function(baseCreate, baseLodash) { /** * The base constructor for creating `lodash` wrapper objects. @@ -14,5 +14,8 @@ define([], function() { this.__chain__ = !!chainAll; } + LodashWrapper.prototype = baseCreate(baseLodash.prototype); + LodashWrapper.prototype.constructor = LodashWrapper; + return LodashWrapper; }); diff --git a/internal/baseIsFunction.js b/internal/baseIsFunction.js new file mode 100644 index 000000000..458999d1a --- /dev/null +++ b/internal/baseIsFunction.js @@ -0,0 +1,18 @@ +define([], function() { + + /** + * 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; + } + + return baseIsFunction; +}); diff --git a/internal/baseLodash.js b/internal/baseLodash.js new file mode 100644 index 000000000..e4dfecf22 --- /dev/null +++ b/internal/baseLodash.js @@ -0,0 +1,13 @@ +define([], function() { + + /** + * The function whose prototype all chaining wrappers inherit from. + * + * @private + */ + function baseLodash() { + // No operation performed. + } + + return baseLodash; +}); diff --git a/internal/baseMerge.js b/internal/baseMerge.js index 089bc36ad..087ce06cd 100644 --- a/internal/baseMerge.js +++ b/internal/baseMerge.js @@ -1,4 +1,4 @@ -define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './isLength', './isObjectLike', '../lang/isTypedArray'], function(arrayEach, baseForOwn, baseMergeDeep, isArray, isLength, isObjectLike, isTypedArray) { +define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './isLength', '../lang/isObject', './isObjectLike', '../lang/isTypedArray'], function(arrayEach, baseForOwn, baseMergeDeep, isArray, isLength, isObject, isObjectLike, isTypedArray) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -16,8 +16,10 @@ define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './ * @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 99e93d5bf..f6eafd974 100644 --- a/internal/isIterateeCall.js +++ b/internal/isIterateeCall.js @@ -20,7 +20,8 @@ define(['./isIndex', './isLength', '../lang/isObject'], function(isIndex, isLeng } else { prereq = type == 'string' && index in object; } - return prereq && object[index] === value; + var other = object[index]; + return prereq && (value === value ? value === other : other !== other); } return isIterateeCall; diff --git a/lang/clone.js b/lang/clone.js index 6b08b6cfa..7285b18e2 100644 --- a/lang/clone.js +++ b/lang/clone.js @@ -38,22 +38,26 @@ define(['../internal/baseClone', '../internal/bindCallback', '../internal/isIter * // => 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 08c25c1bf..c8906cf46 100644 --- a/lang/cloneDeep.js +++ b/lang/cloneDeep.js @@ -33,14 +33,16 @@ define(['../internal/baseClone', '../internal/bindCallback'], function(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 1c4693ab4..a63a94fd5 100644 --- a/lang/isArguments.js +++ b/lang/isArguments.js @@ -26,7 +26,7 @@ define(['../internal/isLength', '../internal/isObjectLike'], function(isLength, * @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 6c7322207..0844a98ff 100644 --- a/lang/isArray.js +++ b/lang/isArray.js @@ -29,7 +29,7 @@ define(['../internal/isLength', './isNative', '../internal/isObjectLike'], funct * _.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 867f03279..fa9777b2d 100644 --- a/lang/isEqual.js +++ b/lang/isEqual.js @@ -40,7 +40,9 @@ define(['../internal/baseIsEqual', '../internal/bindCallback', '../internal/isSt * 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 ddc47b093..d1736aaf6 100644 --- a/lang/isFunction.js +++ b/lang/isFunction.js @@ -1,4 +1,4 @@ -define(['./isNative', '../internal/root'], function(isNative, root) { +define(['../internal/baseIsFunction', './isNative', '../internal/root'], function(baseIsFunction, isNative, root) { /** `Object#toString` result references. */ var funcTag = '[object Function]'; @@ -32,20 +32,12 @@ define(['./isNative', '../internal/root'], function(isNative, root) { * _.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; + }; return isFunction; }); diff --git a/lang/toArray.js b/lang/toArray.js index 9375c7fc8..7df6fa480 100644 --- a/lang/toArray.js +++ b/lang/toArray.js @@ -10,7 +10,9 @@ define(['../internal/arrayCopy', '../internal/isLength', '../object/values'], fu * @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/main.js b/main.js index 9e54ef7ec..7e269edfa 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ /** * @license - * lodash 3.2.0 (Custom Build) + * lodash 3.3.0 (Custom Build) * Build: `lodash modern exports="amd" -d -o ./main.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, @@ -323,6 +323,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 @@ -847,11 +861,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 @@ -871,6 +889,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. * @@ -2359,8 +2386,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 = []); @@ -3644,7 +3673,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); } /** @@ -4039,7 +4069,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() { @@ -4152,7 +4182,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 = [ @@ -4209,7 +4241,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 = [ @@ -4299,7 +4333,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 @@ -4358,7 +4394,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 @@ -4418,11 +4456,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) { @@ -4443,7 +4481,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) { @@ -4472,15 +4510,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) { @@ -4531,9 +4569,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 = [], @@ -4609,15 +4646,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) { @@ -4663,6 +4700,7 @@ * @example * * var array = [1, 2, 3, 1, 2, 3]; + * * _.pull(array, 2, 3); * console.log(array); * // => [1, 1] @@ -4704,7 +4742,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] @@ -4745,7 +4783,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] @@ -4847,7 +4887,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 } }; @@ -4886,7 +4926,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) { @@ -4993,7 +5033,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 = [ @@ -5050,7 +5092,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 = [ @@ -5098,8 +5142,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)); @@ -5148,7 +5192,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 @@ -5160,8 +5206,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; @@ -5221,8 +5266,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)); @@ -5240,11 +5285,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, @@ -5343,7 +5385,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' @@ -5370,7 +5414,9 @@ * @example * * _([1, 2, 3]) - * .tap(function(array) { array.pop(); }) + * .tap(function(array) { + * array.pop(); + * }) * .reverse() * .value(); * // => [2, 1] @@ -5394,7 +5440,9 @@ * * _([1, 2, 3]) * .last() - * .thru(function(value) { return [value]; }) + * .thru(function(value) { + * return [value]; + * }) * .value(); * // => [3] */ @@ -5487,7 +5535,7 @@ var result, parent = this; - while (parent instanceof LodashWrapper) { + while (parent instanceof baseLodash) { var clone = wrapperClone(parent); if (result) { previous.__wrapped__ = clone; @@ -5583,8 +5631,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'] @@ -5597,57 +5645,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 @@ -5676,10 +5673,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'); @@ -5772,8 +5773,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 }, @@ -5831,7 +5834,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 @@ -5869,7 +5874,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) { @@ -5930,10 +5937,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) { @@ -5956,7 +5967,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) { @@ -5993,10 +6006,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 @@ -6011,6 +6028,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 @@ -6047,10 +6115,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) { @@ -6120,11 +6192,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' }, @@ -6179,7 +6255,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 @@ -6226,7 +6304,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 @@ -6262,10 +6342,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 = [ @@ -6274,7 +6358,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); @@ -6344,14 +6430,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; @@ -6374,7 +6462,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) { @@ -6407,7 +6498,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 = [ @@ -6507,12 +6600,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 */ @@ -6607,10 +6700,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 = [ @@ -6727,7 +6824,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() { @@ -6903,7 +7002,9 @@ * * var view = { * 'label': 'docs', - * 'onClick': function() { console.log('clicked ' + this.label); } + * 'onClick': function() { + * console.log('clicked ' + this.label); + * } * }; * * _.bindAll(view); @@ -7256,7 +7357,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) { @@ -7276,7 +7379,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) { @@ -7314,7 +7419,7 @@ if (!length) { return function() { return arguments[0]; }; } - if (!arrayEvery(funcs, isFunction)) { + if (!arrayEvery(funcs, baseIsFunction)) { throw new TypeError(FUNC_ERROR_TEXT); } return function() { @@ -7359,7 +7464,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() { @@ -7594,7 +7699,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) { @@ -7673,8 +7780,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); @@ -7764,22 +7872,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); @@ -7819,14 +7931,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) { @@ -7844,7 +7958,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]); @@ -7868,7 +7982,7 @@ * _.isArray([1, 2, 3]); * // => true * - * (function() { return _.isArray(arguments); })(); + * _.isArray(function() { return arguments; }()); * // => false */ var isArray = nativeIsArray || function(value) { @@ -8018,7 +8132,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 */ @@ -8101,20 +8217,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`. @@ -8443,7 +8551,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) { @@ -8540,7 +8650,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; @@ -8613,7 +8725,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 @@ -8664,7 +8778,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 @@ -8763,10 +8879,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') { @@ -8788,10 +8911,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); @@ -8811,7 +8941,7 @@ * @example * * _.functions(_); - * // => ['all', 'any', 'bind', ...] + * // => ['after', 'ary', 'assign', ...] */ function functions(object) { return baseFunctions(object, keysIn(object)); @@ -8829,7 +8959,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) { @@ -8850,16 +8982,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)) { @@ -9005,8 +9135,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 }, @@ -9069,7 +9201,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'] } */ @@ -9235,18 +9369,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); @@ -9328,6 +9460,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. @@ -9547,7 +9721,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. * @@ -10146,13 +10320,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) { @@ -10280,9 +10462,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); } @@ -10317,7 +10506,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]; * }; * }); * @@ -10345,6 +10536,7 @@ * * var object = { 'user': 'fred' }; * var getter = _.constant(object); + * * getter() === object; * // => true */ @@ -10365,6 +10557,7 @@ * @example * * var object = { 'user': 'fred' }; + * * _.identity(object) === object; * // => true */ @@ -10535,7 +10728,8 @@ } /** - * A no-operation function. + * A no-operation function which returns `undefined` regardless of the + * arguments it receives. * * @static * @memberOf _ @@ -10543,6 +10737,7 @@ * @example * * var object = { 'user': 'fred' }; + * * _.noop(object) === undefined; * // => true */ @@ -10588,11 +10783,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'] */ @@ -10604,8 +10799,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 _ @@ -10677,10 +10873,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) { @@ -10728,11 +10928,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. @@ -10890,6 +11092,7 @@ lodash.identity = identity; lodash.includes = includes; lodash.indexOf = indexOf; + lodash.inRange = inRange; lodash.isArguments = isArguments; lodash.isArray = isArray; lodash.isBoolean = isBoolean; @@ -11161,7 +11364,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; @@ -11169,7 +11372,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/number.js b/number.js index 40c6606fa..f7de03728 100644 --- a/number.js +++ b/number.js @@ -1,5 +1,6 @@ -define(['./number/random'], function(random) { +define(['./number/inRange', './number/random'], function(inRange, random) { return { + 'inRange': inRange, 'random': random }; }); diff --git a/number/inRange.js b/number/inRange.js new file mode 100644 index 000000000..b2c1e4a89 --- /dev/null +++ b/number/inRange.js @@ -0,0 +1,46 @@ +define([], function() { + + /** + * 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; + } + + return inRange; +}); diff --git a/object/create.js b/object/create.js index ce4d5b1bd..dc4f56b26 100644 --- a/object/create.js +++ b/object/create.js @@ -23,7 +23,9 @@ define(['../internal/baseCopy', '../internal/baseCreate', '../internal/isIterate * 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 2589076c9..8a948159f 100644 --- a/object/findKey.js +++ b/object/findKey.js @@ -31,7 +31,9 @@ define(['../internal/baseCallback', '../internal/baseFind', '../internal/baseFor * '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 75f3f9b34..3f262c1b6 100644 --- a/object/findLastKey.js +++ b/object/findLastKey.js @@ -31,7 +31,9 @@ define(['../internal/baseCallback', '../internal/baseFind', '../internal/baseFor * '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 4fc91fde1..99e2de096 100644 --- a/object/forOwn.js +++ b/object/forOwn.js @@ -15,10 +15,17 @@ define(['../internal/baseForOwn', '../internal/bindCallback'], function(baseForO * @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 ec602bc73..09811e51e 100644 --- a/object/forOwnRight.js +++ b/object/forOwnRight.js @@ -13,10 +13,17 @@ define(['../internal/baseForRight', '../internal/bindCallback', './keys'], funct * @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 4d8fc277c..35504e68f 100644 --- a/object/functions.js +++ b/object/functions.js @@ -13,7 +13,7 @@ define(['../internal/baseFunctions', './keysIn'], function(baseFunctions, keysIn * @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 ff51cbd5f..51b1200a4 100644 --- a/object/has.js +++ b/object/has.js @@ -18,7 +18,9 @@ define([], function() { * @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 3d77e8bfd..dc0c2e05c 100644 --- a/object/invert.js +++ b/object/invert.js @@ -20,16 +20,14 @@ define(['../internal/isIterateeCall', './keys'], function(isIterateeCall, keys) * @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 a357138fb..2eb702712 100644 --- a/object/mapValues.js +++ b/object/mapValues.js @@ -27,8 +27,10 @@ define(['../internal/baseCallback', '../internal/baseForOwn'], function(baseCall * @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 43ff4d595..d331ea9c5 100644 --- a/object/merge.js +++ b/object/merge.js @@ -42,7 +42,9 @@ define(['../internal/baseMerge', '../internal/createAssigner'], function(baseMer * }; * * _.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 ad650d560..ec9ca5d1c 100644 --- a/object/transform.js +++ b/object/transform.js @@ -18,18 +18,16 @@ define(['../internal/arrayEach', '../internal/baseCallback', '../internal/baseCr * @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 352a06432..f5aecb096 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash", - "version": "3.2.0", + "version": "3.3.0", "main": "main.js", "private": true, "volo": { diff --git a/string/kebabCase.js b/string/kebabCase.js index d5f76bfa2..3ac2d5e17 100644 --- a/string/kebabCase.js +++ b/string/kebabCase.js @@ -1,7 +1,7 @@ define(['../internal/createCompounder'], function(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 ea4b04379..043b74919 100644 --- a/string/trunc.js +++ b/string/trunc.js @@ -30,13 +30,21 @@ define(['../internal/baseToString', '../internal/isIterateeCall', '../lang/isObj * _.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 92a35dd05..ef66b491c 100644 --- a/utility/attempt.js +++ b/utility/attempt.js @@ -1,4 +1,4 @@ -define(['../internal/baseSlice', '../lang/isError'], function(baseSlice, isError) { +define(['../lang/isError'], function(isError) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -23,9 +23,16 @@ define(['../internal/baseSlice', '../lang/isError'], function(baseSlice, isError * 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 710fbd7e1..977de379c 100644 --- a/utility/callback.js +++ b/utility/callback.js @@ -29,7 +29,9 @@ define(['../internal/baseCallback', '../internal/isIterateeCall', '../internal/i * 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 3e6562dfa..4782c739b 100644 --- a/utility/constant.js +++ b/utility/constant.js @@ -12,6 +12,7 @@ define([], function() { * * var object = { 'user': 'fred' }; * var getter = _.constant(object); + * * getter() === object; * // => true */ diff --git a/utility/identity.js b/utility/identity.js index 64f749007..b4950530b 100644 --- a/utility/identity.js +++ b/utility/identity.js @@ -11,6 +11,7 @@ define([], function() { * @example * * var object = { 'user': 'fred' }; + * * _.identity(object) === object; * // => true */ diff --git a/utility/noop.js b/utility/noop.js index 31e550442..eb2bb8019 100644 --- a/utility/noop.js +++ b/utility/noop.js @@ -1,7 +1,8 @@ define([], function() { /** - * A no-operation function. + * A no-operation function which returns `undefined` regardless of the + * arguments it receives. * * @static * @memberOf _ @@ -9,6 +10,7 @@ define([], function() { * @example * * var object = { 'user': 'fred' }; + * * _.noop(object) === undefined; * // => true */ diff --git a/utility/propertyOf.js b/utility/propertyOf.js index 0f36de682..a69ed064d 100644 --- a/utility/propertyOf.js +++ b/utility/propertyOf.js @@ -14,11 +14,11 @@ define([], function() { * @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 823d39bc9..3fe0bb006 100644 --- a/utility/range.js +++ b/utility/range.js @@ -8,8 +8,9 @@ define(['../internal/isIterateeCall'], function(isIterateeCall) { /** * 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 990e2b5b6..04fa99d6b 100644 --- a/utility/times.js +++ b/utility/times.js @@ -24,10 +24,14 @@ define(['../internal/bindCallback', '../internal/root'], function(bindCallback, * 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) {