Compare commits

...

4 Commits

Author SHA1 Message Date
jdalton
ee1f12c851 Bump to v3.5.0. 2015-03-08 18:09:08 -07:00
jdalton
d01a1e4ef3 Bump to v3.4.0. 2015-03-06 01:11:05 -08:00
jdalton
1e05116bcb Bump to v3.3.1. 2015-02-24 00:27:34 -08:00
jdalton
ebf61a1bd9 Bump to v3.3.0. 2015-02-20 00:25:55 -08:00
136 changed files with 959 additions and 532 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-es v3.2.0
# lodash-es v3.5.0
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [ES](https://people.mozilla.org/~jorendorff/es6-draft.html) modules.
@@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli):
$ lodash modularize modern exports=es -o ./
```
See the [package source](https://github.com/lodash/lodash/tree/3.2.0-es) for more details.
See the [package source](https://github.com/lodash/lodash/tree/3.5.0-es) for more details.

View File

@@ -20,20 +20,21 @@ import isArray from '../lang/isArray';
* @returns {Array} Returns the new array of filtered values.
* @example
*
* _.difference([1, 2, 3], [5, 2, 10]);
* _.difference([1, 2, 3], [4, 2]);
* // => [1, 3]
*/
function difference() {
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));
}
export default difference;

View File

@@ -27,7 +27,9 @@ import baseSlice from '../internal/baseSlice';
* @returns {Array} Returns the slice of `array`.
* @example
*
* _.dropRightWhile([1, 2, 3], function(n) { return n > 1; });
* _.dropRightWhile([1, 2, 3], function(n) {
* return n > 1;
* });
* // => [1]
*
* var users = [
@@ -37,7 +39,7 @@ import baseSlice from '../internal/baseSlice';
* ];
*
* // 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

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

View File

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

View File

@@ -31,16 +31,18 @@ import baseCallback from '../internal/baseCallback';
* { 'user': 'pebbles', 'active': false }
* ];
*
* _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; });
* _.findLastIndex(users, function(chr) {
* return chr.user == 'pebbles';
* });
* // => 2
*
* // using the `_.matches` callback shorthand
* _.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

@@ -14,11 +14,11 @@ import isIterateeCall from '../internal/isIterateeCall';
* @returns {Array} Returns the new flattened array.
* @example
*
* _.flatten([1, [2], [3, [[4]]]]);
* // => [1, 2, 3, [[4]]];
* _.flatten([1, [2, 3, [4]]]);
* // => [1, 2, 3, [4]];
*
* // using `isDeep`
* _.flatten([1, [2], [3, [[4]]]], true);
* _.flatten([1, [2, 3, [4]]], true);
* // => [1, 2, 3, 4];
*/
function flatten(array, isDeep, guard) {
@@ -26,7 +26,7 @@ function flatten(array, isDeep, guard) {
if (guard && isIterateeCall(array, isDeep, guard)) {
isDeep = false;
}
return length ? baseFlatten(array, isDeep) : [];
return length ? baseFlatten(array, isDeep, false, 0) : [];
}
export default flatten;

View File

@@ -10,12 +10,12 @@ import baseFlatten from '../internal/baseFlatten';
* @returns {Array} Returns the new flattened array.
* @example
*
* _.flattenDeep([1, [2], [3, [[4]]]]);
* _.flattenDeep([1, [2, 3, [4]]]);
* // => [1, 2, 3, 4];
*/
function flattenDeep(array) {
var length = array ? array.length : 0;
return length ? baseFlatten(array, true) : [];
return length ? baseFlatten(array, true, false, 0) : [];
}
export default flattenDeep;

View File

@@ -25,15 +25,15 @@ var nativeMax = Math.max;
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
* _.indexOf([1, 2, 3, 1, 2, 3], 2);
* _.indexOf([1, 2, 1, 2], 2);
* // => 1
*
* // using `fromIndex`
* _.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
* // => 4
* _.indexOf([1, 2, 1, 2], 2, 2);
* // => 3
*
* // performing a binary search
* _.indexOf([4, 4, 5, 5, 6, 6], 5, true);
* _.indexOf([1, 1, 2, 2], 2, true);
* // => 2
*/
function indexOf(array, value, fromIndex) {
@@ -42,14 +42,17 @@ function indexOf(array, value, fromIndex) {
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);
}
export default indexOf;

View File

@@ -19,9 +19,8 @@ import isArray from '../lang/isArray';
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of shared values.
* @example
*
* _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]);
* // => [1, 2]
* _.intersection([1, 2], [4, 2], [2, 1]);
* // => [2]
*/
function intersection() {
var args = [],
@@ -35,7 +34,7 @@ function intersection() {
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;
@@ -48,11 +47,11 @@ function intersection() {
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

@@ -19,15 +19,15 @@ var nativeMax = Math.max,
* @returns {number} Returns the index of the matched value, else `-1`.
* @example
*
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
* // => 4
* _.lastIndexOf([1, 2, 1, 2], 2);
* // => 3
*
* // using `fromIndex`
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
* _.lastIndexOf([1, 2, 1, 2], 2, 2);
* // => 1
*
* // performing a binary search
* _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true);
* _.lastIndexOf([1, 1, 2, 2], 2, true);
* // => 3
*/
function lastIndexOf(array, value, fromIndex) {
@@ -41,7 +41,10 @@ function lastIndexOf(array, value, fromIndex) {
} else if (fromIndex) {
index = binaryIndex(array, value, true) - 1;
var other = array[index];
return (value === value ? value === other : other !== other) ? index : -1;
if (value === value ? (value === other) : (other !== other)) {
return index;
}
return -1;
}
if (value !== value) {
return indexOfNaN(array, index, true);

View File

@@ -25,22 +25,25 @@ var splice = arrayProto.splice;
* @example
*
* var array = [1, 2, 3, 1, 2, 3];
*
* _.pull(array, 2, 3);
* console.log(array);
* // => [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

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

View File

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

View File

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

View File

@@ -19,7 +19,7 @@ import binaryIndexBy from '../internal/binaryIndexBy';
* into `array`.
* @example
*
* _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5);
* _.sortedLastIndex([4, 4, 5, 5], 5);
* // => 4
*/
function sortedLastIndex(array, value, iteratee, thisArg) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -15,11 +15,8 @@ import isArray from '../lang/isArray';
* @returns {Array} Returns the new array of values.
* @example
*
* _.xor([1, 2, 3], [5, 2, 1, 4]);
* // => [3, 5, 4]
*
* _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
* // => [1, 4, 5]
* _.xor([1, 2], [4, 2]);
* // => [1, 4]
*/
function xor() {
var index = -1,

View File

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

View File

@@ -1,5 +1,6 @@
import LazyWrapper from '../internal/LazyWrapper';
import LodashWrapper from '../internal/LodashWrapper';
import baseLodash from '../internal/baseLodash';
import isArray from '../lang/isArray';
import isObjectLike from '../internal/isObjectLike';
import wrapperClone from '../internal/wrapperClone';
@@ -26,9 +27,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* Chaining is supported in custom builds as long as the `_#value` method is
* directly or indirectly included in the build.
*
* In addition to lodash methods, wrappers also have the following `Array` methods:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
* and `unshift`
* In addition to lodash methods, wrappers have `Array` and `String` methods.
*
* The wrapper `Array` methods are:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
* `splice`, and `unshift`
*
* The wrapper `String` methods are:
* `replace` and `split`
*
* The wrapper methods that support shortcut fusion are:
* `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
@@ -48,26 +54,26 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* `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.
@@ -82,11 +88,15 @@ var hasOwnProperty = objectProto.hasOwnProperty;
* var wrapped = _([1, 2, 3]);
*
* // returns an unwrapped value
* wrapped.reduce(function(sum, n) { return sum + n; });
* wrapped.reduce(function(sum, n) {
* return sum + n;
* });
* // => 6
*
* // returns a wrapped value
* var squares = wrapped.map(function(n) { return n * n; });
* var squares = wrapped.map(function(n) {
* return n * n;
* });
*
* _.isArray(squares);
* // => false
@@ -106,4 +116,7 @@ function lodash(value) {
return new LodashWrapper(value);
}
// Ensure wrappers are instances of `baseLodash`.
lodash.prototype = baseLodash.prototype;
export default lodash;

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
import LodashWrapper from '../internal/LodashWrapper';
import baseLodash from '../internal/baseLodash';
import wrapperClone from '../internal/wrapperClone';
/**
@@ -28,7 +28,7 @@ function wrapperPlant(value) {
var result,
parent = this;
while (parent instanceof LodashWrapper) {
while (parent instanceof baseLodash) {
var clone = wrapperClone(parent);
if (result) {
previous.__wrapped__ = clone;

View File

@@ -23,8 +23,8 @@ import indexBy from './collection/indexBy';
import inject from './collection/inject';
import invoke from './collection/invoke';
import map from './collection/map';
import max from './collection/max';
import min from './collection/min';
import max from './math/max';
import min from './math/min';
import partition from './collection/partition';
import pluck from './collection/pluck';
import reduce from './collection/reduce';
@@ -37,6 +37,8 @@ import size from './collection/size';
import some from './collection/some';
import sortBy from './collection/sortBy';
import sortByAll from './collection/sortByAll';
import sortByOrder from './collection/sortByOrder';
import sum from './math/sum';
import where from './collection/where';
export default {
@@ -79,5 +81,7 @@ export default {
'some': some,
'sortBy': sortBy,
'sortByAll': sortByAll,
'sortByOrder': sortByOrder,
'sum': sum,
'where': where
};

View File

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

View File

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

View File

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

View File

@@ -37,7 +37,9 @@ import isArray from '../lang/isArray';
* { 'user': 'pebbles', 'age': 1, 'active': true }
* ];
*
* _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user');
* _.result(_.find(users, function(chr) {
* return chr.age < 40;
* }), 'user');
* // => 'barney'
*
* // using the `_.matches` callback shorthand

View File

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

View File

@@ -23,10 +23,14 @@ import isArray from '../lang/isArray';
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2, 3]).forEach(function(n) { console.log(n); }).value();
* _([1, 2]).forEach(function(n) {
* console.log(n);
* }).value();
* // => logs each value from left to right and returns the array
*
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });
* _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
* console.log(n, key);
* });
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
*/
function forEach(collection, iteratee, thisArg) {

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,51 +1,2 @@
import arrayMax from '../internal/arrayMax';
import createExtremum from '../internal/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);
import max from '../math/max'
export default max;

View File

@@ -1,51 +1,2 @@
import arrayMin from '../internal/arrayMin';
import createExtremum from '../internal/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);
import min from '../math/min'
export default min;

View File

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

View File

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

View File

@@ -20,7 +20,10 @@ import isArray from '../lang/isArray';
* @example
*
* var array = [[0, 1], [2, 3], [4, 5]];
* _.reduceRight(array, function(flattened, other) { return flattened.concat(other); }, []);
*
* _.reduceRight(array, function(flattened, other) {
* return flattened.concat(other);
* }, []);
* // => [4, 5, 2, 3, 0, 1]
*/
function reduceRight(collection, iteratee, accumulator, thisArg) {

View File

@@ -28,7 +28,9 @@ import isArray from '../lang/isArray';
* @returns {Array} Returns the new filtered array.
* @example
*
* var odds = _.reject([1, 2, 3, 4], function(n) { return n % 2 == 0; });
* _.reject([1, 2, 3, 4], function(n) {
* return n % 2 == 0;
* });
* // => [1, 3]
*
* var users = [

View File

@@ -2,8 +2,8 @@ import isLength from '../internal/isLength';
import keys from '../object/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 _
@@ -12,12 +12,12 @@ import keys from '../object/keys';
* @returns {number} Returns the size of `collection`.
* @example
*
* _.size([1, 2]);
* // => 2
*
* _.size({ 'one': 1, 'two': 2, 'three': 3 });
* _.size([1, 2, 3]);
* // => 3
*
* _.size({ 'a': 1, 'b': 2 });
* // => 2
*
* _.size('pebbles');
* // => 7
*/

View File

@@ -41,7 +41,7 @@ import isArray from '../lang/isArray';
* ];
*
* // 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

@@ -34,10 +34,14 @@ import isLength from '../internal/isLength';
* @returns {Array} Returns the new sorted array.
* @example
*
* _.sortBy([1, 2, 3], function(n) { return Math.sin(n); });
* _.sortBy([1, 2, 3], function(n) {
* return Math.sin(n);
* });
* // => [3, 1, 2]
*
* _.sortBy([1, 2, 3], function(n) { return this.sin(n); }, Math);
* _.sortBy([1, 2, 3], function(n) {
* return this.sin(n);
* }, Math);
* // => [3, 1, 2]
*
* var users = [
@@ -51,8 +55,11 @@ import isLength from '../internal/isLength';
* // => ['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,9 +1,6 @@
import baseEach from '../internal/baseEach';
import baseFlatten from '../internal/baseFlatten';
import baseSortBy from '../internal/baseSortBy';
import compareMultipleAscending from '../internal/compareMultipleAscending';
import baseSortByOrder from '../internal/baseSortByOrder';
import isIterateeCall from '../internal/isIterateeCall';
import isLength from '../internal/isLength';
/**
* This method is like `_.sortBy` except that it sorts by property names
@@ -29,25 +26,16 @@ import isLength from '../internal/isLength';
* // => [['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), []);
}
export default sortByAll;

48
collection/sortByOrder.js Normal file
View File

@@ -0,0 +1,48 @@
import baseSortByOrder from '../internal/baseSortByOrder';
import isArray from '../lang/isArray';
import isIterateeCall from '../internal/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);
}
export default sortByOrder;

2
collection/sum.js Normal file
View File

@@ -0,0 +1,2 @@
import sum from '../math/sum'
export default sum;

View File

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

View File

@@ -21,7 +21,9 @@ import functions from '../object/functions';
*
* var view = {
* 'label': 'docs',
* 'onClick': function() { console.log('clicked ' + this.label); }
* 'onClick': function() {
* console.log('clicked ' + this.label);
* }
* };
*
* _.bindAll(view);

View File

@@ -26,7 +26,7 @@ var nativeMax = Math.max;
* @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.
@@ -84,7 +84,7 @@ function debounce(func, wait, options) {
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

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

View File

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

View File

@@ -1,8 +1,4 @@
import arrayEvery from '../internal/arrayEvery';
import isFunction from '../lang/isFunction';
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
import createComposer from '../internal/createComposer';
/**
* Creates a function that returns the result of invoking the provided
@@ -16,37 +12,14 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* @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, isFunction)) {
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();
export default flow;

View File

@@ -1,8 +1,4 @@
import arrayEvery from '../internal/arrayEvery';
import isFunction from '../lang/isFunction';
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
import createComposer from '../internal/createComposer';
/**
* This method is like `_.flow` except that it creates a function that
@@ -16,37 +12,14 @@ var FUNC_ERROR_TEXT = 'Expected a function';
* @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, isFunction)) {
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);
export default flowRight;

View File

@@ -61,13 +61,14 @@ function memoize(func, resolver) {
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

@@ -27,7 +27,9 @@ var REARG_FLAG = 128;
* // => ['a', 'b', 'c']
*
* var map = _.rearg(_.map, [1, 0]);
* map(function(n) { return n * 3; }, [1, 2, 3]);
* map(function(n) {
* return n * 3;
* }, [1, 2, 3]);
* // => [3, 6, 9]
*/
function rearg(func) {

View File

@@ -30,7 +30,7 @@ var debounceOptions = {
* @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.
@@ -43,8 +43,9 @@ var debounceOptions = {
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
*
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false })
* jQuery('.interactive').on('click', throttled);
* jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
* 'trailing': false
* }));
*
* // cancel a trailing throttled call
* jQuery(window).on('popstate', throttled.cancel);

View File

@@ -1,3 +1,6 @@
import baseCreate from './baseCreate';
import baseLodash from './baseLodash';
/** Used as references for `-Infinity` and `Infinity`. */
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
@@ -18,4 +21,7 @@ function LazyWrapper(value) {
this.__views__ = null;
}
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
export default LazyWrapper;

View File

@@ -1,3 +1,6 @@
import baseCreate from './baseCreate';
import baseLodash from './baseLodash';
/**
* The base constructor for creating `lodash` wrapper objects.
*
@@ -12,4 +15,7 @@ function LodashWrapper(value, chainAll, actions) {
this.__chain__ = !!chainAll;
}
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
LodashWrapper.prototype.constructor = LodashWrapper;
export default LodashWrapper;

View File

@@ -24,7 +24,7 @@ function baseAssign(object, source, customizer) {
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? result !== value : value === value) ||
if ((result === result ? (result !== value) : (value === value)) ||
(typeof value == 'undefined' && !(key in object))) {
object[key] = result;
}

View File

@@ -21,7 +21,7 @@ function baseDifference(array, values) {
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) {
@@ -42,7 +42,7 @@ function baseDifference(array, values) {
}
result.push(value);
}
else if (indexOf(values, value) < 0) {
else if (indexOf(values, value, 0) < 0) {
result.push(value);
}
}

View File

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

View File

@@ -9,13 +9,13 @@ import isObjectLike from './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 = [];
@@ -26,7 +26,7 @@ function baseFlatten(array, isDeep, isStrict, fromIndex) {
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
if (isDeep) {
// Recursively flatten arrays (susceptible to call stack limits).
value = baseFlatten(value, isDeep, isStrict);
value = baseFlatten(value, isDeep, isStrict, 0);
}
var valIndex = -1,
valLength = value.length;

View File

@@ -6,14 +6,14 @@ import indexOfNaN from './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

@@ -0,0 +1,15 @@
/**
* The base implementation of `_.isFunction` without support for environments
* with incorrect `typeof` results.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
*/
function baseIsFunction(value) {
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
return typeof value == 'function' || false;
}
export default baseIsFunction;

10
internal/baseLodash.js Normal file
View File

@@ -0,0 +1,10 @@
/**
* The function whose prototype all chaining wrappers inherit from.
*
* @private
*/
function baseLodash() {
// No operation performed.
}
export default baseLodash;

View File

@@ -3,6 +3,7 @@ import baseForOwn from './baseForOwn';
import baseMergeDeep from './baseMergeDeep';
import isArray from '../lang/isArray';
import isLength from './isLength';
import isObject from '../lang/isObject';
import isObjectLike from './isObjectLike';
import isTypedArray from '../lang/isTypedArray';
@@ -19,8 +20,10 @@ import isTypedArray from '../lang/isTypedArray';
* @returns {Object} Returns the destination object.
*/
function baseMerge(object, source, customizer, stackA, stackB) {
if (!isObject(object)) {
return object;
}
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
if (isObjectLike(srcValue)) {
stackA || (stackA = []);
@@ -35,7 +38,7 @@ function baseMerge(object, source, customizer, stackA, stackB) {
result = srcValue;
}
if ((isSrcArr || typeof result != 'undefined') &&
(isCommon || (result === result ? result !== value : value === value))) {
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
}
});

View File

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

View File

@@ -19,7 +19,7 @@ function baseSlice(array, start, end) {
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,6 +1,6 @@
/**
* 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,35 @@
import baseEach from './baseEach';
import baseSortBy from './baseSortBy';
import compareMultiple from './compareMultiple';
import isLength from './isLength';
/**
* 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);
});
}
export default baseSortByOrder;

View File

@@ -17,7 +17,7 @@ function baseUniq(array, iteratee) {
length = array.length,
isCommon = true,
isLarge = isCommon && length >= 200,
seen = isLarge && createCache(),
seen = isLarge ? createCache() : null,
result = [];
if (seen) {
@@ -44,7 +44,7 @@ function baseUniq(array, iteratee) {
}
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 @@
import baseCompareAscending from './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,4 +40,4 @@ function compareMultipleAscending(object, other) {
return object.index - other.index;
}
export default compareMultipleAscending;
export default compareMultiple;

View File

@@ -11,24 +11,31 @@ import isIterateeCall from './isIterateeCall';
*/
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,5 @@
import createCtorWrapper from './createCtorWrapper';
import root from './root';
/**
* Creates a function that wraps `func` and invokes it with the `this`
@@ -13,7 +14,8 @@ function createBindWrapper(func, thisArg) {
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,39 @@
/** 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;
};
};
}
export default createComposer;

View File

@@ -4,6 +4,7 @@ import composeArgsRight from './composeArgsRight';
import createCtorWrapper from './createCtorWrapper';
import reorder from './reorder';
import replaceHolders from './replaceHolders';
import root from './root';
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
@@ -96,7 +97,8 @@ function createHybridWrapper(func, bitmask, thisArg, partials, holders, partials
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,5 @@
import createCtorWrapper from './createCtorWrapper';
import root from './root';
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1;
@@ -34,7 +35,8 @@ function createPartialWrapper(func, bitmask, thisArg, partials) {
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

@@ -61,8 +61,10 @@ function equalObjects(object, other, equalFunc, customizer, isWhere, stackA, sta
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 @@ function extremumBy(collection, iteratee, isMin) {
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

@@ -4,13 +4,13 @@
*
* @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

@@ -22,7 +22,11 @@ function isIterateeCall(value, index, object) {
} else {
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;
}
export default isIterateeCall;

View File

@@ -17,7 +17,6 @@ function lazyClone() {
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

@@ -3,8 +3,9 @@ import getView from './getView';
import isArray from '../lang/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;
@@ -28,9 +29,8 @@ function lazyValue() {
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,
@@ -46,24 +46,34 @@ function lazyValue() {
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

@@ -4,24 +4,24 @@ var objectTypes = {
'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;
export default root;

View File

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

View File

@@ -34,14 +34,16 @@ import bindCallback from '../internal/bindCallback';
*
* // using a customizer callback
* var el = _.cloneDeep(document.body, function(value) {
* return _.isElement(value) ? value.cloneNode(true) : undefined;
* if (_.isElement(value)) {
* return value.cloneNode(true);
* }
* });
*
* body === document.body
* el === document.body
* // => false
* body.nodeName
* el.nodeName
* // => BODY
* body.childNodes.length;
* el.childNodes.length;
* // => 20
*/
function cloneDeep(value, customizer, thisArg) {

View File

@@ -24,7 +24,7 @@ var objToString = objectProto.toString;
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* (function() { return _.isArguments(arguments); })();
* _.isArguments(function() { return arguments; }());
* // => true
*
* _.isArguments([1, 2, 3]);

View File

@@ -31,7 +31,7 @@ var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray;
* _.isArray([1, 2, 3]);
* // => true
*
* (function() { return _.isArray(arguments); })();
* _.isArray(function() { return arguments; }());
* // => false
*/
var isArray = nativeIsArray || function(value) {

View File

@@ -30,7 +30,7 @@ var objToString = objectProto.toString;
*/
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

@@ -7,7 +7,7 @@ import isString from './isString';
import keys from '../object/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.
*

View File

@@ -39,7 +39,9 @@ import isStrictComparable from '../internal/isStrictComparable';
* var other = ['hi', 'goodbye'];
*
* _.isEqual(array, other, function(value, other) {
* return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
* if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
* return true;
* }
* });
* // => true
*/

View File

@@ -1,3 +1,4 @@
import baseIsFunction from '../internal/baseIsFunction';
import isNative from './isNative';
import root from '../internal/root';
@@ -33,19 +34,11 @@ var Uint8Array = isNative(Uint8Array = root.Uint8Array) && Uint8Array;
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
return typeof value == 'function' || false;
}
// Fallback for environments that return incorrect `typeof` operator results.
if (isFunction(/x/) || (Uint8Array && !isFunction(Uint8Array))) {
isFunction = function(value) {
// The use of `Object#toString` avoids issues with the `typeof` operator
// in older versions of Chrome and Safari which return 'function' for regexes
// and Safari 8 equivalents which return 'object' for typed array constructors.
return objToString.call(value) == funcTag;
};
}
var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
// The use of `Object#toString` avoids issues with the `typeof` operator
// in older versions of Chrome and Safari which return 'function' for regexes
// and Safari 8 equivalents which return 'object' for typed array constructors.
return objToString.call(value) == funcTag;
};
export default isFunction;

View File

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

114
lodash.js
View File

@@ -1,9 +1,9 @@
/**
* @license
* lodash 3.2.0 (Custom Build) <https://lodash.com/>
* lodash 3.5.0 (Custom Build) <https://lodash.com/>
* Build: `lodash modularize modern exports="es" -o ./`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
* Based on Underscore.js 1.8.2 <http://underscorejs.org/LICENSE>
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <https://lodash.com/license>
*/
@@ -13,6 +13,7 @@ import collection from './collection';
import date from './date';
import func from './function';
import lang from './lang';
import math from './math';
import number from './number';
import object from './object';
import string from './string';
@@ -21,7 +22,6 @@ import LazyWrapper from './internal/LazyWrapper';
import LodashWrapper from './internal/LodashWrapper';
import arrayEach from './internal/arrayEach';
import baseCallback from './internal/baseCallback';
import baseCreate from './internal/baseCreate';
import baseForOwn from './internal/baseForOwn';
import baseFunctions from './internal/baseFunctions';
import baseMatches from './internal/baseMatches';
@@ -30,6 +30,7 @@ import identity from './utility/identity';
import isArray from './lang/isArray';
import isObject from './lang/isObject';
import keys from './object/keys';
import last from './array/last';
import lazyClone from './internal/lazyClone';
import lazyReverse from './internal/lazyReverse';
import lazyValue from './internal/lazyValue';
@@ -39,14 +40,15 @@ import support from './support';
import thru from './chain/thru';
/** Used as the semantic version number. */
var VERSION = '3.2.0';
var VERSION = '3.5.0';
/** Used to indicate the type of lazy iteratees. */
var LAZY_FILTER_FLAG = 0,
LAZY_WHILE_FLAG = 2;
var LAZY_DROP_WHILE_FLAG = 0,
LAZY_MAP_FLAG = 2;
/** Used for native method references. */
var arrayProto = Array.prototype;
var arrayProto = Array.prototype,
stringProto = String.prototype;
/** Native method references. */
var floor = Math.floor,
@@ -56,13 +58,6 @@ var floor = Math.floor,
var nativeMax = Math.max,
nativeMin = Math.min;
// Ensure `new LodashWrapper` is an instance of `lodash`.
LodashWrapper.prototype = baseCreate(lodash.prototype);
// Ensure `new LazyWraper` is an instance of `LodashWrapper`
LazyWrapper.prototype = baseCreate(LodashWrapper.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
// wrap `_.mixin` so it works when provided only one argument
var mixin = (function(func) {
return function(object, source, options) {
@@ -158,6 +153,7 @@ lodash.shuffle = collection.shuffle;
lodash.slice = array.slice;
lodash.sortBy = collection.sortBy;
lodash.sortByAll = collection.sortByAll;
lodash.sortByOrder = collection.sortByOrder;
lodash.spread = func.spread;
lodash.take = array.take;
lodash.takeRight = array.takeRight;
@@ -200,6 +196,7 @@ lodash.unique = array.uniq;
mixin(lodash, lodash);
// Add functions that return unwrapped values when chaining.
lodash.add = math.add;
lodash.attempt = utility.attempt;
lodash.camelCase = string.camelCase;
lodash.capitalize = string.capitalize;
@@ -222,6 +219,7 @@ lodash.has = object.has;
lodash.identity = identity;
lodash.includes = collection.includes;
lodash.indexOf = array.indexOf;
lodash.inRange = number.inRange;
lodash.isArguments = lang.isArguments;
lodash.isArray = isArray;
lodash.isBoolean = lang.isBoolean;
@@ -244,10 +242,10 @@ lodash.isString = lang.isString;
lodash.isTypedArray = lang.isTypedArray;
lodash.isUndefined = lang.isUndefined;
lodash.kebabCase = string.kebabCase;
lodash.last = array.last;
lodash.last = last;
lodash.lastIndexOf = array.lastIndexOf;
lodash.max = collection.max;
lodash.min = collection.min;
lodash.max = math.max;
lodash.min = math.min;
lodash.noop = utility.noop;
lodash.now = date.now;
lodash.pad = string.pad;
@@ -266,6 +264,7 @@ lodash.sortedIndex = array.sortedIndex;
lodash.sortedLastIndex = array.sortedLastIndex;
lodash.startCase = string.startCase;
lodash.startsWith = string.startsWith;
lodash.sum = math.sum;
lodash.template = string.template;
lodash.trim = string.trim;
lodash.trimLeft = string.trimLeft;
@@ -326,33 +325,44 @@ arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'],
});
// Add `LazyWrapper` methods that accept an `iteratee` value.
arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
var isFilter = index == LAZY_FILTER_FLAG,
isWhile = index == LAZY_WHILE_FLAG;
arrayEach(['dropWhile', 'filter', 'map', 'takeWhile'], function(methodName, type) {
var isFilter = type != LAZY_MAP_FLAG,
isDropWhile = type == LAZY_DROP_WHILE_FLAG;
LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
var result = this.clone(),
filtered = result.__filtered__,
var filtered = this.__filtered__,
result = (filtered && isDropWhile) ? new LazyWrapper(this) : this.clone(),
iteratees = result.__iteratees__ || (result.__iteratees__ = []);
result.__filtered__ = filtered || isFilter || (isWhile && result.__dir__ < 0);
iteratees.push({ 'iteratee': baseCallback(iteratee, thisArg, 3), 'type': index });
iteratees.push({
'done': false,
'count': 0,
'index': 0,
'iteratee': baseCallback(iteratee, thisArg, 1),
'limit': -1,
'type': type
});
result.__filtered__ = filtered || isFilter;
return result;
};
});
// Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
arrayEach(['drop', 'take'], function(methodName, index) {
var countName = '__' + methodName + 'Count__',
whileName = methodName + 'While';
var whileName = methodName + 'While';
LazyWrapper.prototype[methodName] = function(n) {
n = n == null ? 1 : nativeMax(floor(n) || 0, 0);
var filtered = this.__filtered__,
result = (filtered && !index) ? this.dropWhile() : this.clone();
var result = this.clone();
if (result.__filtered__) {
var value = result[countName];
result[countName] = index ? nativeMin(value, n) : (value + n);
n = n == null ? 1 : nativeMax(floor(n) || 0, 0);
if (filtered) {
if (index) {
result.__takeCount__ = nativeMin(result.__takeCount__, n);
} else {
last(result.__iteratees__).limit = n;
}
} else {
var views = result.__views__ || (result.__views__ = []);
views.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
@@ -401,18 +411,10 @@ LazyWrapper.prototype.compact = function() {
return this.filter(identity);
};
LazyWrapper.prototype.dropWhile = function(predicate, thisArg) {
var done;
predicate = baseCallback(predicate, thisArg, 3);
return this.filter(function(value, index, array) {
return done || (done = !predicate(value, index, array));
});
};
LazyWrapper.prototype.reject = function(predicate, thisArg) {
predicate = baseCallback(predicate, thisArg, 3);
return this.filter(function(value, index, array) {
return !predicate(value, index, array);
predicate = baseCallback(predicate, thisArg, 1);
return this.filter(function(value) {
return !predicate(value);
});
};
@@ -434,16 +436,24 @@ LazyWrapper.prototype.toArray = function() {
// Add `LazyWrapper` methods to `lodash.prototype`.
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
var lodashFunc = lodash[methodName],
checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
retUnwrapped = /^(?:first|last)$/.test(methodName);
lodash.prototype[methodName] = function() {
var value = this.__wrapped__,
args = arguments,
var args = arguments,
length = args.length,
chainAll = this.__chain__,
value = this.__wrapped__,
isHybrid = !!this.__actions__.length,
isLazy = value instanceof LazyWrapper,
onlyLazy = isLazy && !isHybrid;
iteratee = args[0],
useLazy = isLazy || isArray(value);
if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
// avoid lazy use if the iteratee has a `length` other than `1`
isLazy = useLazy = false;
}
var onlyLazy = isLazy && !isHybrid;
if (retUnwrapped && !chainAll) {
return onlyLazy
? func.call(value)
@@ -454,7 +464,7 @@ baseForOwn(LazyWrapper.prototype, function(func, methodName) {
push.apply(otherArgs, args);
return lodashFunc.apply(lodash, otherArgs);
};
if (isLazy || isArray(value)) {
if (useLazy) {
var wrapper = onlyLazy ? value : new LazyWrapper(this),
result = func.apply(wrapper, args);
@@ -468,11 +478,11 @@ baseForOwn(LazyWrapper.prototype, function(func, methodName) {
};
});
// Add `Array.prototype` functions to `lodash.prototype`.
arrayEach(['concat', 'join', 'pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
var func = arrayProto[methodName],
// Add `Array` and `String` methods to `lodash.prototype`.
arrayEach(['concat', 'join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
retUnwrapped = /^(?:join|pop|shift)$/.test(methodName);
retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
lodash.prototype[methodName] = function() {
var args = arguments;
@@ -490,7 +500,7 @@ LazyWrapper.prototype.clone = lazyClone;
LazyWrapper.prototype.reverse = lazyReverse;
LazyWrapper.prototype.value = lazyValue;
// Add chaining functions to the lodash wrapper.
// Add chaining functions to the `lodash` wrapper.
lodash.prototype.chain = chain.wrapperChain;
lodash.prototype.commit = chain.commit;
lodash.prototype.plant = chain.plant;
@@ -498,7 +508,7 @@ lodash.prototype.reverse = chain.reverse;
lodash.prototype.toString = chain.toString;
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = chain.value;
// Add function aliases to the lodash wrapper.
// Add function aliases to the `lodash` wrapper.
lodash.prototype.collect = lodash.prototype.map;
lodash.prototype.head = lodash.prototype.first;
lodash.prototype.select = lodash.prototype.filter;

11
math.js Normal file
View File

@@ -0,0 +1,11 @@
import add from './math/add';
import max from './math/max';
import min from './math/min';
import sum from './math/sum';
export default {
'add': add,
'max': max,
'min': min,
'sum': sum
};

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