Compare commits

..

3 Commits

Author SHA1 Message Date
John-David Dalton
707fe171fc Bump to v3.5.0. 2015-12-16 17:48:35 -08:00
John-David Dalton
4ce1d5ddd3 Bump to v3.4.0. 2015-12-16 17:48:03 -08:00
John-David Dalton
7a82a3d77b Bump to v3.3.1. 2015-12-16 17:47:30 -08:00
73 changed files with 1071 additions and 695 deletions

View File

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

View File

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

View File

@@ -21,16 +21,17 @@ define(['../internal/baseDifference', '../internal/baseFlatten', '../lang/isArgu
* // => [1, 3]
*/
function difference() {
var index = -1,
length = arguments.length;
var args = arguments,
index = -1,
length = args.length;
while (++index < length) {
var value = arguments[index];
var value = args[index];
if (isArray(value) || isArguments(value)) {
break;
}
}
return baseDifference(value, baseFlatten(arguments, false, true, ++index));
return baseDifference(value, baseFlatten(args, false, true, ++index));
}
return difference;

View File

@@ -38,7 +38,7 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb
* ];
*
* // using the `_.matches` callback shorthand
* _.pluck(_.dropRightWhile(users, { 'user': pebbles, 'active': false }), 'user');
* _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
* // => ['barney', 'fred']
*
* // using the `_.matchesProperty` callback shorthand

View File

@@ -37,12 +37,12 @@ define(['../internal/baseCallback'], function(baseCallback) {
* // => 2
*
* // using the `_.matches` callback shorthand
* _.findLastIndex(users, { user': 'barney', 'active': true });
* _.findLastIndex(users, { 'user': 'barney', 'active': true });
* // => 0
*
* // using the `_.matchesProperty` callback shorthand
* _.findLastIndex(users, 'active', false);
* // => 1
* // => 2
*
* // using the `_.property` callback shorthand
* _.findLastIndex(users, 'active');

View File

@@ -25,7 +25,7 @@ define(['../internal/baseFlatten', '../internal/isIterateeCall'], function(baseF
if (guard && isIterateeCall(array, isDeep, guard)) {
isDeep = false;
}
return length ? baseFlatten(array, isDeep) : [];
return length ? baseFlatten(array, isDeep, false, 0) : [];
}
return flatten;

View File

@@ -15,7 +15,7 @@ define(['../internal/baseFlatten'], function(baseFlatten) {
*/
function flattenDeep(array) {
var length = array ? array.length : 0;
return length ? baseFlatten(array, true) : [];
return length ? baseFlatten(array, true, false, 0) : [];
}
return flattenDeep;

View File

@@ -25,7 +25,7 @@ define(['../internal/baseIndexOf', '../internal/binaryIndex'], function(baseInde
* @example
*
* _.indexOf([1, 2, 1, 2], 2);
* // => 2
* // => 1
*
* // using `fromIndex`
* _.indexOf([1, 2, 1, 2], 2, 2);
@@ -41,14 +41,17 @@ define(['../internal/baseIndexOf', '../internal/binaryIndex'], function(baseInde
return -1;
}
if (typeof fromIndex == 'number') {
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
} else if (fromIndex) {
var index = binaryIndex(array, value),
other = array[index];
return (value === value ? value === other : other !== other) ? index : -1;
if (value === value ? (value === other) : (other !== other)) {
return index;
}
return -1;
}
return baseIndexOf(array, value, fromIndex);
return baseIndexOf(array, value, fromIndex || 0);
}
return indexOf;

View File

@@ -30,7 +30,7 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea
var value = arguments[argsIndex];
if (isArray(value) || isArguments(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;
@@ -43,11 +43,11 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea
outer:
while (++index < length) {
value = array[index];
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value)) < 0) {
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
argsIndex = argsLength;
while (--argsIndex) {
var cache = caches[argsIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value)) < 0) {
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value, 0)) < 0) {
continue outer;
}
}

View File

@@ -40,7 +40,10 @@ define(['../internal/binaryIndex', '../internal/indexOfNaN'], function(binaryInd
} else if (fromIndex) {
index = binaryIndex(array, value, true) - 1;
var other = array[index];
return (value === value ? value === other : other !== other) ? index : -1;
if (value === value ? (value === other) : (other !== other)) {
return index;
}
return -1;
}
if (value !== value) {
return indexOfNaN(array, index, true);

View File

@@ -31,17 +31,19 @@ define(['../internal/baseIndexOf'], function(baseIndexOf) {
* // => [1, 1]
*/
function pull() {
var array = arguments[0];
var args = arguments,
array = args[0];
if (!(array && array.length)) {
return array;
}
var index = 0,
indexOf = baseIndexOf,
length = arguments.length;
length = args.length;
while (++index < length) {
var fromIndex = 0,
value = arguments[index];
value = args[index];
while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
splice.call(array, fromIndex, 1);

View File

@@ -20,7 +20,7 @@ define(['../internal/baseFlatten', '../internal/baseUniq'], function(baseFlatten
* // => [1, 2, 4]
*/
function union() {
return baseUniq(baseFlatten(arguments, false, true));
return baseUniq(baseFlatten(arguments, false, true, 0));
}
return union;

View File

@@ -22,9 +22,14 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../internal/bas
* Chaining is supported in custom builds as long as the `_#value` method is
* directly or indirectly included in the build.
*
* In addition to lodash methods, wrappers also have the following `Array` methods:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
* and `unshift`
* In addition to lodash methods, wrappers have `Array` and `String` methods.
*
* The wrapper `Array` methods are:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
* `splice`, and `unshift`
*
* The wrapper `String` methods are:
* `replace` and `split`
*
* The wrapper methods that support shortcut fusion are:
* `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
@@ -44,26 +49,26 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../internal/bas
* `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `splice`, `spread`,
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
* `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
* `unshift`, `unzip`, `values`, `valuesIn`, `where`, `without`, `wrap`, `xor`,
* `zip`, and `zipObject`
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
* `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
* `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
* `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
* `without`, `wrap`, `xor`, `zip`, and `zipObject`
*
* The wrapper methods that are **not** chainable by default are:
* `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
* `add`, `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
* `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`,
* `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`,
* `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
* `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
* `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
* `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`,
* `trunc`, `unescape`, `uniqueId`, `value`, and `words`
* `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
* `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
*
* The wrapper method `sample` will return a wrapped value when `n` is provided,
* otherwise an unwrapped value is returned.

View File

@@ -1,4 +1,4 @@
define(['./collection/all', './collection/any', './collection/at', './collection/collect', './collection/contains', './collection/countBy', './collection/detect', './collection/each', './collection/eachRight', './collection/every', './collection/filter', './collection/find', './collection/findLast', './collection/findWhere', './collection/foldl', './collection/foldr', './collection/forEach', './collection/forEachRight', './collection/groupBy', './collection/include', './collection/includes', './collection/indexBy', './collection/inject', './collection/invoke', './collection/map', './collection/max', './collection/min', './collection/partition', './collection/pluck', './collection/reduce', './collection/reduceRight', './collection/reject', './collection/sample', './collection/select', './collection/shuffle', './collection/size', './collection/some', './collection/sortBy', './collection/sortByAll', './collection/where'], function(all, any, at, collect, contains, countBy, detect, each, eachRight, every, filter, find, findLast, findWhere, foldl, foldr, forEach, forEachRight, groupBy, include, includes, indexBy, inject, invoke, map, max, min, partition, pluck, reduce, reduceRight, reject, sample, select, shuffle, size, some, sortBy, sortByAll, where) {
define(['./collection/all', './collection/any', './collection/at', './collection/collect', './collection/contains', './collection/countBy', './collection/detect', './collection/each', './collection/eachRight', './collection/every', './collection/filter', './collection/find', './collection/findLast', './collection/findWhere', './collection/foldl', './collection/foldr', './collection/forEach', './collection/forEachRight', './collection/groupBy', './collection/include', './collection/includes', './collection/indexBy', './collection/inject', './collection/invoke', './collection/map', './math/max', './math/min', './collection/partition', './collection/pluck', './collection/reduce', './collection/reduceRight', './collection/reject', './collection/sample', './collection/select', './collection/shuffle', './collection/size', './collection/some', './collection/sortBy', './collection/sortByAll', './collection/sortByOrder', './math/sum', './collection/where'], function(all, any, at, collect, contains, countBy, detect, each, eachRight, every, filter, find, findLast, findWhere, foldl, foldr, forEach, forEachRight, groupBy, include, includes, indexBy, inject, invoke, map, max, min, partition, pluck, reduce, reduceRight, reject, sample, select, shuffle, size, some, sortBy, sortByAll, sortByOrder, sum, where) {
return {
'all': all,
'any': any,
@@ -39,6 +39,8 @@ define(['./collection/all', './collection/any', './collection/at', './collection
'some': some,
'sortBy': sortBy,
'sortByAll': sortByAll,
'sortByOrder': sortByOrder,
'sum': sum,
'where': where
};
});

View File

@@ -1,53 +1,3 @@
define(['../internal/arrayMax', '../internal/createExtremum'], function(arrayMax, createExtremum) {
/**
* Gets the maximum value of `collection`. If `collection` is empty or falsey
* `-Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* arguments; (value, index, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the maximum value.
* @example
*
* _.max([4, 2, 8, 6]);
* // => 8
*
* _.max([]);
* // => -Infinity
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* _.max(users, function(chr) {
* return chr.age;
* });
* // => { 'user': 'fred', 'age': 40 };
*
* // using the `_.property` callback shorthand
* _.max(users, 'age');
* // => { 'user': 'fred', 'age': 40 };
*/
var max = createExtremum(arrayMax);
define(["../math/max"], function(max) {
return max;
});

View File

@@ -1,53 +1,3 @@
define(['../internal/arrayMin', '../internal/createExtremum'], function(arrayMin, createExtremum) {
/**
* Gets the minimum value of `collection`. If `collection` is empty or falsey
* `Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* arguments; (value, index, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Collection
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the minimum value.
* @example
*
* _.min([4, 2, 8, 6]);
* // => 2
*
* _.min([]);
* // => Infinity
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* _.min(users, function(chr) {
* return chr.age;
* });
* // => { 'user': 'barney', 'age': 36 };
*
* // using the `_.property` callback shorthand
* _.min(users, 'age');
* // => { 'user': 'barney', 'age': 36 };
*/
var min = createExtremum(arrayMin, true);
define(["../math/min"], function(min) {
return min;
});

View File

@@ -35,7 +35,7 @@ define(['../internal/createAggregator'], function(createAggregator) {
* _.partition([1.2, 2.3, 3.4], function(n) {
* return this.floor(n) % 2;
* }, Math);
* // => [[1, 3], [2]]
* // => [[1.2, 3.4], [2.3]]
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': false },

View File

@@ -1,8 +1,8 @@
define(['../internal/isLength', '../object/keys'], function(isLength, keys) {
/**
* Gets the size of `collection` by returning `collection.length` for
* array-like values or the number of own enumerable properties for objects.
* Gets the size of `collection` by returning its length for array-like
* values or the number of own enumerable properties for objects.
*
* @static
* @memberOf _

View File

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

View File

@@ -50,8 +50,11 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseSor
* // => ['barney', 'fred', 'pebbles']
*/
function sortBy(collection, iteratee, thisArg) {
if (collection == null) {
return [];
}
var index = -1,
length = collection ? collection.length : 0,
length = collection.length,
result = isLength(length) ? Array(length) : [];
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {

View File

@@ -1,7 +1,4 @@
define(['../internal/baseEach', '../internal/baseFlatten', '../internal/baseSortBy', '../internal/compareMultipleAscending', '../internal/isIterateeCall', '../internal/isLength'], function(baseEach, baseFlatten, baseSortBy, compareMultipleAscending, isIterateeCall, isLength) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
define(['../internal/baseFlatten', '../internal/baseSortByOrder', '../internal/isIterateeCall'], function(baseFlatten, baseSortByOrder, isIterateeCall) {
/**
* This method is like `_.sortBy` except that it sorts by property names
@@ -27,25 +24,16 @@ define(['../internal/baseEach', '../internal/baseFlatten', '../internal/baseSort
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
*/
function sortByAll(collection) {
var args = arguments;
if (args.length > 3 && isIterateeCall(args[1], args[2], args[3])) {
if (collection == null) {
return [];
}
var args = arguments,
guard = args[3];
if (guard && isIterateeCall(args[1], args[2], guard)) {
args = [collection, args[1]];
}
var index = -1,
length = collection ? collection.length : 0,
props = baseFlatten(args, false, false, 1),
result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value) {
var length = props.length,
criteria = Array(length);
while (length--) {
criteria[length] = value == null ? undefined : value[props[length]];
}
result[++index] = { 'criteria': criteria, 'index': index, 'value': value };
});
return baseSortBy(result, compareMultipleAscending);
return baseSortByOrder(collection, baseFlatten(args, false, false, 1), []);
}
return sortByAll;

47
collection/sortByOrder.js Normal file
View File

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

3
collection/sum.js Normal file
View File

@@ -0,0 +1,3 @@
define(["../math/sum"], function(sum) {
return sum;
});

View File

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

View File

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

View File

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

View File

@@ -61,13 +61,14 @@ define(['../internal/MapCache'], function(MapCache) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var memoized = function() {
var cache = memoized.cache,
key = resolver ? resolver.apply(this, arguments) : arguments[0];
var args = arguments,
cache = memoized.cache,
key = resolver ? resolver.apply(this, args) : args[0];
if (cache.has(key)) {
return cache.get(key);
}
var result = func.apply(this, arguments);
var result = func.apply(this, args);
cache.set(key, result);
return result;
};

View File

@@ -29,7 +29,7 @@ define(['./debounce', '../lang/isObject'], function(debounce, isObject) {
* @memberOf _
* @category Function
* @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 {boolean} [options.leading=true] Specify invoking on the leading
* edge of the timeout.

View File

@@ -23,7 +23,7 @@ define(['./baseCopy', '../object/keys'], function(baseCopy, keys) {
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? result !== value : value === value) ||
if ((result === result ? (result !== value) : (value === value)) ||
(typeof value == 'undefined' && !(key in object))) {
object[key] = result;
}

View File

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

View File

@@ -21,7 +21,7 @@ define([], function() {
if (end < 0) {
end += length;
}
length = start > end ? 0 : end >>> 0;
length = start > end ? 0 : (end >>> 0);
start >>>= 0;
while (start < length) {

View File

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

View File

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

View File

@@ -34,7 +34,7 @@ define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './
result = srcValue;
}
if ((isSrcArr || typeof result != 'undefined') &&
(isCommon || (result === result ? result !== value : value === value))) {
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
}
});

View File

@@ -56,7 +56,7 @@ define(['./arrayCopy', '../lang/isArguments', '../lang/isArray', './isLength', '
if (isCommon) {
// Recursively merge objects and arrays (susceptible to call stack limits).
object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
} else if (result === result ? result !== value : value === value) {
} else if (result === result ? (result !== value) : (value === value)) {
object[key] = result;
}
}

View File

@@ -21,7 +21,7 @@ define([], function() {
if (end < 0) {
end += length;
}
length = start > end ? 0 : (end - start) >>> 0;
length = start > end ? 0 : ((end - start) >>> 0);
start >>>= 0;
var result = Array(length);

View File

@@ -1,8 +1,8 @@
define([], function() {
/**
* The base implementation of `_.sortBy` and `_.sortByAll` which uses `comparer`
* to define the sort order of `array` and replaces criteria objects with their
* The base implementation of `_.sortBy` which uses `comparer` to define
* the sort order of `array` and replaces criteria objects with their
* corresponding values.
*
* @private

View File

@@ -0,0 +1,36 @@
define(['./baseEach', './baseSortBy', './compareMultiple', './isLength'], function(baseEach, baseSortBy, compareMultiple, isLength) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* The base implementation of `_.sortByOrder` without param guards.
*
* @private
* @param {Array|Object|string} collection The collection to iterate over.
* @param {string[]} props The property names to sort by.
* @param {boolean[]} orders The sort orders of `props`.
* @returns {Array} Returns the new sorted array.
*/
function baseSortByOrder(collection, props, orders) {
var index = -1,
length = collection.length,
result = isLength(length) ? Array(length) : [];
baseEach(collection, function(value) {
var length = props.length,
criteria = Array(length);
while (length--) {
criteria[length] = value == null ? undefined : value[props[length]];
}
result[++index] = { 'criteria': criteria, 'index': index, 'value': value };
});
return baseSortBy(result, function(object, other) {
return compareMultiple(object, other, orders);
});
}
return baseSortByOrder;
});

View File

@@ -15,7 +15,7 @@ define(['./baseIndexOf', './cacheIndexOf', './createCache'], function(baseIndexO
length = array.length,
isCommon = true,
isLarge = isCommon && length >= 200,
seen = isLarge && createCache(),
seen = isLarge ? createCache() : null,
result = [];
if (seen) {
@@ -42,7 +42,7 @@ define(['./baseIndexOf', './cacheIndexOf', './createCache'], function(baseIndexO
}
result.push(value);
}
else if (indexOf(seen, computed) < 0) {
else if (indexOf(seen, computed, 0) < 0) {
if (iteratee || isLarge) {
seen.push(computed);
}

View File

@@ -1,24 +1,33 @@
define(['./baseCompareAscending'], function(baseCompareAscending) {
/**
* Used by `_.sortByAll` to compare multiple properties of each element
* in a collection and stable sort them in ascending order.
* Used by `_.sortByOrder` to compare multiple properties of each element
* in a collection and stable sort them in the following order:
*
* If orders is unspecified, sort in ascending order for all properties.
* Otherwise, for each property, sort in ascending order if its corresponding value in
* orders is true, and descending order if false.
*
* @private
* @param {Object} object The object to compare to `other`.
* @param {Object} other The object to compare to `object`.
* @param {boolean[]} orders The order to sort by for each property.
* @returns {number} Returns the sort order indicator for `object`.
*/
function compareMultipleAscending(object, other) {
function compareMultiple(object, other, orders) {
var index = -1,
objCriteria = object.criteria,
othCriteria = other.criteria,
length = objCriteria.length;
length = objCriteria.length,
ordersLength = orders.length;
while (++index < length) {
var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
if (result) {
return result;
if (index >= ordersLength) {
return result;
}
return result * (orders[index] ? 1 : -1);
}
}
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
@@ -31,5 +40,5 @@ define(['./baseCompareAscending'], function(baseCompareAscending) {
return object.index - other.index;
}
return compareMultipleAscending;
return compareMultiple;
});

View File

@@ -10,24 +10,31 @@ define(['./bindCallback', './isIterateeCall'], function(bindCallback, isIteratee
*/
function createAssigner(assigner) {
return function() {
var length = arguments.length,
object = arguments[0];
var args = arguments,
length = args.length,
object = args[0];
if (length < 2 || object == null) {
return object;
}
if (length > 3 && isIterateeCall(arguments[1], arguments[2], arguments[3])) {
length = 2;
var customizer = args[length - 2],
thisArg = args[length - 1],
guard = args[3];
if (length > 3 && typeof customizer == 'function') {
customizer = bindCallback(customizer, thisArg, 5);
length -= 2;
} else {
customizer = (length > 2 && typeof thisArg == 'function') ? thisArg : null;
length -= (customizer ? 1 : 0);
}
// Juggle arguments.
if (length > 3 && typeof arguments[length - 2] == 'function') {
var customizer = bindCallback(arguments[--length - 1], arguments[length--], 5);
} else if (length > 2 && typeof arguments[length - 1] == 'function') {
customizer = arguments[--length];
if (guard && isIterateeCall(args[1], args[2], guard)) {
customizer = length == 3 ? null : customizer;
length = 2;
}
var index = 0;
while (++index < length) {
var source = arguments[index];
var source = args[index];
if (source) {
assigner(object, source, customizer);
}

View File

@@ -1,4 +1,4 @@
define(['./createCtorWrapper'], function(createCtorWrapper) {
define(['./createCtorWrapper', './root'], function(createCtorWrapper, root) {
/**
* Creates a function that wraps `func` and invokes it with the `this`
@@ -13,7 +13,8 @@ define(['./createCtorWrapper'], function(createCtorWrapper) {
var Ctor = createCtorWrapper(func);
function wrapper() {
return (this instanceof wrapper ? Ctor : func).apply(thisArg, arguments);
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
return fn.apply(thisArg, arguments);
}
return wrapper;
}

View File

@@ -0,0 +1,42 @@
define([], function() {
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a function to compose other functions into a single function.
*
* @private
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Function} Returns the new composer function.
*/
function createComposer(fromRight) {
return function() {
var length = arguments.length,
index = length,
fromIndex = fromRight ? (length - 1) : 0;
if (!length) {
return function() { return arguments[0]; };
}
var funcs = Array(length);
while (index--) {
funcs[index] = arguments[index];
if (typeof funcs[index] != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
}
return function() {
var index = fromIndex,
result = funcs[index].apply(this, arguments);
while ((fromRight ? index-- : ++index < length)) {
result = funcs[index].call(this, result);
}
return result;
};
};
}
return createComposer;
});

View File

@@ -1,4 +1,4 @@
define(['./arrayCopy', './composeArgs', './composeArgsRight', './createCtorWrapper', './reorder', './replaceHolders'], function(arrayCopy, composeArgs, composeArgsRight, createCtorWrapper, reorder, replaceHolders) {
define(['./arrayCopy', './composeArgs', './composeArgsRight', './createCtorWrapper', './reorder', './replaceHolders', './root'], function(arrayCopy, composeArgs, composeArgsRight, createCtorWrapper, reorder, replaceHolders, root) {
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
@@ -91,7 +91,8 @@ define(['./arrayCopy', './composeArgs', './composeArgsRight', './createCtorWrapp
if (isAry && ary < args.length) {
args.length = ary;
}
return (this instanceof wrapper ? (Ctor || createCtorWrapper(func)) : func).apply(thisBinding, args);
var fn = (this && this !== root && this instanceof wrapper) ? (Ctor || createCtorWrapper(func)) : func;
return fn.apply(thisBinding, args);
}
return wrapper;
}

View File

@@ -1,4 +1,4 @@
define(['./createCtorWrapper'], function(createCtorWrapper) {
define(['./createCtorWrapper', './root'], function(createCtorWrapper, root) {
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1;
@@ -34,7 +34,8 @@ define(['./createCtorWrapper'], function(createCtorWrapper) {
while (argsLength--) {
args[leftIndex++] = arguments[++argsIndex];
}
return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args);
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
return fn.apply(isBind ? thisArg : this, args);
}
return wrapper;
}

View File

@@ -64,8 +64,10 @@ define(['../object/keys'], function(keys) {
othCtor = other.constructor;
// Non `Object` object instances with different constructors are not equal.
if (objCtor != othCtor && ('constructor' in object && 'constructor' in other) &&
!(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
if (objCtor != othCtor &&
('constructor' in object && 'constructor' in other) &&
!(typeof objCtor == 'function' && objCtor instanceof objCtor &&
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
return false;
}
}

View File

@@ -23,7 +23,8 @@ define(['./baseEach'], function(baseEach) {
baseEach(collection, function(value, index, collection) {
var current = iteratee(value, index, collection);
if ((isMin ? current < computed : current > computed) || (current === exValue && current === result)) {
if ((isMin ? (current < computed) : (current > computed)) ||
(current === exValue && current === result)) {
computed = current;
result = value;
}

View File

@@ -6,13 +6,13 @@ define([], function() {
*
* @private
* @param {Array} array The array to search.
* @param {number} [fromIndex] The index to search from.
* @param {number} fromIndex The index to search from.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched `NaN`, else `-1`.
*/
function indexOfNaN(array, fromIndex, fromRight) {
var length = array.length,
index = fromRight ? (fromIndex || length) : ((fromIndex || 0) - 1);
index = fromIndex + (fromRight ? 0 : -1);
while ((fromRight ? index-- : ++index < length)) {
var other = array[index];

View File

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

View File

@@ -16,7 +16,6 @@ define(['./LazyWrapper', './arrayCopy'], function(LazyWrapper, arrayCopy) {
result.__actions__ = actions ? arrayCopy(actions) : null;
result.__dir__ = this.__dir__;
result.__dropCount__ = this.__dropCount__;
result.__filtered__ = this.__filtered__;
result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
result.__takeCount__ = this.__takeCount__;

View File

@@ -1,8 +1,9 @@
define(['./baseWrapperValue', './getView', '../lang/isArray'], function(baseWrapperValue, getView, isArray) {
/** Used to indicate the type of lazy iteratees. */
var LAZY_FILTER_FLAG = 0,
LAZY_MAP_FLAG = 1;
var LAZY_DROP_WHILE_FLAG = 0,
LAZY_FILTER_FLAG = 1,
LAZY_MAP_FLAG = 2;
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMin = Math.min;
@@ -26,9 +27,8 @@ define(['./baseWrapperValue', './getView', '../lang/isArray'], function(baseWrap
start = view.start,
end = view.end,
length = end - start,
dropCount = this.__dropCount__,
index = isRight ? end : (start - 1),
takeCount = nativeMin(length, this.__takeCount__),
index = isRight ? end : start - 1,
iteratees = this.__iteratees__,
iterLength = iteratees ? iteratees.length : 0,
resIndex = 0,
@@ -44,24 +44,34 @@ define(['./baseWrapperValue', './getView', '../lang/isArray'], function(baseWrap
while (++iterIndex < iterLength) {
var data = iteratees[iterIndex],
iteratee = data.iteratee,
computed = iteratee(value, index, array),
type = data.type;
if (type == LAZY_MAP_FLAG) {
value = computed;
} else if (!computed) {
if (type == LAZY_FILTER_FLAG) {
continue outer;
} else {
break outer;
if (type == LAZY_DROP_WHILE_FLAG) {
if (data.done && (isRight ? (index > data.index) : (index < data.index))) {
data.count = 0;
data.done = false;
}
data.index = index;
if (!data.done) {
var limit = data.limit;
if (!(data.done = limit > -1 ? (data.count++ >= limit) : !iteratee(value))) {
continue outer;
}
}
} else {
var computed = iteratee(value);
if (type == LAZY_MAP_FLAG) {
value = computed;
} else if (!computed) {
if (type == LAZY_FILTER_FLAG) {
continue outer;
} else {
break outer;
}
}
}
}
if (dropCount) {
dropCount--;
} else {
result[resIndex++] = value;
}
result[resIndex++] = value;
}
return result;
}

View File

@@ -6,25 +6,25 @@ define([], function() {
'object': true
};
/**
* Used as a reference to the global object.
*
* The `this` value is used if it is the global object to avoid Greasemonkey's
* restricted `window` object, otherwise the `window` object is used.
*/
var root = (objectTypes[typeof window] && window !== (this && this.window)) ? window : this;
/** Detect free variable `exports`. */
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
/** Detect free variable `module`. */
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
/** Detect free variable `global` from Node.js or Browserified code and use it as `root`. */
/** Detect free variable `global` from Node.js. */
var freeGlobal = freeExports && freeModule && typeof global == 'object' && global;
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
root = freeGlobal;
}
/** Detect free variable `window`. */
var freeWindow = objectTypes[typeof window] && window;
/**
* Used as a reference to the global object.
*
* The `this` value is used if it is the global object to avoid Greasemonkey's
* restricted `window` object, otherwise the `window` object is used.
*/
var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || this;
return root;
});

View File

@@ -28,7 +28,7 @@ define(['../internal/isObjectLike', './isPlainObject', '../support'], function(i
*/
function isElement(value) {
return (value && value.nodeType === 1 && isObjectLike(value) &&
objToString.call(value).indexOf('Element') > -1) || false;
(objToString.call(value).indexOf('Element') > -1)) || false;
}
// Fallback for environments without DOM support.
if (!support.dom) {

View File

@@ -1,7 +1,7 @@
define(['./isArguments', './isArray', './isFunction', '../internal/isLength', '../internal/isObjectLike', './isString', '../object/keys'], function(isArguments, isArray, isFunction, isLength, isObjectLike, isString, keys) {
/**
* Checks if a value is empty. A value is considered empty unless it is an
* Checks if `value` is empty. A value is considered empty unless it is an
* `arguments` object, array, string, or jQuery-like collection with a length
* greater than `0` or an object with own enumerable properties.
*

904
main.js

File diff suppressed because it is too large Load Diff

8
math.js Normal file
View File

@@ -0,0 +1,8 @@
define(['./math/add', './math/max', './math/min', './math/sum'], function(add, max, min, sum) {
return {
'add': add,
'max': max,
'min': min,
'sum': sum
};
});

22
math/add.js Normal file
View File

@@ -0,0 +1,22 @@
define([], function() {
/**
* Adds two numbers.
*
* @static
* @memberOf _
* @category Math
* @param {number} augend The first number to add.
* @param {number} addend The second number to add.
* @returns {number} Returns the sum.
* @example
*
* _.add(6, 4);
* // => 10
*/
function add(augend, addend) {
return augend + addend;
}
return add;
});

53
math/max.js Normal file
View File

@@ -0,0 +1,53 @@
define(['../internal/arrayMax', '../internal/createExtremum'], function(arrayMax, createExtremum) {
/**
* Gets the maximum value of `collection`. If `collection` is empty or falsey
* `-Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* arguments; (value, index, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Math
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the maximum value.
* @example
*
* _.max([4, 2, 8, 6]);
* // => 8
*
* _.max([]);
* // => -Infinity
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* _.max(users, function(chr) {
* return chr.age;
* });
* // => { 'user': 'fred', 'age': 40 };
*
* // using the `_.property` callback shorthand
* _.max(users, 'age');
* // => { 'user': 'fred', 'age': 40 };
*/
var max = createExtremum(arrayMax);
return max;
});

53
math/min.js Normal file
View File

@@ -0,0 +1,53 @@
define(['../internal/arrayMin', '../internal/createExtremum'], function(arrayMin, createExtremum) {
/**
* Gets the minimum value of `collection`. If `collection` is empty or falsey
* `Infinity` is returned. If an iteratee function is provided it is invoked
* for each value in `collection` to generate the criterion by which the value
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
* arguments; (value, index, collection).
*
* If a property name is provided for `predicate` the created `_.property`
* style callback returns the property value of the given element.
*
* If a value is also provided for `thisArg` the created `_.matchesProperty`
* style callback returns `true` for elements that have a matching property
* value, else `false`.
*
* If an object is provided for `predicate` the created `_.matches` style
* callback returns `true` for elements that have the properties of the given
* object, else `false`.
*
* @static
* @memberOf _
* @category Math
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the minimum value.
* @example
*
* _.min([4, 2, 8, 6]);
* // => 2
*
* _.min([]);
* // => Infinity
*
* var users = [
* { 'user': 'barney', 'age': 36 },
* { 'user': 'fred', 'age': 40 }
* ];
*
* _.min(users, function(chr) {
* return chr.age;
* });
* // => { 'user': 'barney', 'age': 36 };
*
* // using the `_.property` callback shorthand
* _.min(users, 'age');
* // => { 'user': 'barney', 'age': 36 };
*/
var min = createExtremum(arrayMin, true);
return min;
});

33
math/sum.js Normal file
View File

@@ -0,0 +1,33 @@
define(['../lang/isArray', '../internal/toIterable'], function(isArray, toIterable) {
/**
* Gets the sum of the values in `collection`.
*
* @static
* @memberOf _
* @category Math
* @param {Array|Object|string} collection The collection to iterate over.
* @returns {number} Returns the sum.
* @example
*
* _.sum([4, 6, 2]);
* // => 12
*
* _.sum({ 'a': 4, 'b': 6, 'c': 2 });
* // => 12
*/
function sum(collection) {
if (!isArray(collection)) {
collection = toIterable(collection);
}
var length = collection.length,
result = 0;
while (length--) {
result += +collection[length] || 0;
}
return result;
}
return sum;
});

View File

@@ -2,7 +2,7 @@ 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`.
* `end` is not specified it is set to `start` with `start` then set to `0`.
*
* @static
* @memberOf _

View File

@@ -6,7 +6,7 @@ define(['../internal/arrayCopy', './assign', '../internal/assignDefaults'], func
/**
* Assigns own enumerable properties of source object(s) to the destination
* object for all destination properties that resolve to `undefined`. Once a
* property is set, additional defaults of the same property are ignored.
* property is set, additional values of the same property are ignored.
*
* @static
* @memberOf _

View File

@@ -36,7 +36,7 @@ define(['../internal/isLength', '../lang/isNative', '../lang/isObject', '../inte
length = object.length;
}
if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
(typeof object != 'function' && (length && isLength(length)))) {
(typeof object != 'function' && (length && isLength(length)))) {
return shimKeys(object);
}
return isObject(object) ? nativeKeys(object) : [];

View File

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

View File

@@ -29,7 +29,11 @@ define(['../internal/baseToString'], function(baseToString) {
target = (target + '');
var length = string.length;
position = (typeof position == 'undefined' ? length : nativeMin(position < 0 ? 0 : (+position || 0), length)) - target.length;
position = typeof position == 'undefined'
? length
: nativeMin(position < 0 ? 0 : (+position || 0), length);
position -= target.length;
return position >= 0 && string.indexOf(target, position) == position;
}

View File

@@ -5,7 +5,7 @@ define(['../internal/baseToString', '../internal/escapeHtmlChar'], function(base
reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
/**
* Converts the characters "&", "<", ">", '"', "'", and '`', in `string` to
* Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
* their corresponding HTML entities.
*
* **Note:** No other characters are escaped. To escape additional characters

View File

@@ -26,7 +26,10 @@ define(['../internal/baseToString'], function(baseToString) {
*/
function startsWith(string, target, position) {
string = baseToString(string);
position = position == null ? 0 : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
position = position == null
? 0
: nativeMin(position < 0 ? 0 : (+position || 0), string.length);
return string.lastIndexOf(target, position) == position;
}

View File

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

View File

@@ -57,7 +57,7 @@ define(['../internal/baseToString', '../internal/isIterateeCall', '../lang/isObj
if (options != null) {
if (isObject(options)) {
var separator = 'separator' in options ? options.separator : separator;
length = 'length' in options ? +options.length || 0 : length;
length = 'length' in options ? (+options.length || 0) : length;
omission = 'omission' in options ? baseToString(options.omission) : omission;
} else {
length = +options || 0;

View File

@@ -5,7 +5,7 @@ define(['../internal/baseToString', '../internal/isIterateeCall'], function(base
var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
return RegExp(upper + '{2,}(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
}());
/**

View File

@@ -24,14 +24,14 @@ define(['../lang/isError'], function(isError) {
* }
*/
function attempt() {
var length = arguments.length,
func = arguments[0];
var func = arguments[0],
length = arguments.length,
args = Array(length ? (length - 1) : 0);
while (--length > 0) {
args[length - 1] = arguments[length];
}
try {
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);

View File

@@ -66,7 +66,11 @@ define(['../internal/arrayCopy', '../internal/baseFunctions', '../lang/isFunctio
var chainAll = this.__chain__;
if (chain || chainAll) {
var result = object(this.__wrapped__);
(result.__actions__ = arrayCopy(this.__actions__)).push({ 'func': func, 'args': arguments, 'thisArg': object });
(result.__actions__ = arrayCopy(this.__actions__)).push({
'func': func,
'args': arguments,
'thisArg': object
});
result.__chain__ = chainAll;
return result;
}

View File

@@ -8,9 +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 `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.
* `start` up to, but not including, `end`. If `end` is not specified it is
* set to `start` with `start` then set to `0`. If `start` is less than `end`
* a zero-length range is created unless a negative `step` is specified.
*
* @static
* @memberOf _