Compare commits

...

2 Commits

Author SHA1 Message Date
John-David Dalton
7a82a3d77b Bump to v3.3.1. 2015-12-16 17:47:30 -08:00
John-David Dalton
f8e4370129 Bump to v3.3.0. 2015-12-16 17:46:57 -08:00
96 changed files with 863 additions and 429 deletions

View File

@@ -1,4 +1,4 @@
# lodash v3.2.0 # lodash v3.3.1
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. 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.

View File

@@ -17,7 +17,7 @@ define(['../internal/baseDifference', '../internal/baseFlatten', '../lang/isArgu
* @returns {Array} Returns the new array of filtered values. * @returns {Array} Returns the new array of filtered values.
* @example * @example
* *
* _.difference([1, 2, 3], [5, 2, 10]); * _.difference([1, 2, 3], [4, 2]);
* // => [1, 3] * // => [1, 3]
*/ */
function difference() { function difference() {

View File

@@ -26,7 +26,9 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
* *
* _.dropRightWhile([1, 2, 3], function(n) { return n > 1; }); * _.dropRightWhile([1, 2, 3], function(n) {
* return n > 1;
* });
* // => [1] * // => [1]
* *
* var users = [ * var users = [

View File

@@ -26,7 +26,9 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
* *
* _.dropWhile([1, 2, 3], function(n) { return n < 3; }); * _.dropWhile([1, 2, 3], function(n) {
* return n < 3;
* });
* // => [3] * // => [3]
* *
* var users = [ * var users = [

View File

@@ -31,7 +31,9 @@ define(['../internal/baseCallback'], function(baseCallback) {
* { 'user': 'pebbles', 'active': true } * { 'user': 'pebbles', 'active': true }
* ]; * ];
* *
* _.findIndex(users, function(chr) { return chr.user == 'barney'; }); * _.findIndex(users, function(chr) {
* return chr.user == 'barney';
* });
* // => 0 * // => 0
* *
* // using the `_.matches` callback shorthand * // using the `_.matches` callback shorthand

View File

@@ -31,11 +31,13 @@ define(['../internal/baseCallback'], function(baseCallback) {
* { 'user': 'pebbles', 'active': false } * { 'user': 'pebbles', 'active': false }
* ]; * ];
* *
* _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; }); * _.findLastIndex(users, function(chr) {
* return chr.user == 'pebbles';
* });
* // => 2 * // => 2
* *
* // using the `_.matches` callback shorthand * // using the `_.matches` callback shorthand
* _.findLastIndex(users, { user': 'barney', 'active': true }); * _.findLastIndex(users, { 'user': 'barney', 'active': true });
* // => 0 * // => 0
* *
* // using the `_.matchesProperty` callback shorthand * // using the `_.matchesProperty` callback shorthand

View File

@@ -13,11 +13,11 @@ define(['../internal/baseFlatten', '../internal/isIterateeCall'], function(baseF
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
* @example * @example
* *
* _.flatten([1, [2], [3, [[4]]]]); * _.flatten([1, [2, 3, [4]]]);
* // => [1, 2, 3, [[4]]]; * // => [1, 2, 3, [4]];
* *
* // using `isDeep` * // using `isDeep`
* _.flatten([1, [2], [3, [[4]]]], true); * _.flatten([1, [2, 3, [4]]], true);
* // => [1, 2, 3, 4]; * // => [1, 2, 3, 4];
*/ */
function flatten(array, isDeep, guard) { function flatten(array, isDeep, guard) {

View File

@@ -10,7 +10,7 @@ define(['../internal/baseFlatten'], function(baseFlatten) {
* @returns {Array} Returns the new flattened array. * @returns {Array} Returns the new flattened array.
* @example * @example
* *
* _.flattenDeep([1, [2], [3, [[4]]]]); * _.flattenDeep([1, [2, 3, [4]]]);
* // => [1, 2, 3, 4]; * // => [1, 2, 3, 4];
*/ */
function flattenDeep(array) { function flattenDeep(array) {

View File

@@ -24,15 +24,15 @@ define(['../internal/baseIndexOf', '../internal/binaryIndex'], function(baseInde
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
* @example * @example
* *
* _.indexOf([1, 2, 3, 1, 2, 3], 2); * _.indexOf([1, 2, 1, 2], 2);
* // => 1 * // => 1
* *
* // using `fromIndex` * // using `fromIndex`
* _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); * _.indexOf([1, 2, 1, 2], 2, 2);
* // => 4 * // => 3
* *
* // performing a binary search * // performing a binary search
* _.indexOf([4, 4, 5, 5, 6, 6], 5, true); * _.indexOf([1, 1, 2, 2], 2, true);
* // => 2 * // => 2
*/ */
function indexOf(array, value, fromIndex) { function indexOf(array, value, fromIndex) {

View File

@@ -15,9 +15,8 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea
* @param {...Array} [arrays] The arrays to inspect. * @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of shared values. * @returns {Array} Returns the new array of shared values.
* @example * @example
* * _.intersection([1, 2], [4, 2], [2, 1]);
* _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); * // => [2]
* // => [1, 2]
*/ */
function intersection() { function intersection() {
var args = [], var args = [],
@@ -31,7 +30,7 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea
var value = arguments[argsIndex]; var value = arguments[argsIndex];
if (isArray(value) || isArguments(value)) { if (isArray(value) || isArguments(value)) {
args.push(value); args.push(value);
caches.push(isCommon && value.length >= 120 && createCache(argsIndex && value)); caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null);
} }
} }
argsLength = args.length; argsLength = args.length;

View File

@@ -18,15 +18,15 @@ define(['../internal/binaryIndex', '../internal/indexOfNaN'], function(binaryInd
* @returns {number} Returns the index of the matched value, else `-1`. * @returns {number} Returns the index of the matched value, else `-1`.
* @example * @example
* *
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); * _.lastIndexOf([1, 2, 1, 2], 2);
* // => 4 * // => 3
* *
* // using `fromIndex` * // using `fromIndex`
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); * _.lastIndexOf([1, 2, 1, 2], 2, 2);
* // => 1 * // => 1
* *
* // performing a binary search * // performing a binary search
* _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true); * _.lastIndexOf([1, 1, 2, 2], 2, true);
* // => 3 * // => 3
*/ */
function lastIndexOf(array, value, fromIndex) { function lastIndexOf(array, value, fromIndex) {

View File

@@ -25,6 +25,7 @@ define(['../internal/baseIndexOf'], function(baseIndexOf) {
* @example * @example
* *
* var array = [1, 2, 3, 1, 2, 3]; * var array = [1, 2, 3, 1, 2, 3];
*
* _.pull(array, 2, 3); * _.pull(array, 2, 3);
* console.log(array); * console.log(array);
* // => [1, 1] * // => [1, 1]

View File

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

View File

@@ -35,7 +35,9 @@ define(['../internal/baseCallback'], function(baseCallback) {
* @example * @example
* *
* var array = [1, 2, 3, 4]; * var array = [1, 2, 3, 4];
* var evens = _.remove(array, function(n) { return n % 2 == 0; }); * var evens = _.remove(array, function(n) {
* return n % 2 == 0;
* });
* *
* console.log(array); * console.log(array);
* // => [1, 3] * // => [1, 3]

View File

@@ -33,7 +33,7 @@ define(['../internal/baseCallback', '../internal/binaryIndex', '../internal/bina
* _.sortedIndex([30, 50], 40); * _.sortedIndex([30, 50], 40);
* // => 1 * // => 1
* *
* _.sortedIndex([4, 4, 5, 5, 6, 6], 5); * _.sortedIndex([4, 4, 5, 5], 5);
* // => 2 * // => 2
* *
* var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } }; * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };

View File

@@ -17,7 +17,7 @@ define(['../internal/baseCallback', '../internal/binaryIndex', '../internal/bina
* into `array`. * into `array`.
* @example * @example
* *
* _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5); * _.sortedLastIndex([4, 4, 5, 5], 5);
* // => 4 * // => 4
*/ */
function sortedLastIndex(array, value, iteratee, thisArg) { function sortedLastIndex(array, value, iteratee, thisArg) {

View File

@@ -26,7 +26,9 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
* *
* _.takeRightWhile([1, 2, 3], function(n) { return n > 1; }); * _.takeRightWhile([1, 2, 3], function(n) {
* return n > 1;
* });
* // => [2, 3] * // => [2, 3]
* *
* var users = [ * var users = [

View File

@@ -26,7 +26,9 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb
* @returns {Array} Returns the slice of `array`. * @returns {Array} Returns the slice of `array`.
* @example * @example
* *
* _.takeWhile([1, 2, 3], function(n) { return n < 3; }); * _.takeWhile([1, 2, 3], function(n) {
* return n < 3;
* });
* // => [1, 2] * // => [1, 2]
* *
* var users = [ * var users = [

View File

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

View File

@@ -43,7 +43,9 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera
* // => [1, 2] * // => [1, 2]
* *
* // using an iteratee function * // using an iteratee function
* _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math); * _.uniq([1, 2.5, 1.5, 2], function(n) {
* return this.floor(n);
* }, Math);
* // => [1, 2.5] * // => [1, 2.5]
* *
* // using the `_.property` callback shorthand * // using the `_.property` callback shorthand
@@ -55,8 +57,7 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera
if (!length) { if (!length) {
return []; return [];
} }
// Juggle arguments. if (isSorted != null && typeof isSorted != 'boolean') {
if (typeof isSorted != 'boolean' && isSorted != null) {
thisArg = iteratee; thisArg = iteratee;
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted; iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
isSorted = false; isSorted = false;

View File

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

View File

@@ -12,11 +12,8 @@ define(['../internal/baseDifference', '../internal/baseUniq', '../lang/isArgumen
* @returns {Array} Returns the new array of values. * @returns {Array} Returns the new array of values.
* @example * @example
* *
* _.xor([1, 2, 3], [5, 2, 1, 4]); * _.xor([1, 2], [4, 2]);
* // => [3, 5, 4] * // => [1, 4]
*
* _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
* // => [1, 4, 5]
*/ */
function xor() { function xor() {
var index = -1, var index = -1,

View File

@@ -19,7 +19,9 @@ define(['./lodash'], function(lodash) {
* *
* var youngest = _.chain(users) * var youngest = _.chain(users)
* .sortBy('age') * .sortBy('age')
* .map(function(chr) { return chr.user + ' is ' + chr.age; }) * .map(function(chr) {
* return chr.user + ' is ' + chr.age;
* })
* .first() * .first()
* .value(); * .value();
* // => 'pebbles is 1' * // => 'pebbles is 1'

View File

@@ -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. */ /** Used for native method references. */
var objectProto = Object.prototype; var objectProto = Object.prototype;
@@ -78,11 +78,15 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../lang/isArray
* var wrapped = _([1, 2, 3]); * var wrapped = _([1, 2, 3]);
* *
* // returns an unwrapped value * // returns an unwrapped value
* wrapped.reduce(function(sum, n) { return sum + n; }); * wrapped.reduce(function(sum, n) {
* return sum + n;
* });
* // => 6 * // => 6
* *
* // returns a wrapped value * // returns a wrapped value
* var squares = wrapped.map(function(n) { return n * n; }); * var squares = wrapped.map(function(n) {
* return n * n;
* });
* *
* _.isArray(squares); * _.isArray(squares);
* // => false * // => false
@@ -102,5 +106,8 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../lang/isArray
return new LodashWrapper(value); return new LodashWrapper(value);
} }
// Ensure wrappers are instances of `baseLodash`.
lodash.prototype = baseLodash.prototype;
return lodash; return lodash;
}); });

View File

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

View File

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

View File

@@ -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. * 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, var result,
parent = this; parent = this;
while (parent instanceof LodashWrapper) { while (parent instanceof baseLodash) {
var clone = wrapperClone(parent); var clone = wrapperClone(parent);
if (result) { if (result) {
previous.__wrapped__ = clone; previous.__wrapped__ = clone;

View File

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

View File

@@ -34,10 +34,14 @@ define(['../internal/createAggregator'], function(createAggregator) {
* @returns {Object} Returns the composed aggregate object. * @returns {Object} Returns the composed aggregate object.
* @example * @example
* *
* _.countBy([4.3, 6.1, 6.4], function(n) { return Math.floor(n); }); * _.countBy([4.3, 6.1, 6.4], function(n) {
* return Math.floor(n);
* });
* // => { '4': 1, '6': 2 } * // => { '4': 1, '6': 2 }
* *
* _.countBy([4.3, 6.1, 6.4], function(n) { return this.floor(n); }, Math); * _.countBy([4.3, 6.1, 6.4], function(n) {
* return this.floor(n);
* }, Math);
* // => { '4': 1, '6': 2 } * // => { '4': 1, '6': 2 }
* *
* _.countBy(['one', 'two', 'three'], 'length'); * _.countBy(['one', 'two', 'three'], 'length');

View File

@@ -27,8 +27,10 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base
* @returns {Array} Returns the new filtered array. * @returns {Array} Returns the new filtered array.
* @example * @example
* *
* var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; }); * _.filter([4, 5, 6], function(n) {
* // => [2, 4] * return n % 2 == 0;
* });
* // => [4, 6]
* *
* var users = [ * var users = [
* { 'user': 'barney', 'age': 36, 'active': true }, * { 'user': 'barney', 'age': 36, 'active': true },

View File

@@ -36,7 +36,9 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseFin
* { 'user': 'pebbles', 'age': 1, 'active': true } * { 'user': 'pebbles', 'age': 1, 'active': true }
* ]; * ];
* *
* _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user'); * _.result(_.find(users, function(chr) {
* return chr.age < 40;
* }), 'user');
* // => 'barney' * // => 'barney'
* *
* // using the `_.matches` callback shorthand * // using the `_.matches` callback shorthand

View File

@@ -14,7 +14,9 @@ define(['../internal/baseCallback', '../internal/baseEachRight', '../internal/ba
* @returns {*} Returns the matched element, else `undefined`. * @returns {*} Returns the matched element, else `undefined`.
* @example * @example
* *
* _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; }); * _.findLast([1, 2, 3, 4], function(n) {
* return n % 2 == 1;
* });
* // => 3 * // => 3
*/ */
function findLast(collection, predicate, thisArg) { function findLast(collection, predicate, thisArg) {

View File

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

View File

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

View File

@@ -34,10 +34,14 @@ define(['../internal/createAggregator'], function(createAggregator) {
* @returns {Object} Returns the composed aggregate object. * @returns {Object} Returns the composed aggregate object.
* @example * @example
* *
* _.groupBy([4.2, 6.1, 6.4], function(n) { return Math.floor(n); }); * _.groupBy([4.2, 6.1, 6.4], function(n) {
* return Math.floor(n);
* });
* // => { '4': [4.2], '6': [6.1, 6.4] } * // => { '4': [4.2], '6': [6.1, 6.4] }
* *
* _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math); * _.groupBy([4.2, 6.1, 6.4], function(n) {
* return this.floor(n);
* }, Math);
* // => { '4': [4.2], '6': [6.1, 6.4] } * // => { '4': [4.2], '6': [6.1, 6.4] }
* *
* // using the `_.property` callback shorthand * // using the `_.property` callback shorthand

View File

@@ -36,10 +36,14 @@ define(['../internal/createAggregator'], function(createAggregator) {
* _.indexBy(keyData, 'dir'); * _.indexBy(keyData, 'dir');
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
* *
* _.indexBy(keyData, function(object) { return String.fromCharCode(object.code); }); * _.indexBy(keyData, function(object) {
* return String.fromCharCode(object.code);
* });
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
* *
* _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, String); * _.indexBy(keyData, function(object) {
* return this.fromCharCode(object.code);
* }, String);
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*/ */
var indexBy = createAggregator(function(result, value, key) { var indexBy = createAggregator(function(result, value, key) {

View File

@@ -37,11 +37,15 @@ define(['../internal/arrayMap', '../internal/baseCallback', '../internal/baseMap
* @returns {Array} Returns the new mapped array. * @returns {Array} Returns the new mapped array.
* @example * @example
* *
* _.map([1, 2, 3], function(n) { return n * 3; }); * function timesThree(n) {
* // => [3, 6, 9] * return n * 3;
* }
* *
* _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; }); * _.map([1, 2], timesThree);
* // => [3, 6, 9] (iteration order is not guaranteed) * // => [3, 6]
*
* _.map({ 'a': 1, 'b': 2 }, timesThree);
* // => [3, 6] (iteration order is not guaranteed)
* *
* var users = [ * var users = [
* { 'user': 'barney' }, * { 'user': 'barney' },

View File

@@ -38,7 +38,9 @@ define(['../internal/arrayMax', '../internal/createExtremum'], function(arrayMax
* { 'user': 'fred', 'age': 40 } * { 'user': 'fred', 'age': 40 }
* ]; * ];
* *
* _.max(users, function(chr) { return chr.age; }); * _.max(users, function(chr) {
* return chr.age;
* });
* // => { 'user': 'fred', 'age': 40 }; * // => { 'user': 'fred', 'age': 40 };
* *
* // using the `_.property` callback shorthand * // using the `_.property` callback shorthand

View File

@@ -38,7 +38,9 @@ define(['../internal/arrayMin', '../internal/createExtremum'], function(arrayMin
* { 'user': 'fred', 'age': 40 } * { 'user': 'fred', 'age': 40 }
* ]; * ];
* *
* _.min(users, function(chr) { return chr.age; }); * _.min(users, function(chr) {
* return chr.age;
* });
* // => { 'user': 'barney', 'age': 36 }; * // => { 'user': 'barney', 'age': 36 };
* *
* // using the `_.property` callback shorthand * // using the `_.property` callback shorthand

View File

@@ -27,10 +27,14 @@ define(['../internal/createAggregator'], function(createAggregator) {
* @returns {Array} Returns the array of grouped elements. * @returns {Array} Returns the array of grouped elements.
* @example * @example
* *
* _.partition([1, 2, 3], function(n) { return n % 2; }); * _.partition([1, 2, 3], function(n) {
* return n % 2;
* });
* // => [[1, 3], [2]] * // => [[1, 3], [2]]
* *
* _.partition([1.2, 2.3, 3.4], function(n) { return this.floor(n) % 2; }, Math); * _.partition([1.2, 2.3, 3.4], function(n) {
* return this.floor(n) % 2;
* }, Math);
* // => [[1, 3], [2]] * // => [[1, 3], [2]]
* *
* var users = [ * var users = [
@@ -39,7 +43,9 @@ define(['../internal/createAggregator'], function(createAggregator) {
* { 'user': 'pebbles', 'age': 1, 'active': false } * { '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 * // using the `_.matches` callback shorthand
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper); * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);

View File

@@ -25,14 +25,16 @@ define(['../internal/arrayReduce', '../internal/baseCallback', '../internal/base
* @returns {*} Returns the accumulated value. * @returns {*} Returns the accumulated value.
* @example * @example
* *
* var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; }); * _.reduce([1, 2], function(sum, n) {
* // => 6 * return sum + n;
* });
* // => 3
* *
* var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) { * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
* result[key] = n * 3; * result[key] = n * 3;
* return result; * return result;
* }, {}); * }, {});
* // => { 'a': 3, 'b': 6, 'c': 9 } (iteration order is not guaranteed) * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
*/ */
function reduce(collection, iteratee, accumulator, thisArg) { function reduce(collection, iteratee, accumulator, thisArg) {
var func = isArray(collection) ? arrayReduce : baseReduce; var func = isArray(collection) ? arrayReduce : baseReduce;

View File

@@ -16,7 +16,10 @@ define(['../internal/arrayReduceRight', '../internal/baseCallback', '../internal
* @example * @example
* *
* var array = [[0, 1], [2, 3], [4, 5]]; * var array = [[0, 1], [2, 3], [4, 5]];
* _.reduceRight(array, function(flattened, other) { return flattened.concat(other); }, []); *
* _.reduceRight(array, function(flattened, other) {
* return flattened.concat(other);
* }, []);
* // => [4, 5, 2, 3, 0, 1] * // => [4, 5, 2, 3, 0, 1]
*/ */
function reduceRight(collection, iteratee, accumulator, thisArg) { function reduceRight(collection, iteratee, accumulator, thisArg) {

View File

@@ -25,7 +25,9 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base
* @returns {Array} Returns the new filtered array. * @returns {Array} Returns the new filtered array.
* @example * @example
* *
* var odds = _.reject([1, 2, 3, 4], function(n) { return n % 2 == 0; }); * _.reject([1, 2, 3, 4], function(n) {
* return n % 2 == 0;
* });
* // => [1, 3] * // => [1, 3]
* *
* var users = [ * var users = [

View File

@@ -11,12 +11,12 @@ define(['../internal/isLength', '../object/keys'], function(isLength, keys) {
* @returns {number} Returns the size of `collection`. * @returns {number} Returns the size of `collection`.
* @example * @example
* *
* _.size([1, 2]); * _.size([1, 2, 3]);
* // => 2
*
* _.size({ 'one': 1, 'two': 2, 'three': 3 });
* // => 3 * // => 3
* *
* _.size({ 'a': 1, 'b': 2 });
* // => 2
*
* _.size('pebbles'); * _.size('pebbles');
* // => 7 * // => 7
*/ */

View File

@@ -38,7 +38,7 @@ define(['../internal/arraySome', '../internal/baseCallback', '../internal/baseSo
* ]; * ];
* *
* // using the `_.matches` callback shorthand * // using the `_.matches` callback shorthand
* _.some(users, { user': 'barney', 'active': false }); * _.some(users, { 'user': 'barney', 'active': false });
* // => false * // => false
* *
* // using the `_.matchesProperty` callback shorthand * // using the `_.matchesProperty` callback shorthand

View File

@@ -29,10 +29,14 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseSor
* @returns {Array} Returns the new sorted array. * @returns {Array} Returns the new sorted array.
* @example * @example
* *
* _.sortBy([1, 2, 3], function(n) { return Math.sin(n); }); * _.sortBy([1, 2, 3], function(n) {
* return Math.sin(n);
* });
* // => [3, 1, 2] * // => [3, 1, 2]
* *
* _.sortBy([1, 2, 3], function(n) { return this.sin(n); }, Math); * _.sortBy([1, 2, 3], function(n) {
* return this.sin(n);
* }, Math);
* // => [3, 1, 2] * // => [3, 1, 2]
* *
* var users = [ * var users = [

View File

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

View File

@@ -19,7 +19,9 @@ define(['../internal/baseBindAll', '../internal/baseFlatten', '../object/functio
* *
* var view = { * var view = {
* 'label': 'docs', * 'label': 'docs',
* 'onClick': function() { console.log('clicked ' + this.label); } * 'onClick': function() {
* console.log('clicked ' + this.label);
* }
* }; * };
* *
* _.bindAll(view); * _.bindAll(view);

View File

@@ -28,7 +28,7 @@ define(['../lang/isObject', '../date/now'], function(isObject, now) {
* @memberOf _ * @memberOf _
* @category Function * @category Function
* @param {Function} func The function to debounce. * @param {Function} func The function to debounce.
* @param {number} wait The number of milliseconds to delay. * @param {number} [wait=0] The number of milliseconds to delay.
* @param {Object} [options] The options object. * @param {Object} [options] The options object.
* @param {boolean} [options.leading=false] Specify invoking on the leading * @param {boolean} [options.leading=false] Specify invoking on the leading
* edge of the timeout. * edge of the timeout.
@@ -86,7 +86,7 @@ define(['../lang/isObject', '../date/now'], function(isObject, now) {
if (typeof func != 'function') { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
wait = wait < 0 ? 0 : wait; wait = wait < 0 ? 0 : (+wait || 0);
if (options === true) { if (options === true) {
var leading = true; var leading = true;
trailing = false; trailing = false;

View File

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

View File

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

View File

@@ -1,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. */ /** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function'; var FUNC_ERROR_TEXT = 'Expected a function';
@@ -34,7 +34,7 @@ define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, is
if (!length) { if (!length) {
return function() { return arguments[0]; }; return function() { return arguments[0]; };
} }
if (!arrayEvery(funcs, isFunction)) { if (!arrayEvery(funcs, baseIsFunction)) {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
return function() { return function() {

View File

@@ -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. */ /** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function'; var FUNC_ERROR_TEXT = 'Expected a function';
@@ -34,7 +34,7 @@ define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, is
if (fromIndex < 0) { if (fromIndex < 0) {
return function() { return arguments[0]; }; return function() { return arguments[0]; };
} }
if (!arrayEvery(funcs, isFunction)) { if (!arrayEvery(funcs, baseIsFunction)) {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
return function() { return function() {

View File

@@ -26,7 +26,9 @@ define(['../internal/baseFlatten', '../internal/createWrapper'], function(baseFl
* // => ['a', 'b', 'c'] * // => ['a', 'b', 'c']
* *
* var map = _.rearg(_.map, [1, 0]); * var map = _.rearg(_.map, [1, 0]);
* map(function(n) { return n * 3; }, [1, 2, 3]); * map(function(n) {
* return n * 3;
* }, [1, 2, 3]);
* // => [3, 6, 9] * // => [3, 6, 9]
*/ */
function rearg(func) { function rearg(func) {

View File

@@ -29,7 +29,7 @@ define(['./debounce', '../lang/isObject'], function(debounce, isObject) {
* @memberOf _ * @memberOf _
* @category Function * @category Function
* @param {Function} func The function to throttle. * @param {Function} func The function to throttle.
* @param {number} wait The number of milliseconds to throttle invocations to. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
* @param {Object} [options] The options object. * @param {Object} [options] The options object.
* @param {boolean} [options.leading=true] Specify invoking on the leading * @param {boolean} [options.leading=true] Specify invoking on the leading
* edge of the timeout. * edge of the timeout.
@@ -42,8 +42,9 @@ define(['./debounce', '../lang/isObject'], function(debounce, isObject) {
* jQuery(window).on('scroll', _.throttle(updatePosition, 100)); * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
* *
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false }) * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
* jQuery('.interactive').on('click', throttled); * 'trailing': false
* }));
* *
* // cancel a trailing throttled call * // cancel a trailing throttled call
* jQuery(window).on('popstate', throttled.cancel); * jQuery(window).on('popstate', throttled.cancel);

View File

@@ -1,4 +1,4 @@
define([], function() { define(['./baseCreate', './baseLodash'], function(baseCreate, baseLodash) {
/** Used as references for `-Infinity` and `Infinity`. */ /** Used as references for `-Infinity` and `Infinity`. */
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY; var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
@@ -20,5 +20,8 @@ define([], function() {
this.__views__ = null; this.__views__ = null;
} }
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
return LazyWrapper; return LazyWrapper;
}); });

View File

@@ -1,4 +1,4 @@
define([], function() { define(['./baseCreate', './baseLodash'], function(baseCreate, baseLodash) {
/** /**
* The base constructor for creating `lodash` wrapper objects. * The base constructor for creating `lodash` wrapper objects.
@@ -14,5 +14,8 @@ define([], function() {
this.__chain__ = !!chainAll; this.__chain__ = !!chainAll;
} }
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
LodashWrapper.prototype.constructor = LodashWrapper;
return LodashWrapper; return LodashWrapper;
}); });

View File

@@ -19,7 +19,7 @@ define(['./baseIndexOf', './cacheIndexOf', './createCache'], function(baseIndexO
var index = -1, var index = -1,
indexOf = baseIndexOf, indexOf = baseIndexOf,
isCommon = true, isCommon = true,
cache = isCommon && values.length >= 200 && createCache(values), cache = (isCommon && values.length >= 200) ? createCache(values) : null,
valuesLength = values.length; valuesLength = values.length;
if (cache) { if (cache) {

View File

@@ -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;
});

13
internal/baseLodash.js Normal file
View File

@@ -0,0 +1,13 @@
define([], function() {
/**
* The function whose prototype all chaining wrappers inherit from.
*
* @private
*/
function baseLodash() {
// No operation performed.
}
return baseLodash;
});

View File

@@ -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. */ /** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined; var undefined;
@@ -16,8 +16,10 @@ define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './
* @returns {Object} Returns the destination object. * @returns {Object} Returns the destination object.
*/ */
function baseMerge(object, source, customizer, stackA, stackB) { function baseMerge(object, source, customizer, stackA, stackB) {
if (!isObject(object)) {
return object;
}
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source)); var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) { (isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
if (isObjectLike(srcValue)) { if (isObjectLike(srcValue)) {
stackA || (stackA = []); stackA || (stackA = []);

View File

@@ -15,7 +15,7 @@ define(['./baseIndexOf', './cacheIndexOf', './createCache'], function(baseIndexO
length = array.length, length = array.length,
isCommon = true, isCommon = true,
isLarge = isCommon && length >= 200, isLarge = isCommon && length >= 200,
seen = isLarge && createCache(), seen = isLarge ? createCache() : null,
result = []; result = [];
if (seen) { if (seen) {

View File

@@ -20,7 +20,11 @@ define(['./isIndex', './isLength', '../lang/isObject'], function(isIndex, isLeng
} else { } else {
prereq = type == 'string' && index in object; prereq = type == 'string' && index in object;
} }
return prereq && object[index] === value; if (prereq) {
var other = object[index];
return value === value ? value === other : other !== other;
}
return false;
} }
return isIterateeCall; return isIterateeCall;

View File

@@ -38,22 +38,26 @@ define(['../internal/baseClone', '../internal/bindCallback', '../internal/isIter
* // => false * // => false
* *
* // using a customizer callback * // using a customizer callback
* var body = _.clone(document.body, function(value) { * var el = _.clone(document.body, function(value) {
* return _.isElement(value) ? value.cloneNode(false) : undefined; * if (_.isElement(value)) {
* return value.cloneNode(false);
* }
* }); * });
* *
* body === document.body * el === document.body
* // => false * // => false
* body.nodeName * el.nodeName
* // => BODY * // => BODY
* body.childNodes.length; * el.childNodes.length;
* // => 0 * // => 0
*/ */
function clone(value, isDeep, customizer, thisArg) { function clone(value, isDeep, customizer, thisArg) {
// Juggle arguments. if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
if (typeof isDeep != 'boolean' && isDeep != null) { isDeep = false;
}
else if (typeof isDeep == 'function') {
thisArg = customizer; thisArg = customizer;
customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep; customizer = isDeep;
isDeep = false; isDeep = false;
} }
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1); customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);

View File

@@ -33,14 +33,16 @@ define(['../internal/baseClone', '../internal/bindCallback'], function(baseClone
* *
* // using a customizer callback * // using a customizer callback
* var el = _.cloneDeep(document.body, function(value) { * 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 * // => false
* body.nodeName * el.nodeName
* // => BODY * // => BODY
* body.childNodes.length; * el.childNodes.length;
* // => 20 * // => 20
*/ */
function cloneDeep(value, customizer, thisArg) { function cloneDeep(value, customizer, thisArg) {

View File

@@ -26,7 +26,7 @@ define(['../internal/isLength', '../internal/isObjectLike'], function(isLength,
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example * @example
* *
* (function() { return _.isArguments(arguments); })(); * _.isArguments(function() { return arguments; }());
* // => true * // => true
* *
* _.isArguments([1, 2, 3]); * _.isArguments([1, 2, 3]);

View File

@@ -29,7 +29,7 @@ define(['../internal/isLength', './isNative', '../internal/isObjectLike'], funct
* _.isArray([1, 2, 3]); * _.isArray([1, 2, 3]);
* // => true * // => true
* *
* (function() { return _.isArray(arguments); })(); * _.isArray(function() { return arguments; }());
* // => false * // => false
*/ */
var isArray = nativeIsArray || function(value) { var isArray = nativeIsArray || function(value) {

View File

@@ -40,7 +40,9 @@ define(['../internal/baseIsEqual', '../internal/bindCallback', '../internal/isSt
* var other = ['hi', 'goodbye']; * var other = ['hi', 'goodbye'];
* *
* _.isEqual(array, other, function(value, other) { * _.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 * // => true
*/ */

View File

@@ -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. */ /** `Object#toString` result references. */
var funcTag = '[object Function]'; var funcTag = '[object Function]';
@@ -32,20 +32,12 @@ define(['./isNative', '../internal/root'], function(isNative, root) {
* _.isFunction(/abc/); * _.isFunction(/abc/);
* // => false * // => false
*/ */
function isFunction(value) { var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
// Avoid a Chakra JIT bug in compatibility modes of IE 11. // The use of `Object#toString` avoids issues with the `typeof` operator
// See https://github.com/jashkenas/underscore/issues/1621 for more details. // in older versions of Chrome and Safari which return 'function' for regexes
return typeof value == 'function' || false; // and Safari 8 equivalents which return 'object' for typed array constructors.
} return objToString.call(value) == funcTag;
// 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;
};
}
return isFunction; return isFunction;
}); });

View File

@@ -10,7 +10,9 @@ define(['../internal/arrayCopy', '../internal/isLength', '../object/values'], fu
* @returns {Array} Returns the converted array. * @returns {Array} Returns the converted array.
* @example * @example
* *
* (function() { return _.toArray(arguments).slice(1); })(1, 2, 3); * (function() {
* return _.toArray(arguments).slice(1);
* }(1, 2, 3));
* // => [2, 3] * // => [2, 3]
*/ */
function toArray(value) { function toArray(value) {

691
main.js

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
define(['./number/random'], function(random) { define(['./number/inRange', './number/random'], function(inRange, random) {
return { return {
'inRange': inRange,
'random': random 'random': random
}; };
}); });

46
number/inRange.js Normal file
View File

@@ -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;
});

View File

@@ -23,7 +23,9 @@ define(['../internal/baseCopy', '../internal/baseCreate', '../internal/isIterate
* Shape.call(this); * Shape.call(this);
* } * }
* *
* Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle }); * Circle.prototype = _.create(Shape.prototype, {
* 'constructor': Circle
* });
* *
* var circle = new Circle; * var circle = new Circle;
* circle instanceof Circle; * circle instanceof Circle;

View File

@@ -31,7 +31,9 @@ define(['../internal/baseCallback', '../internal/baseFind', '../internal/baseFor
* 'pebbles': { 'age': 1, 'active': true } * '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) * // => 'barney' (iteration order is not guaranteed)
* *
* // using the `_.matches` callback shorthand * // using the `_.matches` callback shorthand

View File

@@ -31,7 +31,9 @@ define(['../internal/baseCallback', '../internal/baseFind', '../internal/baseFor
* 'pebbles': { 'age': 1, 'active': true } * '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` * // => returns `pebbles` assuming `_.findKey` returns `barney`
* *
* // using the `_.matches` callback shorthand * // using the `_.matches` callback shorthand

View File

@@ -15,10 +15,17 @@ define(['../internal/baseForOwn', '../internal/bindCallback'], function(baseForO
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
* @example * @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); * 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) { function forOwn(object, iteratee, thisArg) {
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') { if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {

View File

@@ -13,10 +13,17 @@ define(['../internal/baseForRight', '../internal/bindCallback', './keys'], funct
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
* @example * @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); * 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) { function forOwnRight(object, iteratee, thisArg) {
iteratee = bindCallback(iteratee, thisArg, 3); iteratee = bindCallback(iteratee, thisArg, 3);

View File

@@ -13,7 +13,7 @@ define(['../internal/baseFunctions', './keysIn'], function(baseFunctions, keysIn
* @example * @example
* *
* _.functions(_); * _.functions(_);
* // => ['all', 'any', 'bind', ...] * // => ['after', 'ary', 'assign', ...]
*/ */
function functions(object) { function functions(object) {
return baseFunctions(object, keysIn(object)); return baseFunctions(object, keysIn(object));

View File

@@ -18,7 +18,9 @@ define([], function() {
* @returns {boolean} Returns `true` if `key` is a direct property, else `false`. * @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
* @example * @example
* *
* _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); * var object = { 'a': 1, 'b': 2, 'c': 3 };
*
* _.has(object, 'b');
* // => true * // => true
*/ */
function has(object, key) { function has(object, key) {

View File

@@ -20,16 +20,14 @@ define(['../internal/isIterateeCall', './keys'], function(isIterateeCall, keys)
* @returns {Object} Returns the new inverted object. * @returns {Object} Returns the new inverted object.
* @example * @example
* *
* _.invert({ 'first': 'fred', 'second': 'barney' }); * var object = { 'a': 1, 'b': 2, 'c': 1 };
* // => { 'fred': 'first', 'barney': 'second' }
* *
* // without `multiValue` * _.invert(object);
* _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }); * // => { '1': 'c', '2': 'b' }
* // => { 'fred': 'third', 'barney': 'second' }
* *
* // with `multiValue` * // with `multiValue`
* _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }, true); * _.invert(object, true);
* // => { 'fred': ['first', 'third'], 'barney': ['second'] } * // => { '1': ['a', 'c'], '2': ['b'] }
*/ */
function invert(object, multiValue, guard) { function invert(object, multiValue, guard) {
if (guard && isIterateeCall(object, multiValue, guard)) { if (guard && isIterateeCall(object, multiValue, guard)) {

View File

@@ -27,8 +27,10 @@ define(['../internal/baseCallback', '../internal/baseForOwn'], function(baseCall
* @returns {Object} Returns the new mapped object. * @returns {Object} Returns the new mapped object.
* @example * @example
* *
* _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(n) { return n * 3; }); * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
* // => { 'a': 3, 'b': 6, 'c': 9 } * return n * 3;
* });
* // => { 'a': 3, 'b': 6 }
* *
* var users = { * var users = {
* 'fred': { 'user': 'fred', 'age': 40 }, * 'fred': { 'user': 'fred', 'age': 40 },

View File

@@ -42,7 +42,9 @@ define(['../internal/baseMerge', '../internal/createAssigner'], function(baseMer
* }; * };
* *
* _.merge(object, other, function(a, b) { * _.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'] } * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
*/ */

View File

@@ -18,18 +18,16 @@ define(['../internal/arrayEach', '../internal/baseCallback', '../internal/baseCr
* @returns {*} Returns the accumulated value. * @returns {*} Returns the accumulated value.
* @example * @example
* *
* var squares = _.transform([1, 2, 3, 4, 5, 6], function(result, n) { * _.transform([2, 3, 4], function(result, n) {
* n *= n; * result.push(n *= n);
* if (n % 2) { * return n % 2 == 0;
* return result.push(n) < 3;
* }
* }); * });
* // => [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; * result[key] = n * 3;
* }); * });
* // => { 'a': 3, 'b': 6, 'c': 9 } * // => { 'a': 3, 'b': 6 }
*/ */
function transform(object, iteratee, accumulator, thisArg) { function transform(object, iteratee, accumulator, thisArg) {
var isArr = isArray(object) || isTypedArray(object); var isArr = isArray(object) || isTypedArray(object);

View File

@@ -1,6 +1,6 @@
{ {
"name": "lodash", "name": "lodash",
"version": "3.2.0", "version": "3.3.1",
"main": "main.js", "main": "main.js",
"private": true, "private": true,
"volo": { "volo": {

View File

@@ -1,7 +1,7 @@
define(['../internal/createCompounder'], function(createCompounder) { 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 * See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for
* more details. * more details.
* *

View File

@@ -104,10 +104,10 @@ define(['../internal/assignOwnDefaults', '../utility/attempt', '../internal/base
* var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
* compiled.source; * compiled.source;
* // => function(data) { * // => function(data) {
* var __t, __p = ''; * // var __t, __p = '';
* __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!'; * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
* return __p; * // return __p;
* } * // }
* *
* // using the `source` property to inline compiled templates for meaningful * // using the `source` property to inline compiled templates for meaningful
* // line numbers in error messages and a stack trace * // line numbers in error messages and a stack trace

View File

@@ -30,13 +30,21 @@ define(['../internal/baseToString', '../internal/isIterateeCall', '../lang/isObj
* _.trunc('hi-diddly-ho there, neighborino', 24); * _.trunc('hi-diddly-ho there, neighborino', 24);
* // => 'hi-diddly-ho there, n...' * // => '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,...' * // => '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...' * //=> 'hi-diddly-ho there...'
* *
* _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' }); * _.trunc('hi-diddly-ho there, neighborino', {
* 'omission': ' [...]'
* });
* // => 'hi-diddly-ho there, neig [...]' * // => 'hi-diddly-ho there, neig [...]'
*/ */
function trunc(string, options, guard) { function trunc(string, options, guard) {

View File

@@ -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. */ /** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined; var undefined;
@@ -23,9 +23,16 @@ define(['../internal/baseSlice', '../lang/isError'], function(baseSlice, isError
* elements = []; * elements = [];
* } * }
*/ */
function attempt(func) { function attempt() {
var length = arguments.length,
func = arguments[0];
try { 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) { } catch(e) {
return isError(e) ? e : new Error(e); return isError(e) ? e : new Error(e);
} }

View File

@@ -29,7 +29,9 @@ define(['../internal/baseCallback', '../internal/isIterateeCall', '../internal/i
* return callback(func, thisArg); * return callback(func, thisArg);
* } * }
* return function(object) { * 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];
* }; * };
* }); * });
* *

View File

@@ -12,6 +12,7 @@ define([], function() {
* *
* var object = { 'user': 'fred' }; * var object = { 'user': 'fred' };
* var getter = _.constant(object); * var getter = _.constant(object);
*
* getter() === object; * getter() === object;
* // => true * // => true
*/ */

View File

@@ -11,6 +11,7 @@ define([], function() {
* @example * @example
* *
* var object = { 'user': 'fred' }; * var object = { 'user': 'fred' };
*
* _.identity(object) === object; * _.identity(object) === object;
* // => true * // => true
*/ */

View File

@@ -1,7 +1,8 @@
define([], function() { define([], function() {
/** /**
* A no-operation function. * A no-operation function which returns `undefined` regardless of the
* arguments it receives.
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -9,6 +10,7 @@ define([], function() {
* @example * @example
* *
* var object = { 'user': 'fred' }; * var object = { 'user': 'fred' };
*
* _.noop(object) === undefined; * _.noop(object) === undefined;
* // => true * // => true
*/ */

View File

@@ -14,11 +14,11 @@ define([], function() {
* @returns {Function} Returns the new function. * @returns {Function} Returns the new function.
* @example * @example
* *
* var object = { 'user': 'fred', 'age': 40, 'active': true };
* _.map(['active', 'user'], _.propertyOf(object));
* // => [true, 'fred']
*
* var object = { 'a': 3, 'b': 1, 'c': 2 }; * var object = { 'a': 3, 'b': 1, 'c': 2 };
*
* _.map(['a', 'c'], _.propertyOf(object));
* // => [3, 2]
*
* _.sortBy(['a', 'b', 'c'], _.propertyOf(object)); * _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
* // => ['b', 'c', 'a'] * // => ['b', 'c', 'a']
*/ */

View File

@@ -8,8 +8,9 @@ define(['../internal/isIterateeCall'], function(isIterateeCall) {
/** /**
* Creates an array of numbers (positive and/or negative) progressing from * 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 * `start` up to, but not including, `end`. If `end` is not specified it
* zero-length range is created unless a negative `step` is specified. * 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 * @static
* @memberOf _ * @memberOf _

View File

@@ -24,10 +24,14 @@ define(['../internal/bindCallback', '../internal/root'], function(bindCallback,
* var diceRolls = _.times(3, _.partial(_.random, 1, 6, false)); * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
* // => [3, 6, 4] * // => [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 * // => 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 * // => also invokes `mage.castSpell(n)` three times
*/ */
function times(n, iteratee, thisArg) { function times(n, iteratee, thisArg) {