mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4881dda9d1 | ||
|
|
cc16e113c2 | ||
|
|
5dc85cc9a8 |
@@ -1,5 +1,5 @@
|
|||||||
Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
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/>
|
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
|||||||
30
README.md
30
README.md
@@ -1,4 +1,4 @@
|
|||||||
# lodash v3.2.0
|
# lodash v3.4.0
|
||||||
|
|
||||||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules.
|
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) modules.
|
||||||
|
|
||||||
@@ -24,11 +24,11 @@ In Node.js/io.js:
|
|||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
// or a method category
|
// or a method category
|
||||||
var array = require('lodash/array');
|
var array = require('lodash/array');
|
||||||
// or a method
|
// or a method (great for smaller builds with browserify/webpack)
|
||||||
var chunk = require('lodash/array/chunk');
|
var chunk = require('lodash/array/chunk');
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [package source](https://github.com/lodash/lodash/tree/3.2.0-npm) for more details.
|
See the [package source](https://github.com/lodash/lodash/tree/3.4.0-npm) for more details.
|
||||||
|
|
||||||
**Note:**<br>
|
**Note:**<br>
|
||||||
Don’t assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br>
|
Don’t assign values to the [special variable](http://nodejs.org/api/repl.html#repl_repl_features) `_` when in the REPL.<br>
|
||||||
@@ -39,8 +39,8 @@ Install [n_](https://www.npmjs.com/package/n_) for a REPL that includes lodash b
|
|||||||
lodash is also available in a variety of other builds & module formats.
|
lodash is also available in a variety of other builds & module formats.
|
||||||
|
|
||||||
* npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds
|
* npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds
|
||||||
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.2.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.2.0-amd) builds
|
* AMD modules for [modern](https://github.com/lodash/lodash/tree/3.4.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.4.0-amd) builds
|
||||||
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.2.0-es) build
|
* ES modules for the [modern](https://github.com/lodash/lodash/tree/3.4.0-es) build
|
||||||
|
|
||||||
## Further Reading
|
## Further Reading
|
||||||
|
|
||||||
@@ -57,6 +57,7 @@ lodash is also available in a variety of other builds & module formats.
|
|||||||
* Follows [semantic versioning](http://semver.org/) for releases
|
* Follows [semantic versioning](http://semver.org/) for releases
|
||||||
* [Lazily evaluated](http://filimanjaro.com/blog/2014/introducing-lazy-evaluation/) chaining
|
* [Lazily evaluated](http://filimanjaro.com/blog/2014/introducing-lazy-evaluation/) chaining
|
||||||
* [_(…)](https://lodash.com/docs#_) supports intuitive chaining
|
* [_(…)](https://lodash.com/docs#_) supports intuitive chaining
|
||||||
|
* [_.add](https://lodash.com/docs#add) for mathematical composition
|
||||||
* [_.ary](https://lodash.com/docs#ary) & [_.rearg](https://lodash.com/docs#rearg) to change function argument limits & order
|
* [_.ary](https://lodash.com/docs#ary) & [_.rearg](https://lodash.com/docs#rearg) to change function argument limits & order
|
||||||
* [_.at](https://lodash.com/docs#at) for cherry-picking collection values
|
* [_.at](https://lodash.com/docs#at) for cherry-picking collection values
|
||||||
* [_.attempt](https://lodash.com/docs#attempt) to execute functions which may error without a try-catch
|
* [_.attempt](https://lodash.com/docs#attempt) to execute functions which may error without a try-catch
|
||||||
@@ -69,33 +70,31 @@ lodash is also available in a variety of other builds & module formats.
|
|||||||
* [_.curry](https://lodash.com/docs#curry) & [_.curryRight](https://lodash.com/docs#curryRight) for creating [curried](http://hughfdjackson.com/javascript/why-curry-helps/) functions
|
* [_.curry](https://lodash.com/docs#curry) & [_.curryRight](https://lodash.com/docs#curryRight) for creating [curried](http://hughfdjackson.com/javascript/why-curry-helps/) functions
|
||||||
* [_.debounce](https://lodash.com/docs#debounce) & [_.throttle](https://lodash.com/docs#throttle) are cancelable & accept options for more control
|
* [_.debounce](https://lodash.com/docs#debounce) & [_.throttle](https://lodash.com/docs#throttle) are cancelable & accept options for more control
|
||||||
* [_.fill](https://lodash.com/docs#fill) to fill arrays with values
|
* [_.fill](https://lodash.com/docs#fill) to fill arrays with values
|
||||||
* [_.findIndex](https://lodash.com/docs#findIndex) & [_.findKey](https://lodash.com/docs#findKey) for finding indexes & keys
|
* [_.findKey](https://lodash.com/docs#findKey) for finding keys
|
||||||
* [_.flow](https://lodash.com/docs#flow) to complement [_.flowRight](https://lodash.com/docs#flowRight) (a.k.a `_.compose`)
|
* [_.flow](https://lodash.com/docs#flow) to complement [_.flowRight](https://lodash.com/docs#flowRight) (a.k.a `_.compose`)
|
||||||
* [_.forEach](https://lodash.com/docs#forEach) supports exiting early
|
* [_.forEach](https://lodash.com/docs#forEach) supports exiting early
|
||||||
* [_.forIn](https://lodash.com/docs#forIn) for iterating all enumerable properties
|
* [_.forIn](https://lodash.com/docs#forIn) for iterating all enumerable properties
|
||||||
* [_.forOwn](https://lodash.com/docs#forOwn) for iterating own properties
|
* [_.forOwn](https://lodash.com/docs#forOwn) for iterating own properties
|
||||||
* [_.includes](https://lodash.com/docs#includes) accepts a `fromIndex`
|
* [_.inRange](https://lodash.com/docs#inRange) for checking whether a number is within a given range
|
||||||
* [_.isError](https://lodash.com/docs#isError) to check for error objects
|
|
||||||
* [_.isNative](https://lodash.com/docs#isNative) to check for native functions
|
* [_.isNative](https://lodash.com/docs#isNative) to check for native functions
|
||||||
* [_.isPlainObject](https://lodash.com/docs#isPlainObject) & [_.toPlainObject](https://lodash.com/docs#toPlainObject) to check for & convert to `Object` objects
|
* [_.isPlainObject](https://lodash.com/docs#isPlainObject) & [_.toPlainObject](https://lodash.com/docs#toPlainObject) to check for & convert to `Object` objects
|
||||||
* [_.isTypedArray](https://lodash.com/docs#isTypedArray) to check for typed arrays
|
* [_.isTypedArray](https://lodash.com/docs#isTypedArray) to check for typed arrays
|
||||||
* [_.keysIn](https://lodash.com/docs#keysIn) & [_.valuesIn](https://lodash.com/docs#valuesIn) for getting keys & values of all enumerable properties
|
|
||||||
* [_.mapValues](https://lodash.com/docs#mapValues) for [mapping](https://lodash.com/docs#map) values to an object
|
|
||||||
* [_.matches](https://lodash.com/docs#matches) supports deep object comparisons
|
* [_.matches](https://lodash.com/docs#matches) supports deep object comparisons
|
||||||
* [_.matchesProperty](https://lodash.com/docs#matchesProperty) to complement [_.matches](https://lodash.com/docs#matches) & [_.property](https://lodash.com/docs#property)
|
* [_.matchesProperty](https://lodash.com/docs#matchesProperty) to complement [_.matches](https://lodash.com/docs#matches) & [_.property](https://lodash.com/docs#property)
|
||||||
* [_.merge](https://lodash.com/docs#merge) for a deep [_.extend](https://lodash.com/docs#extend)
|
* [_.merge](https://lodash.com/docs#merge) for a deep [_.extend](https://lodash.com/docs#extend)
|
||||||
* [_.parseInt](https://lodash.com/docs#parseInt) for consistent cross-environment behavior
|
* [_.parseInt](https://lodash.com/docs#parseInt) for consistent cross-environment behavior
|
||||||
* [_.propertyOf](https://lodash.com/docs#propertyOf) to complement [_.property](https://lodash.com/docs#property)
|
|
||||||
* [_.pull](https://lodash.com/docs#pull), [_.pullAt](https://lodash.com/docs#pullAt), & [_.remove](https://lodash.com/docs#remove) for mutating arrays
|
* [_.pull](https://lodash.com/docs#pull), [_.pullAt](https://lodash.com/docs#pullAt), & [_.remove](https://lodash.com/docs#remove) for mutating arrays
|
||||||
* [_.random](https://lodash.com/docs#random) supports returning floating-point numbers
|
* [_.random](https://lodash.com/docs#random) supports returning floating-point numbers
|
||||||
* [_.runInContext](https://lodash.com/docs#runInContext) for collisionless mixins & easier mocking
|
* [_.runInContext](https://lodash.com/docs#runInContext) for collisionless mixins & easier mocking
|
||||||
* [_.slice](https://lodash.com/docs#slice) for creating subsets of array-like values
|
* [_.slice](https://lodash.com/docs#slice) for creating subsets of array-like values
|
||||||
* [_.sortByAll](https://lodash.com/docs#sortBy) for sorting by multiple properties
|
* [_.sortByAll](https://lodash.com/docs#sortByAll) & [_.sortByOrder](https://lodash.com/docs#sortByOrder) for sorting by multiple properties & orders
|
||||||
* [_.spread](https://lodash.com/docs#spread) for creating a function to spread an array of arguments to another
|
* [_.spread](https://lodash.com/docs#spread) for creating a function to spread an array of arguments to another
|
||||||
|
* [_.sum](https://lodash.com/docs#sum) to get the sum of values
|
||||||
* [_.support](https://lodash.com/docs#support) for flagging environment features
|
* [_.support](https://lodash.com/docs#support) for flagging environment features
|
||||||
* [_.template](https://lodash.com/docs#template) supports [*“imports”*](https://lodash.com/docs#templateSettings-imports) options & [ES template delimiters](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
|
* [_.template](https://lodash.com/docs#template) supports [*“imports”*](https://lodash.com/docs#templateSettings-imports) options & [ES template delimiters](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-template-literal-lexical-components)
|
||||||
* [_.transform](https://lodash.com/docs#transform) as a powerful alternative to [_.reduce](https://lodash.com/docs#reduce) for transforming objects
|
* [_.transform](https://lodash.com/docs#transform) as a powerful alternative to [_.reduce](https://lodash.com/docs#reduce) for transforming objects
|
||||||
* [_.xor](https://lodash.com/docs#xor) to complement [_.difference](https://lodash.com/docs#difference), [_.intersection](https://lodash.com/docs#intersection), & [_.union](https://lodash.com/docs#union)
|
* [_.xor](https://lodash.com/docs#xor) to complement [_.difference](https://lodash.com/docs#difference), [_.intersection](https://lodash.com/docs#intersection), & [_.union](https://lodash.com/docs#union)
|
||||||
|
* [_.valuesIn](https://lodash.com/docs#valuesIn) for getting values of all enumerable properties
|
||||||
* [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), &
|
* [_.bind](https://lodash.com/docs#bind), [_.curry](https://lodash.com/docs#curry), [_.partial](https://lodash.com/docs#partial), &
|
||||||
[more](https://lodash.com/docs "_.bindKey, _.curryRight, _.partialRight") support customizable argument placeholders
|
[more](https://lodash.com/docs "_.bindKey, _.curryRight, _.partialRight") support customizable argument placeholders
|
||||||
* [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), &
|
* [_.capitalize](https://lodash.com/docs#capitalize), [_.trim](https://lodash.com/docs#trim), &
|
||||||
@@ -104,8 +103,8 @@ lodash is also available in a variety of other builds & module formats.
|
|||||||
[more](https://lodash.com/docs "_.assign, _.cloneDeep, _.merge") accept callbacks
|
[more](https://lodash.com/docs "_.assign, _.cloneDeep, _.merge") accept callbacks
|
||||||
* [_.dropWhile](https://lodash.com/docs#dropWhile), [_.takeWhile](https://lodash.com/docs#takeWhile), &
|
* [_.dropWhile](https://lodash.com/docs#dropWhile), [_.takeWhile](https://lodash.com/docs#takeWhile), &
|
||||||
[more](https://lodash.com/docs "_.drop, _.dropRightWhile, _.take, _.takeRightWhile") to complement [_.first](https://lodash.com/docs#first), [_.initial](https://lodash.com/docs#initial), [_.last](https://lodash.com/docs#last), & [_.rest](https://lodash.com/docs#rest)
|
[more](https://lodash.com/docs "_.drop, _.dropRightWhile, _.take, _.takeRightWhile") to complement [_.first](https://lodash.com/docs#first), [_.initial](https://lodash.com/docs#initial), [_.last](https://lodash.com/docs#last), & [_.rest](https://lodash.com/docs#rest)
|
||||||
* [_.findLast](https://lodash.com/docs#findLast), [_.findLastIndex](https://lodash.com/docs#findLastIndex), &
|
* [_.findLast](https://lodash.com/docs#findLast), [_.findLastKey](https://lodash.com/docs#findLastKey), &
|
||||||
[more](https://lodash.com/docs "_.findLastKey, _.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.partialRight") right-associative methods
|
[more](https://lodash.com/docs "_.flowRight, _.forEachRight, _.forInRight, _.forOwnRight, _.partialRight") right-associative methods
|
||||||
* [_.includes](https://lodash.com/docs#includes), [_.toArray](https://lodash.com/docs#toArray), &
|
* [_.includes](https://lodash.com/docs#includes), [_.toArray](https://lodash.com/docs#toArray), &
|
||||||
[more](https://lodash.com/docs "_.at, _.countBy, _.every, _.filter, _.find, _.findLast, _.forEach, _.forEachRight, _.groupBy, _.indexBy, _.invoke, _.map, _.max, _.min, _.partition, _.pluck, _.reduce, _.reduceRight, _.reject, _.shuffle, _.size, _.some, _.sortBy") accept strings
|
[more](https://lodash.com/docs "_.at, _.countBy, _.every, _.filter, _.find, _.findLast, _.forEach, _.forEachRight, _.groupBy, _.indexBy, _.invoke, _.map, _.max, _.min, _.partition, _.pluck, _.reduce, _.reduceRight, _.reject, _.shuffle, _.size, _.some, _.sortBy") accept strings
|
||||||
* [_#commit](https://lodash.com/docs#prototype-commit) & [_#plant](https://lodash.com/docs#prototype-plant) for working with chain sequences
|
* [_#commit](https://lodash.com/docs#prototype-commit) & [_#plant](https://lodash.com/docs#prototype-plant) for working with chain sequences
|
||||||
@@ -113,6 +112,5 @@ lodash is also available in a variety of other builds & module formats.
|
|||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
Tested in Chrome 39-40, Firefox 34-35, IE 6-11, Opera 26-27, Safari 5-8, io.js 1.2.0, Node.js 0.8.28, 0.10.36, & 0.12.0, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5.
|
Tested in Chrome 40-41, Firefox 35-36, IE 6-11, Opera 26-27, Safari 5-8, io.js 1.4.3, Node.js 0.8.28, 0.10.36, & 0.12.0, PhantomJS 1.9.8, RingoJS 0.11, & Rhino 1.7RC5.
|
||||||
|
|
||||||
Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Special thanks to [Sauce Labs](https://saucelabs.com/) for providing automated browser testing.
|
Automated [browser](https://saucelabs.com/u/lodash) & [CI](https://travis-ci.org/lodash/lodash/) test runs are available. Special thanks to [Sauce Labs](https://saucelabs.com/) for providing automated browser testing.
|
||||||
|
|||||||
@@ -20,20 +20,21 @@ var baseDifference = require('../internal/baseDifference'),
|
|||||||
* @returns {Array} Returns the new array of filtered values.
|
* @returns {Array} Returns the new array of filtered values.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.difference([1, 2, 3], [5, 2, 10]);
|
* _.difference([1, 2, 3], [4, 2]);
|
||||||
* // => [1, 3]
|
* // => [1, 3]
|
||||||
*/
|
*/
|
||||||
function difference() {
|
function difference() {
|
||||||
var index = -1,
|
var args = arguments,
|
||||||
length = arguments.length;
|
index = -1,
|
||||||
|
length = args.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var value = arguments[index];
|
var value = args[index];
|
||||||
if (isArray(value) || isArguments(value)) {
|
if (isArray(value) || isArguments(value)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return baseDifference(value, baseFlatten(arguments, false, true, ++index));
|
return baseDifference(value, baseFlatten(args, false, true, ++index));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = difference;
|
module.exports = difference;
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* @returns {Array} Returns the slice of `array`.
|
* @returns {Array} Returns the slice of `array`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.dropRightWhile([1, 2, 3], function(n) { return n > 1; });
|
* _.dropRightWhile([1, 2, 3], function(n) {
|
||||||
|
* return n > 1;
|
||||||
|
* });
|
||||||
* // => [1]
|
* // => [1]
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
@@ -37,7 +39,7 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* // using the `_.matches` callback shorthand
|
* // using the `_.matches` callback shorthand
|
||||||
* _.pluck(_.dropRightWhile(users, { 'user': pebbles, 'active': false }), 'user');
|
* _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
|
||||||
* // => ['barney', 'fred']
|
* // => ['barney', 'fred']
|
||||||
*
|
*
|
||||||
* // using the `_.matchesProperty` callback shorthand
|
* // using the `_.matchesProperty` callback shorthand
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* @returns {Array} Returns the slice of `array`.
|
* @returns {Array} Returns the slice of `array`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.dropWhile([1, 2, 3], function(n) { return n < 3; });
|
* _.dropWhile([1, 2, 3], function(n) {
|
||||||
|
* return n < 3;
|
||||||
|
* });
|
||||||
* // => [3]
|
* // => [3]
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ var baseCallback = require('../internal/baseCallback');
|
|||||||
* { 'user': 'pebbles', 'active': true }
|
* { 'user': 'pebbles', 'active': true }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* _.findIndex(users, function(chr) { return chr.user == 'barney'; });
|
* _.findIndex(users, function(chr) {
|
||||||
|
* return chr.user == 'barney';
|
||||||
|
* });
|
||||||
* // => 0
|
* // => 0
|
||||||
*
|
*
|
||||||
* // using the `_.matches` callback shorthand
|
* // using the `_.matches` callback shorthand
|
||||||
|
|||||||
@@ -31,16 +31,18 @@ var baseCallback = require('../internal/baseCallback');
|
|||||||
* { 'user': 'pebbles', 'active': false }
|
* { 'user': 'pebbles', 'active': false }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; });
|
* _.findLastIndex(users, function(chr) {
|
||||||
|
* return chr.user == 'pebbles';
|
||||||
|
* });
|
||||||
* // => 2
|
* // => 2
|
||||||
*
|
*
|
||||||
* // using the `_.matches` callback shorthand
|
* // using the `_.matches` callback shorthand
|
||||||
* _.findLastIndex(users, { user': 'barney', 'active': true });
|
* _.findLastIndex(users, { 'user': 'barney', 'active': true });
|
||||||
* // => 0
|
* // => 0
|
||||||
*
|
*
|
||||||
* // using the `_.matchesProperty` callback shorthand
|
* // using the `_.matchesProperty` callback shorthand
|
||||||
* _.findLastIndex(users, 'active', false);
|
* _.findLastIndex(users, 'active', false);
|
||||||
* // => 1
|
* // => 2
|
||||||
*
|
*
|
||||||
* // using the `_.property` callback shorthand
|
* // using the `_.property` callback shorthand
|
||||||
* _.findLastIndex(users, 'active');
|
* _.findLastIndex(users, 'active');
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ var baseFlatten = require('../internal/baseFlatten'),
|
|||||||
* @returns {Array} Returns the new flattened array.
|
* @returns {Array} Returns the new flattened array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.flatten([1, [2], [3, [[4]]]]);
|
* _.flatten([1, [2, 3, [4]]]);
|
||||||
* // => [1, 2, 3, [[4]]];
|
* // => [1, 2, 3, [4]];
|
||||||
*
|
*
|
||||||
* // using `isDeep`
|
* // using `isDeep`
|
||||||
* _.flatten([1, [2], [3, [[4]]]], true);
|
* _.flatten([1, [2, 3, [4]]], true);
|
||||||
* // => [1, 2, 3, 4];
|
* // => [1, 2, 3, 4];
|
||||||
*/
|
*/
|
||||||
function flatten(array, isDeep, guard) {
|
function flatten(array, isDeep, guard) {
|
||||||
@@ -26,7 +26,7 @@ function flatten(array, isDeep, guard) {
|
|||||||
if (guard && isIterateeCall(array, isDeep, guard)) {
|
if (guard && isIterateeCall(array, isDeep, guard)) {
|
||||||
isDeep = false;
|
isDeep = false;
|
||||||
}
|
}
|
||||||
return length ? baseFlatten(array, isDeep) : [];
|
return length ? baseFlatten(array, isDeep, false, 0) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = flatten;
|
module.exports = flatten;
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ var baseFlatten = require('../internal/baseFlatten');
|
|||||||
* @returns {Array} Returns the new flattened array.
|
* @returns {Array} Returns the new flattened array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.flattenDeep([1, [2], [3, [[4]]]]);
|
* _.flattenDeep([1, [2, 3, [4]]]);
|
||||||
* // => [1, 2, 3, 4];
|
* // => [1, 2, 3, 4];
|
||||||
*/
|
*/
|
||||||
function flattenDeep(array) {
|
function flattenDeep(array) {
|
||||||
var length = array ? array.length : 0;
|
var length = array ? array.length : 0;
|
||||||
return length ? baseFlatten(array, true) : [];
|
return length ? baseFlatten(array, true, false, 0) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = flattenDeep;
|
module.exports = flattenDeep;
|
||||||
|
|||||||
@@ -25,15 +25,15 @@ var nativeMax = Math.max;
|
|||||||
* @returns {number} Returns the index of the matched value, else `-1`.
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.indexOf([1, 2, 3, 1, 2, 3], 2);
|
* _.indexOf([1, 2, 1, 2], 2);
|
||||||
* // => 1
|
* // => 1
|
||||||
*
|
*
|
||||||
* // using `fromIndex`
|
* // using `fromIndex`
|
||||||
* _.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
|
* _.indexOf([1, 2, 1, 2], 2, 2);
|
||||||
* // => 4
|
* // => 3
|
||||||
*
|
*
|
||||||
* // performing a binary search
|
* // performing a binary search
|
||||||
* _.indexOf([4, 4, 5, 5, 6, 6], 5, true);
|
* _.indexOf([1, 1, 2, 2], 2, true);
|
||||||
* // => 2
|
* // => 2
|
||||||
*/
|
*/
|
||||||
function indexOf(array, value, fromIndex) {
|
function indexOf(array, value, fromIndex) {
|
||||||
@@ -42,14 +42,14 @@ function indexOf(array, value, fromIndex) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (typeof fromIndex == 'number') {
|
if (typeof fromIndex == 'number') {
|
||||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
|
||||||
} else if (fromIndex) {
|
} else if (fromIndex) {
|
||||||
var index = binaryIndex(array, value),
|
var index = binaryIndex(array, value),
|
||||||
other = array[index];
|
other = array[index];
|
||||||
|
|
||||||
return (value === value ? value === other : other !== other) ? index : -1;
|
return (value === value ? value === other : other !== other) ? index : -1;
|
||||||
}
|
}
|
||||||
return baseIndexOf(array, value, fromIndex);
|
return baseIndexOf(array, value, fromIndex || 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = indexOf;
|
module.exports = indexOf;
|
||||||
|
|||||||
@@ -19,9 +19,8 @@ var baseIndexOf = require('../internal/baseIndexOf'),
|
|||||||
* @param {...Array} [arrays] The arrays to inspect.
|
* @param {...Array} [arrays] The arrays to inspect.
|
||||||
* @returns {Array} Returns the new array of shared values.
|
* @returns {Array} Returns the new array of shared values.
|
||||||
* @example
|
* @example
|
||||||
*
|
* _.intersection([1, 2], [4, 2], [2, 1]);
|
||||||
* _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]);
|
* // => [2]
|
||||||
* // => [1, 2]
|
|
||||||
*/
|
*/
|
||||||
function intersection() {
|
function intersection() {
|
||||||
var args = [],
|
var args = [],
|
||||||
@@ -35,7 +34,7 @@ function intersection() {
|
|||||||
var value = arguments[argsIndex];
|
var value = arguments[argsIndex];
|
||||||
if (isArray(value) || isArguments(value)) {
|
if (isArray(value) || isArguments(value)) {
|
||||||
args.push(value);
|
args.push(value);
|
||||||
caches.push(isCommon && value.length >= 120 && createCache(argsIndex && value));
|
caches.push((isCommon && value.length >= 120) ? createCache(argsIndex && value) : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argsLength = args.length;
|
argsLength = args.length;
|
||||||
@@ -48,11 +47,11 @@ function intersection() {
|
|||||||
outer:
|
outer:
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
value = array[index];
|
value = array[index];
|
||||||
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value)) < 0) {
|
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
|
||||||
argsIndex = argsLength;
|
argsIndex = argsLength;
|
||||||
while (--argsIndex) {
|
while (--argsIndex) {
|
||||||
var cache = caches[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;
|
continue outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,15 +19,15 @@ var nativeMax = Math.max,
|
|||||||
* @returns {number} Returns the index of the matched value, else `-1`.
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
|
* _.lastIndexOf([1, 2, 1, 2], 2);
|
||||||
* // => 4
|
* // => 3
|
||||||
*
|
*
|
||||||
* // using `fromIndex`
|
* // using `fromIndex`
|
||||||
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
|
* _.lastIndexOf([1, 2, 1, 2], 2, 2);
|
||||||
* // => 1
|
* // => 1
|
||||||
*
|
*
|
||||||
* // performing a binary search
|
* // performing a binary search
|
||||||
* _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true);
|
* _.lastIndexOf([1, 1, 2, 2], 2, true);
|
||||||
* // => 3
|
* // => 3
|
||||||
*/
|
*/
|
||||||
function lastIndexOf(array, value, fromIndex) {
|
function lastIndexOf(array, value, fromIndex) {
|
||||||
|
|||||||
@@ -25,22 +25,25 @@ var splice = arrayProto.splice;
|
|||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var array = [1, 2, 3, 1, 2, 3];
|
* var array = [1, 2, 3, 1, 2, 3];
|
||||||
|
*
|
||||||
* _.pull(array, 2, 3);
|
* _.pull(array, 2, 3);
|
||||||
* console.log(array);
|
* console.log(array);
|
||||||
* // => [1, 1]
|
* // => [1, 1]
|
||||||
*/
|
*/
|
||||||
function pull() {
|
function pull() {
|
||||||
var array = arguments[0];
|
var args = arguments,
|
||||||
|
array = args[0];
|
||||||
|
|
||||||
if (!(array && array.length)) {
|
if (!(array && array.length)) {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
var index = 0,
|
var index = 0,
|
||||||
indexOf = baseIndexOf,
|
indexOf = baseIndexOf,
|
||||||
length = arguments.length;
|
length = args.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var fromIndex = 0,
|
var fromIndex = 0,
|
||||||
value = arguments[index];
|
value = args[index];
|
||||||
|
|
||||||
while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
|
while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
|
||||||
splice.call(array, fromIndex, 1);
|
splice.call(array, fromIndex, 1);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ var baseFlatten = require('../internal/baseFlatten'),
|
|||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var array = [5, 10, 15, 20];
|
* var array = [5, 10, 15, 20];
|
||||||
* var evens = _.pullAt(array, [1, 3]);
|
* var evens = _.pullAt(array, 1, 3);
|
||||||
*
|
*
|
||||||
* console.log(array);
|
* console.log(array);
|
||||||
* // => [5, 15]
|
* // => [5, 15]
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ var splice = arrayProto.splice;
|
|||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var array = [1, 2, 3, 4];
|
* var array = [1, 2, 3, 4];
|
||||||
* var evens = _.remove(array, function(n) { return n % 2 == 0; });
|
* var evens = _.remove(array, function(n) {
|
||||||
|
* return n % 2 == 0;
|
||||||
|
* });
|
||||||
*
|
*
|
||||||
* console.log(array);
|
* console.log(array);
|
||||||
* // => [1, 3]
|
* // => [1, 3]
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* _.sortedIndex([30, 50], 40);
|
* _.sortedIndex([30, 50], 40);
|
||||||
* // => 1
|
* // => 1
|
||||||
*
|
*
|
||||||
* _.sortedIndex([4, 4, 5, 5, 6, 6], 5);
|
* _.sortedIndex([4, 4, 5, 5], 5);
|
||||||
* // => 2
|
* // => 2
|
||||||
*
|
*
|
||||||
* var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
|
* var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* into `array`.
|
* into `array`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5);
|
* _.sortedLastIndex([4, 4, 5, 5], 5);
|
||||||
* // => 4
|
* // => 4
|
||||||
*/
|
*/
|
||||||
function sortedLastIndex(array, value, iteratee, thisArg) {
|
function sortedLastIndex(array, value, iteratee, thisArg) {
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* @returns {Array} Returns the slice of `array`.
|
* @returns {Array} Returns the slice of `array`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.takeRightWhile([1, 2, 3], function(n) { return n > 1; });
|
* _.takeRightWhile([1, 2, 3], function(n) {
|
||||||
|
* return n > 1;
|
||||||
|
* });
|
||||||
* // => [2, 3]
|
* // => [2, 3]
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* @returns {Array} Returns the slice of `array`.
|
* @returns {Array} Returns the slice of `array`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.takeWhile([1, 2, 3], function(n) { return n < 3; });
|
* _.takeWhile([1, 2, 3], function(n) {
|
||||||
|
* return n < 3;
|
||||||
|
* });
|
||||||
* // => [1, 2]
|
* // => [1, 2]
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ var baseFlatten = require('../internal/baseFlatten'),
|
|||||||
* @returns {Array} Returns the new array of combined values.
|
* @returns {Array} Returns the new array of combined values.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]);
|
* _.union([1, 2], [4, 2], [2, 1]);
|
||||||
* // => [1, 2, 3, 5, 4]
|
* // => [1, 2, 4]
|
||||||
*/
|
*/
|
||||||
function union() {
|
function union() {
|
||||||
return baseUniq(baseFlatten(arguments, false, true));
|
return baseUniq(baseFlatten(arguments, false, true, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = union;
|
module.exports = union;
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* // => [1, 2]
|
* // => [1, 2]
|
||||||
*
|
*
|
||||||
* // using an iteratee function
|
* // using an iteratee function
|
||||||
* _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math);
|
* _.uniq([1, 2.5, 1.5, 2], function(n) {
|
||||||
|
* return this.floor(n);
|
||||||
|
* }, Math);
|
||||||
* // => [1, 2.5]
|
* // => [1, 2.5]
|
||||||
*
|
*
|
||||||
* // using the `_.property` callback shorthand
|
* // using the `_.property` callback shorthand
|
||||||
@@ -58,8 +60,7 @@ function uniq(array, isSorted, iteratee, thisArg) {
|
|||||||
if (!length) {
|
if (!length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
// Juggle arguments.
|
if (isSorted != null && typeof isSorted != 'boolean') {
|
||||||
if (typeof isSorted != 'boolean' && isSorted != null) {
|
|
||||||
thisArg = iteratee;
|
thisArg = iteratee;
|
||||||
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
|
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
|
||||||
isSorted = false;
|
isSorted = false;
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ var baseDifference = require('../internal/baseDifference'),
|
|||||||
* @returns {Array} Returns the new array of filtered values.
|
* @returns {Array} Returns the new array of filtered values.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
|
* _.without([1, 2, 1, 3], 1, 2);
|
||||||
* // => [2, 3, 4]
|
* // => [3]
|
||||||
*/
|
*/
|
||||||
function without(array) {
|
function without(array) {
|
||||||
return baseDifference(array, baseSlice(arguments, 1));
|
return baseDifference(array, baseSlice(arguments, 1));
|
||||||
|
|||||||
@@ -15,11 +15,8 @@ var baseDifference = require('../internal/baseDifference'),
|
|||||||
* @returns {Array} Returns the new array of values.
|
* @returns {Array} Returns the new array of values.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.xor([1, 2, 3], [5, 2, 1, 4]);
|
* _.xor([1, 2], [4, 2]);
|
||||||
* // => [3, 5, 4]
|
* // => [1, 4]
|
||||||
*
|
|
||||||
* _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
|
|
||||||
* // => [1, 4, 5]
|
|
||||||
*/
|
*/
|
||||||
function xor() {
|
function xor() {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ var lodash = require('./lodash');
|
|||||||
*
|
*
|
||||||
* var youngest = _.chain(users)
|
* var youngest = _.chain(users)
|
||||||
* .sortBy('age')
|
* .sortBy('age')
|
||||||
* .map(function(chr) { return chr.user + ' is ' + chr.age; })
|
* .map(function(chr) {
|
||||||
|
* return chr.user + ' is ' + chr.age;
|
||||||
|
* })
|
||||||
* .first()
|
* .first()
|
||||||
* .value();
|
* .value();
|
||||||
* // => 'pebbles is 1'
|
* // => 'pebbles is 1'
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var LazyWrapper = require('../internal/LazyWrapper'),
|
var LazyWrapper = require('../internal/LazyWrapper'),
|
||||||
LodashWrapper = require('../internal/LodashWrapper'),
|
LodashWrapper = require('../internal/LodashWrapper'),
|
||||||
|
baseLodash = require('../internal/baseLodash'),
|
||||||
isArray = require('../lang/isArray'),
|
isArray = require('../lang/isArray'),
|
||||||
isObjectLike = require('../internal/isObjectLike'),
|
isObjectLike = require('../internal/isObjectLike'),
|
||||||
wrapperClone = require('../internal/wrapperClone');
|
wrapperClone = require('../internal/wrapperClone');
|
||||||
@@ -48,26 +49,26 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
|||||||
* `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
* `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
||||||
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
|
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
|
||||||
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
|
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
|
||||||
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `splice`, `spread`,
|
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `sortByOrder`, `splice`,
|
||||||
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
|
* `spread`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`,
|
||||||
* `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
|
* `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, `transform`,
|
||||||
* `unshift`, `unzip`, `values`, `valuesIn`, `where`, `without`, `wrap`, `xor`,
|
* `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, `where`,
|
||||||
* `zip`, and `zipObject`
|
* `without`, `wrap`, `xor`, `zip`, and `zipObject`
|
||||||
*
|
*
|
||||||
* The wrapper methods that are **not** chainable by default are:
|
* 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`,
|
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
|
||||||
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
|
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
|
||||||
* `identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`,
|
* `identity`, `includes`, `indexOf`, `inRange`, `isArguments`, `isArray`,
|
||||||
* `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`,
|
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`,
|
||||||
* `isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
|
* `isFinite`,`isFunction`, `isMatch`, `isNative`, `isNaN`, `isNull`, `isNumber`,
|
||||||
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
|
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`,
|
||||||
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
|
* `isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`,
|
||||||
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
|
* `noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`,
|
||||||
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
|
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`,
|
||||||
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
|
* `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`,
|
||||||
* `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`,
|
* `startCase`, `startsWith`, `sum`, `template`, `trim`, `trimLeft`,
|
||||||
* `trunc`, `unescape`, `uniqueId`, `value`, and `words`
|
* `trimRight`, `trunc`, `unescape`, `uniqueId`, `value`, and `words`
|
||||||
*
|
*
|
||||||
* The wrapper method `sample` will return a wrapped value when `n` is provided,
|
* The wrapper method `sample` will return a wrapped value when `n` is provided,
|
||||||
* otherwise an unwrapped value is returned.
|
* otherwise an unwrapped value is returned.
|
||||||
@@ -82,11 +83,15 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
|||||||
* var wrapped = _([1, 2, 3]);
|
* var wrapped = _([1, 2, 3]);
|
||||||
*
|
*
|
||||||
* // returns an unwrapped value
|
* // returns an unwrapped value
|
||||||
* wrapped.reduce(function(sum, n) { return sum + n; });
|
* wrapped.reduce(function(sum, n) {
|
||||||
|
* return sum + n;
|
||||||
|
* });
|
||||||
* // => 6
|
* // => 6
|
||||||
*
|
*
|
||||||
* // returns a wrapped value
|
* // returns a wrapped value
|
||||||
* var squares = wrapped.map(function(n) { return n * n; });
|
* var squares = wrapped.map(function(n) {
|
||||||
|
* return n * n;
|
||||||
|
* });
|
||||||
*
|
*
|
||||||
* _.isArray(squares);
|
* _.isArray(squares);
|
||||||
* // => false
|
* // => false
|
||||||
@@ -106,4 +111,7 @@ function lodash(value) {
|
|||||||
return new LodashWrapper(value);
|
return new LodashWrapper(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure wrappers are instances of `baseLodash`.
|
||||||
|
lodash.prototype = baseLodash.prototype;
|
||||||
|
|
||||||
module.exports = lodash;
|
module.exports = lodash;
|
||||||
|
|||||||
@@ -14,7 +14,9 @@
|
|||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _([1, 2, 3])
|
* _([1, 2, 3])
|
||||||
* .tap(function(array) { array.pop(); })
|
* .tap(function(array) {
|
||||||
|
* array.pop();
|
||||||
|
* })
|
||||||
* .reverse()
|
* .reverse()
|
||||||
* .value();
|
* .value();
|
||||||
* // => [2, 1]
|
* // => [2, 1]
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
*
|
*
|
||||||
* _([1, 2, 3])
|
* _([1, 2, 3])
|
||||||
* .last()
|
* .last()
|
||||||
* .thru(function(value) { return [value]; })
|
* .thru(function(value) {
|
||||||
|
* return [value];
|
||||||
|
* })
|
||||||
* .value();
|
* .value();
|
||||||
* // => [3]
|
* // => [3]
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var LodashWrapper = require('../internal/LodashWrapper'),
|
var baseLodash = require('../internal/baseLodash'),
|
||||||
wrapperClone = require('../internal/wrapperClone');
|
wrapperClone = require('../internal/wrapperClone');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,7 +28,7 @@ function wrapperPlant(value) {
|
|||||||
var result,
|
var result,
|
||||||
parent = this;
|
parent = this;
|
||||||
|
|
||||||
while (parent instanceof LodashWrapper) {
|
while (parent instanceof baseLodash) {
|
||||||
var clone = wrapperClone(parent);
|
var clone = wrapperClone(parent);
|
||||||
if (result) {
|
if (result) {
|
||||||
previous.__wrapped__ = clone;
|
previous.__wrapped__ = clone;
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ module.exports = {
|
|||||||
'inject': require('./collection/inject'),
|
'inject': require('./collection/inject'),
|
||||||
'invoke': require('./collection/invoke'),
|
'invoke': require('./collection/invoke'),
|
||||||
'map': require('./collection/map'),
|
'map': require('./collection/map'),
|
||||||
'max': require('./collection/max'),
|
'max': require('./math/max'),
|
||||||
'min': require('./collection/min'),
|
'min': require('./math/min'),
|
||||||
'partition': require('./collection/partition'),
|
'partition': require('./collection/partition'),
|
||||||
'pluck': require('./collection/pluck'),
|
'pluck': require('./collection/pluck'),
|
||||||
'reduce': require('./collection/reduce'),
|
'reduce': require('./collection/reduce'),
|
||||||
@@ -38,5 +38,7 @@ module.exports = {
|
|||||||
'some': require('./collection/some'),
|
'some': require('./collection/some'),
|
||||||
'sortBy': require('./collection/sortBy'),
|
'sortBy': require('./collection/sortBy'),
|
||||||
'sortByAll': require('./collection/sortByAll'),
|
'sortByAll': require('./collection/sortByAll'),
|
||||||
|
'sortByOrder': require('./collection/sortByOrder'),
|
||||||
|
'sum': require('./math/sum'),
|
||||||
'where': require('./collection/where')
|
'where': require('./collection/where')
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ var baseAt = require('../internal/baseAt'),
|
|||||||
* @returns {Array} Returns the new array of picked elements.
|
* @returns {Array} Returns the new array of picked elements.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
|
* _.at(['a', 'b', 'c'], [0, 2]);
|
||||||
* // => ['a', 'c', 'e']
|
* // => ['a', 'c']
|
||||||
*
|
*
|
||||||
* _.at(['fred', 'barney', 'pebbles'], 0, 2);
|
* _.at(['fred', 'barney', 'pebbles'], 0, 2);
|
||||||
* // => ['fred', 'pebbles']
|
* // => ['fred', 'pebbles']
|
||||||
|
|||||||
@@ -34,10 +34,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
|||||||
* @returns {Object} Returns the composed aggregate object.
|
* @returns {Object} Returns the composed aggregate object.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.countBy([4.3, 6.1, 6.4], function(n) { return Math.floor(n); });
|
* _.countBy([4.3, 6.1, 6.4], function(n) {
|
||||||
|
* return Math.floor(n);
|
||||||
|
* });
|
||||||
* // => { '4': 1, '6': 2 }
|
* // => { '4': 1, '6': 2 }
|
||||||
*
|
*
|
||||||
* _.countBy([4.3, 6.1, 6.4], function(n) { return this.floor(n); }, Math);
|
* _.countBy([4.3, 6.1, 6.4], function(n) {
|
||||||
|
* return this.floor(n);
|
||||||
|
* }, Math);
|
||||||
* // => { '4': 1, '6': 2 }
|
* // => { '4': 1, '6': 2 }
|
||||||
*
|
*
|
||||||
* _.countBy(['one', 'two', 'three'], 'length');
|
* _.countBy(['one', 'two', 'three'], 'length');
|
||||||
|
|||||||
@@ -30,8 +30,10 @@ var arrayFilter = require('../internal/arrayFilter'),
|
|||||||
* @returns {Array} Returns the new filtered array.
|
* @returns {Array} Returns the new filtered array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; });
|
* _.filter([4, 5, 6], function(n) {
|
||||||
* // => [2, 4]
|
* return n % 2 == 0;
|
||||||
|
* });
|
||||||
|
* // => [4, 6]
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
* { 'user': 'barney', 'age': 36, 'active': true },
|
* { 'user': 'barney', 'age': 36, 'active': true },
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* { 'user': 'pebbles', 'age': 1, 'active': true }
|
* { 'user': 'pebbles', 'age': 1, 'active': true }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user');
|
* _.result(_.find(users, function(chr) {
|
||||||
|
* return chr.age < 40;
|
||||||
|
* }), 'user');
|
||||||
* // => 'barney'
|
* // => 'barney'
|
||||||
*
|
*
|
||||||
* // using the `_.matches` callback shorthand
|
* // using the `_.matches` callback shorthand
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* @returns {*} Returns the matched element, else `undefined`.
|
* @returns {*} Returns the matched element, else `undefined`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; });
|
* _.findLast([1, 2, 3, 4], function(n) {
|
||||||
|
* return n % 2 == 1;
|
||||||
|
* });
|
||||||
* // => 3
|
* // => 3
|
||||||
*/
|
*/
|
||||||
function findLast(collection, predicate, thisArg) {
|
function findLast(collection, predicate, thisArg) {
|
||||||
|
|||||||
@@ -23,10 +23,14 @@ var arrayEach = require('../internal/arrayEach'),
|
|||||||
* @returns {Array|Object|string} Returns `collection`.
|
* @returns {Array|Object|string} Returns `collection`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _([1, 2, 3]).forEach(function(n) { console.log(n); }).value();
|
* _([1, 2]).forEach(function(n) {
|
||||||
|
* console.log(n);
|
||||||
|
* }).value();
|
||||||
* // => logs each value from left to right and returns the array
|
* // => logs each value from left to right and returns the array
|
||||||
*
|
*
|
||||||
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });
|
* _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
|
||||||
|
* console.log(n, key);
|
||||||
|
* });
|
||||||
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
|
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
|
||||||
*/
|
*/
|
||||||
function forEach(collection, iteratee, thisArg) {
|
function forEach(collection, iteratee, thisArg) {
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ var arrayEachRight = require('../internal/arrayEachRight'),
|
|||||||
* @returns {Array|Object|string} Returns `collection`.
|
* @returns {Array|Object|string} Returns `collection`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(',');
|
* _([1, 2]).forEachRight(function(n) {
|
||||||
|
* console.log(n);
|
||||||
|
* }).join(',');
|
||||||
* // => logs each value from right to left and returns the array
|
* // => logs each value from right to left and returns the array
|
||||||
*/
|
*/
|
||||||
function forEachRight(collection, iteratee, thisArg) {
|
function forEachRight(collection, iteratee, thisArg) {
|
||||||
|
|||||||
@@ -34,10 +34,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
|||||||
* @returns {Object} Returns the composed aggregate object.
|
* @returns {Object} Returns the composed aggregate object.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.groupBy([4.2, 6.1, 6.4], function(n) { return Math.floor(n); });
|
* _.groupBy([4.2, 6.1, 6.4], function(n) {
|
||||||
|
* return Math.floor(n);
|
||||||
|
* });
|
||||||
* // => { '4': [4.2], '6': [6.1, 6.4] }
|
* // => { '4': [4.2], '6': [6.1, 6.4] }
|
||||||
*
|
*
|
||||||
* _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math);
|
* _.groupBy([4.2, 6.1, 6.4], function(n) {
|
||||||
|
* return this.floor(n);
|
||||||
|
* }, Math);
|
||||||
* // => { '4': [4.2], '6': [6.1, 6.4] }
|
* // => { '4': [4.2], '6': [6.1, 6.4] }
|
||||||
*
|
*
|
||||||
* // using the `_.property` callback shorthand
|
* // using the `_.property` callback shorthand
|
||||||
|
|||||||
@@ -36,10 +36,14 @@ var createAggregator = require('../internal/createAggregator');
|
|||||||
* _.indexBy(keyData, 'dir');
|
* _.indexBy(keyData, 'dir');
|
||||||
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
|
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
|
||||||
*
|
*
|
||||||
* _.indexBy(keyData, function(object) { return String.fromCharCode(object.code); });
|
* _.indexBy(keyData, function(object) {
|
||||||
|
* return String.fromCharCode(object.code);
|
||||||
|
* });
|
||||||
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
||||||
*
|
*
|
||||||
* _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, String);
|
* _.indexBy(keyData, function(object) {
|
||||||
|
* return this.fromCharCode(object.code);
|
||||||
|
* }, String);
|
||||||
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
||||||
*/
|
*/
|
||||||
var indexBy = createAggregator(function(result, value, key) {
|
var indexBy = createAggregator(function(result, value, key) {
|
||||||
|
|||||||
@@ -40,11 +40,15 @@ var arrayMap = require('../internal/arrayMap'),
|
|||||||
* @returns {Array} Returns the new mapped array.
|
* @returns {Array} Returns the new mapped array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.map([1, 2, 3], function(n) { return n * 3; });
|
* function timesThree(n) {
|
||||||
* // => [3, 6, 9]
|
* return n * 3;
|
||||||
|
* }
|
||||||
*
|
*
|
||||||
* _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; });
|
* _.map([1, 2], timesThree);
|
||||||
* // => [3, 6, 9] (iteration order is not guaranteed)
|
* // => [3, 6]
|
||||||
|
*
|
||||||
|
* _.map({ 'a': 1, 'b': 2 }, timesThree);
|
||||||
|
* // => [3, 6] (iteration order is not guaranteed)
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
* { 'user': 'barney' },
|
* { 'user': 'barney' },
|
||||||
|
|||||||
@@ -1,51 +1 @@
|
|||||||
var arrayMax = require('../internal/arrayMax'),
|
module.exports = require('../math/max');
|
||||||
createExtremum = require('../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);
|
|
||||||
|
|
||||||
module.exports = max;
|
|
||||||
|
|||||||
@@ -1,51 +1 @@
|
|||||||
var arrayMin = require('../internal/arrayMin'),
|
module.exports = require('../math/min');
|
||||||
createExtremum = require('../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);
|
|
||||||
|
|
||||||
module.exports = min;
|
|
||||||
|
|||||||
@@ -27,11 +27,15 @@ var createAggregator = require('../internal/createAggregator');
|
|||||||
* @returns {Array} Returns the array of grouped elements.
|
* @returns {Array} Returns the array of grouped elements.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.partition([1, 2, 3], function(n) { return n % 2; });
|
* _.partition([1, 2, 3], function(n) {
|
||||||
|
* return n % 2;
|
||||||
|
* });
|
||||||
* // => [[1, 3], [2]]
|
* // => [[1, 3], [2]]
|
||||||
*
|
*
|
||||||
* _.partition([1.2, 2.3, 3.4], function(n) { return this.floor(n) % 2; }, Math);
|
* _.partition([1.2, 2.3, 3.4], function(n) {
|
||||||
* // => [[1, 3], [2]]
|
* return this.floor(n) % 2;
|
||||||
|
* }, Math);
|
||||||
|
* // => [[1.2, 3.4], [2.3]]
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
* { 'user': 'barney', 'age': 36, 'active': false },
|
* { 'user': 'barney', 'age': 36, 'active': false },
|
||||||
@@ -39,7 +43,9 @@ var createAggregator = require('../internal/createAggregator');
|
|||||||
* { 'user': 'pebbles', 'age': 1, 'active': false }
|
* { 'user': 'pebbles', 'age': 1, 'active': false }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* var mapper = function(array) { return _.pluck(array, 'user'); };
|
* var mapper = function(array) {
|
||||||
|
* return _.pluck(array, 'user');
|
||||||
|
* };
|
||||||
*
|
*
|
||||||
* // using the `_.matches` callback shorthand
|
* // using the `_.matches` callback shorthand
|
||||||
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
|
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
|
||||||
|
|||||||
@@ -29,14 +29,16 @@ var arrayReduce = require('../internal/arrayReduce'),
|
|||||||
* @returns {*} Returns the accumulated value.
|
* @returns {*} Returns the accumulated value.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; });
|
* _.reduce([1, 2], function(sum, n) {
|
||||||
* // => 6
|
* return sum + n;
|
||||||
|
* });
|
||||||
|
* // => 3
|
||||||
*
|
*
|
||||||
* var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) {
|
* _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
|
||||||
* result[key] = n * 3;
|
* result[key] = n * 3;
|
||||||
* return result;
|
* return result;
|
||||||
* }, {});
|
* }, {});
|
||||||
* // => { 'a': 3, 'b': 6, 'c': 9 } (iteration order is not guaranteed)
|
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
|
||||||
*/
|
*/
|
||||||
function reduce(collection, iteratee, accumulator, thisArg) {
|
function reduce(collection, iteratee, accumulator, thisArg) {
|
||||||
var func = isArray(collection) ? arrayReduce : baseReduce;
|
var func = isArray(collection) ? arrayReduce : baseReduce;
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ var arrayReduceRight = require('../internal/arrayReduceRight'),
|
|||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var array = [[0, 1], [2, 3], [4, 5]];
|
* var array = [[0, 1], [2, 3], [4, 5]];
|
||||||
* _.reduceRight(array, function(flattened, other) { return flattened.concat(other); }, []);
|
*
|
||||||
|
* _.reduceRight(array, function(flattened, other) {
|
||||||
|
* return flattened.concat(other);
|
||||||
|
* }, []);
|
||||||
* // => [4, 5, 2, 3, 0, 1]
|
* // => [4, 5, 2, 3, 0, 1]
|
||||||
*/
|
*/
|
||||||
function reduceRight(collection, iteratee, accumulator, thisArg) {
|
function reduceRight(collection, iteratee, accumulator, thisArg) {
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ var arrayFilter = require('../internal/arrayFilter'),
|
|||||||
* @returns {Array} Returns the new filtered array.
|
* @returns {Array} Returns the new filtered array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var odds = _.reject([1, 2, 3, 4], function(n) { return n % 2 == 0; });
|
* _.reject([1, 2, 3, 4], function(n) {
|
||||||
|
* return n % 2 == 0;
|
||||||
|
* });
|
||||||
* // => [1, 3]
|
* // => [1, 3]
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ var isLength = require('../internal/isLength'),
|
|||||||
keys = require('../object/keys');
|
keys = require('../object/keys');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the size of `collection` by returning `collection.length` for
|
* Gets the size of `collection` by returning its length for array-like
|
||||||
* array-like values or the number of own enumerable properties for objects.
|
* values or the number of own enumerable properties for objects.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -12,12 +12,12 @@ var isLength = require('../internal/isLength'),
|
|||||||
* @returns {number} Returns the size of `collection`.
|
* @returns {number} Returns the size of `collection`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.size([1, 2]);
|
* _.size([1, 2, 3]);
|
||||||
* // => 2
|
|
||||||
*
|
|
||||||
* _.size({ 'one': 1, 'two': 2, 'three': 3 });
|
|
||||||
* // => 3
|
* // => 3
|
||||||
*
|
*
|
||||||
|
* _.size({ 'a': 1, 'b': 2 });
|
||||||
|
* // => 2
|
||||||
|
*
|
||||||
* _.size('pebbles');
|
* _.size('pebbles');
|
||||||
* // => 7
|
* // => 7
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ var arraySome = require('../internal/arraySome'),
|
|||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* // using the `_.matches` callback shorthand
|
* // using the `_.matches` callback shorthand
|
||||||
* _.some(users, { user': 'barney', 'active': false });
|
* _.some(users, { 'user': 'barney', 'active': false });
|
||||||
* // => false
|
* // => false
|
||||||
*
|
*
|
||||||
* // using the `_.matchesProperty` callback shorthand
|
* // using the `_.matchesProperty` callback shorthand
|
||||||
|
|||||||
@@ -34,10 +34,14 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* @returns {Array} Returns the new sorted array.
|
* @returns {Array} Returns the new sorted array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.sortBy([1, 2, 3], function(n) { return Math.sin(n); });
|
* _.sortBy([1, 2, 3], function(n) {
|
||||||
|
* return Math.sin(n);
|
||||||
|
* });
|
||||||
* // => [3, 1, 2]
|
* // => [3, 1, 2]
|
||||||
*
|
*
|
||||||
* _.sortBy([1, 2, 3], function(n) { return this.sin(n); }, Math);
|
* _.sortBy([1, 2, 3], function(n) {
|
||||||
|
* return this.sin(n);
|
||||||
|
* }, Math);
|
||||||
* // => [3, 1, 2]
|
* // => [3, 1, 2]
|
||||||
*
|
*
|
||||||
* var users = [
|
* var users = [
|
||||||
@@ -51,8 +55,11 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* // => ['barney', 'fred', 'pebbles']
|
* // => ['barney', 'fred', 'pebbles']
|
||||||
*/
|
*/
|
||||||
function sortBy(collection, iteratee, thisArg) {
|
function sortBy(collection, iteratee, thisArg) {
|
||||||
|
if (collection == null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = collection ? collection.length : 0,
|
length = collection.length,
|
||||||
result = isLength(length) ? Array(length) : [];
|
result = isLength(length) ? Array(length) : [];
|
||||||
|
|
||||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
var baseEach = require('../internal/baseEach'),
|
var baseFlatten = require('../internal/baseFlatten'),
|
||||||
baseFlatten = require('../internal/baseFlatten'),
|
baseSortByOrder = require('../internal/baseSortByOrder'),
|
||||||
baseSortBy = require('../internal/baseSortBy'),
|
isIterateeCall = require('../internal/isIterateeCall');
|
||||||
compareMultipleAscending = require('../internal/compareMultipleAscending'),
|
|
||||||
isIterateeCall = require('../internal/isIterateeCall'),
|
|
||||||
isLength = require('../internal/isLength');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is like `_.sortBy` except that it sorts by property names
|
* This method is like `_.sortBy` except that it sorts by property names
|
||||||
@@ -29,25 +26,16 @@ var baseEach = require('../internal/baseEach'),
|
|||||||
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
|
* // => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
|
||||||
*/
|
*/
|
||||||
function sortByAll(collection) {
|
function sortByAll(collection) {
|
||||||
var args = arguments;
|
if (collection == null) {
|
||||||
if (args.length > 3 && isIterateeCall(args[1], args[2], args[3])) {
|
return [];
|
||||||
|
}
|
||||||
|
var args = arguments,
|
||||||
|
guard = args[3];
|
||||||
|
|
||||||
|
if (guard && isIterateeCall(args[1], args[2], guard)) {
|
||||||
args = [collection, args[1]];
|
args = [collection, args[1]];
|
||||||
}
|
}
|
||||||
var index = -1,
|
return baseSortByOrder(collection, baseFlatten(args, false, false, 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = sortByAll;
|
module.exports = sortByAll;
|
||||||
|
|||||||
47
collection/sortByOrder.js
Normal file
47
collection/sortByOrder.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
var baseSortByOrder = require('../internal/baseSortByOrder'),
|
||||||
|
isArray = require('../lang/isArray'),
|
||||||
|
isIterateeCall = require('../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`.
|
||||||
|
* @returns {Array} Returns the new sorted array.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var users = [
|
||||||
|
* { 'user': 'barney', 'age': 36 },
|
||||||
|
* { 'user': 'fred', 'age': 40 },
|
||||||
|
* { 'user': 'barney', 'age': 26 },
|
||||||
|
* { '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);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = sortByOrder;
|
||||||
1
collection/sum.js
Normal file
1
collection/sum.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = require('../math/sum');
|
||||||
@@ -12,7 +12,9 @@ var nativeNow = isNative(nativeNow = Date.now) && nativeNow;
|
|||||||
* @category Date
|
* @category Date
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now());
|
* _.defer(function(stamp) {
|
||||||
|
* console.log(_.now() - stamp);
|
||||||
|
* }, _.now());
|
||||||
* // => logs the number of milliseconds it took for the deferred function to be invoked
|
* // => logs the number of milliseconds it took for the deferred function to be invoked
|
||||||
*/
|
*/
|
||||||
var now = nativeNow || function() {
|
var now = nativeNow || function() {
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ var baseBindAll = require('../internal/baseBindAll'),
|
|||||||
*
|
*
|
||||||
* var view = {
|
* var view = {
|
||||||
* 'label': 'docs',
|
* 'label': 'docs',
|
||||||
* 'onClick': function() { console.log('clicked ' + this.label); }
|
* 'onClick': function() {
|
||||||
|
* console.log('clicked ' + this.label);
|
||||||
|
* }
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
* _.bindAll(view);
|
* _.bindAll(view);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ var nativeMax = Math.max;
|
|||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Function
|
* @category Function
|
||||||
* @param {Function} func The function to debounce.
|
* @param {Function} func The function to debounce.
|
||||||
* @param {number} wait The number of milliseconds to delay.
|
* @param {number} [wait=0] The number of milliseconds to delay.
|
||||||
* @param {Object} [options] The options object.
|
* @param {Object} [options] The options object.
|
||||||
* @param {boolean} [options.leading=false] Specify invoking on the leading
|
* @param {boolean} [options.leading=false] Specify invoking on the leading
|
||||||
* edge of the timeout.
|
* edge of the timeout.
|
||||||
@@ -84,7 +84,7 @@ function debounce(func, wait, options) {
|
|||||||
if (typeof func != 'function') {
|
if (typeof func != 'function') {
|
||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
wait = wait < 0 ? 0 : wait;
|
wait = wait < 0 ? 0 : (+wait || 0);
|
||||||
if (options === true) {
|
if (options === true) {
|
||||||
var leading = true;
|
var leading = true;
|
||||||
trailing = false;
|
trailing = false;
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ var baseDelay = require('../internal/baseDelay');
|
|||||||
* @returns {number} Returns the timer id.
|
* @returns {number} Returns the timer id.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.defer(function(text) { console.log(text); }, 'deferred');
|
* _.defer(function(text) {
|
||||||
|
* console.log(text);
|
||||||
|
* }, 'deferred');
|
||||||
* // logs 'deferred' after one or more milliseconds
|
* // logs 'deferred' after one or more milliseconds
|
||||||
*/
|
*/
|
||||||
function defer(func) {
|
function defer(func) {
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ var baseDelay = require('../internal/baseDelay');
|
|||||||
* @returns {number} Returns the timer id.
|
* @returns {number} Returns the timer id.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.delay(function(text) { console.log(text); }, 1000, 'later');
|
* _.delay(function(text) {
|
||||||
|
* console.log(text);
|
||||||
|
* }, 1000, 'later');
|
||||||
* // => logs 'later' after one second
|
* // => logs 'later' after one second
|
||||||
*/
|
*/
|
||||||
function delay(func, wait) {
|
function delay(func, wait) {
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
var arrayEvery = require('../internal/arrayEvery'),
|
var createComposer = require('../internal/createComposer');
|
||||||
isFunction = require('../lang/isFunction');
|
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that returns the result of invoking the provided
|
* 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.
|
* @returns {Function} Returns the new function.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* function add(x, y) {
|
|
||||||
* return x + y;
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* function square(n) {
|
* function square(n) {
|
||||||
* return n * n;
|
* return n * n;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* var addSquare = _.flow(add, square);
|
* var addSquare = _.flow(_.add, square);
|
||||||
* addSquare(1, 2);
|
* addSquare(1, 2);
|
||||||
* // => 9
|
* // => 9
|
||||||
*/
|
*/
|
||||||
function flow() {
|
var flow = createComposer();
|
||||||
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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = flow;
|
module.exports = flow;
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
var arrayEvery = require('../internal/arrayEvery'),
|
var createComposer = require('../internal/createComposer');
|
||||||
isFunction = require('../lang/isFunction');
|
|
||||||
|
|
||||||
/** Used as the `TypeError` message for "Functions" methods. */
|
|
||||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is like `_.flow` except that it creates a function that
|
* 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.
|
* @returns {Function} Returns the new function.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* function add(x, y) {
|
|
||||||
* return x + y;
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* function square(n) {
|
* function square(n) {
|
||||||
* return n * n;
|
* return n * n;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* var addSquare = _.flowRight(square, add);
|
* var addSquare = _.flowRight(square, _.add);
|
||||||
* addSquare(1, 2);
|
* addSquare(1, 2);
|
||||||
* // => 9
|
* // => 9
|
||||||
*/
|
*/
|
||||||
function flowRight() {
|
var flowRight = createComposer(true);
|
||||||
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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = flowRight;
|
module.exports = flowRight;
|
||||||
|
|||||||
@@ -61,13 +61,14 @@ function memoize(func, resolver) {
|
|||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
var memoized = function() {
|
var memoized = function() {
|
||||||
var cache = memoized.cache,
|
var args = arguments,
|
||||||
key = resolver ? resolver.apply(this, arguments) : arguments[0];
|
cache = memoized.cache,
|
||||||
|
key = resolver ? resolver.apply(this, args) : args[0];
|
||||||
|
|
||||||
if (cache.has(key)) {
|
if (cache.has(key)) {
|
||||||
return cache.get(key);
|
return cache.get(key);
|
||||||
}
|
}
|
||||||
var result = func.apply(this, arguments);
|
var result = func.apply(this, args);
|
||||||
cache.set(key, result);
|
cache.set(key, result);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ var REARG_FLAG = 128;
|
|||||||
* // => ['a', 'b', 'c']
|
* // => ['a', 'b', 'c']
|
||||||
*
|
*
|
||||||
* var map = _.rearg(_.map, [1, 0]);
|
* var map = _.rearg(_.map, [1, 0]);
|
||||||
* map(function(n) { return n * 3; }, [1, 2, 3]);
|
* map(function(n) {
|
||||||
|
* return n * 3;
|
||||||
|
* }, [1, 2, 3]);
|
||||||
* // => [3, 6, 9]
|
* // => [3, 6, 9]
|
||||||
*/
|
*/
|
||||||
function rearg(func) {
|
function rearg(func) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ var debounceOptions = {
|
|||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Function
|
* @category Function
|
||||||
* @param {Function} func The function to throttle.
|
* @param {Function} func The function to throttle.
|
||||||
* @param {number} wait The number of milliseconds to throttle invocations to.
|
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
||||||
* @param {Object} [options] The options object.
|
* @param {Object} [options] The options object.
|
||||||
* @param {boolean} [options.leading=true] Specify invoking on the leading
|
* @param {boolean} [options.leading=true] Specify invoking on the leading
|
||||||
* edge of the timeout.
|
* edge of the timeout.
|
||||||
@@ -43,8 +43,9 @@ var debounceOptions = {
|
|||||||
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
||||||
*
|
*
|
||||||
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
|
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
|
||||||
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false })
|
* jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
|
||||||
* jQuery('.interactive').on('click', throttled);
|
* 'trailing': false
|
||||||
|
* }));
|
||||||
*
|
*
|
||||||
* // cancel a trailing throttled call
|
* // cancel a trailing throttled call
|
||||||
* jQuery(window).on('popstate', throttled.cancel);
|
* jQuery(window).on('popstate', throttled.cancel);
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
var baseCreate = require('./baseCreate'),
|
||||||
|
baseLodash = require('./baseLodash');
|
||||||
|
|
||||||
/** Used as references for `-Infinity` and `Infinity`. */
|
/** Used as references for `-Infinity` and `Infinity`. */
|
||||||
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
||||||
|
|
||||||
@@ -18,4 +21,7 @@ function LazyWrapper(value) {
|
|||||||
this.__views__ = null;
|
this.__views__ = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||||
|
LazyWrapper.prototype.constructor = LazyWrapper;
|
||||||
|
|
||||||
module.exports = LazyWrapper;
|
module.exports = LazyWrapper;
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
var baseCreate = require('./baseCreate'),
|
||||||
|
baseLodash = require('./baseLodash');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base constructor for creating `lodash` wrapper objects.
|
* The base constructor for creating `lodash` wrapper objects.
|
||||||
*
|
*
|
||||||
@@ -12,4 +15,7 @@ function LodashWrapper(value, chainAll, actions) {
|
|||||||
this.__chain__ = !!chainAll;
|
this.__chain__ = !!chainAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||||
|
LodashWrapper.prototype.constructor = LodashWrapper;
|
||||||
|
|
||||||
module.exports = LodashWrapper;
|
module.exports = LodashWrapper;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function baseDifference(array, values) {
|
|||||||
var index = -1,
|
var index = -1,
|
||||||
indexOf = baseIndexOf,
|
indexOf = baseIndexOf,
|
||||||
isCommon = true,
|
isCommon = true,
|
||||||
cache = isCommon && values.length >= 200 && createCache(values),
|
cache = (isCommon && values.length >= 200) ? createCache(values) : null,
|
||||||
valuesLength = values.length;
|
valuesLength = values.length;
|
||||||
|
|
||||||
if (cache) {
|
if (cache) {
|
||||||
@@ -42,7 +42,7 @@ function baseDifference(array, values) {
|
|||||||
}
|
}
|
||||||
result.push(value);
|
result.push(value);
|
||||||
}
|
}
|
||||||
else if (indexOf(values, value) < 0) {
|
else if (indexOf(values, value, 0) < 0) {
|
||||||
result.push(value);
|
result.push(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ var isArguments = require('../lang/isArguments'),
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Array} array The array to flatten.
|
* @param {Array} array The array to flatten.
|
||||||
* @param {boolean} [isDeep] Specify a deep flatten.
|
* @param {boolean} isDeep Specify a deep flatten.
|
||||||
* @param {boolean} [isStrict] Restrict flattening to arrays and `arguments` objects.
|
* @param {boolean} isStrict Restrict flattening to arrays and `arguments` objects.
|
||||||
* @param {number} [fromIndex=0] The index to start from.
|
* @param {number} fromIndex The index to start from.
|
||||||
* @returns {Array} Returns the new flattened array.
|
* @returns {Array} Returns the new flattened array.
|
||||||
*/
|
*/
|
||||||
function baseFlatten(array, isDeep, isStrict, fromIndex) {
|
function baseFlatten(array, isDeep, isStrict, fromIndex) {
|
||||||
var index = (fromIndex || 0) - 1,
|
var index = fromIndex - 1,
|
||||||
length = array.length,
|
length = array.length,
|
||||||
resIndex = -1,
|
resIndex = -1,
|
||||||
result = [];
|
result = [];
|
||||||
@@ -26,7 +26,7 @@ function baseFlatten(array, isDeep, isStrict, fromIndex) {
|
|||||||
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
|
if (isObjectLike(value) && isLength(value.length) && (isArray(value) || isArguments(value))) {
|
||||||
if (isDeep) {
|
if (isDeep) {
|
||||||
// Recursively flatten arrays (susceptible to call stack limits).
|
// Recursively flatten arrays (susceptible to call stack limits).
|
||||||
value = baseFlatten(value, isDeep, isStrict);
|
value = baseFlatten(value, isDeep, isStrict, 0);
|
||||||
}
|
}
|
||||||
var valIndex = -1,
|
var valIndex = -1,
|
||||||
valLength = value.length;
|
valLength = value.length;
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ var indexOfNaN = require('./indexOfNaN');
|
|||||||
* @private
|
* @private
|
||||||
* @param {Array} array The array to search.
|
* @param {Array} array The array to search.
|
||||||
* @param {*} value The value to search for.
|
* @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`.
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||||
*/
|
*/
|
||||||
function baseIndexOf(array, value, fromIndex) {
|
function baseIndexOf(array, value, fromIndex) {
|
||||||
if (value !== value) {
|
if (value !== value) {
|
||||||
return indexOfNaN(array, fromIndex);
|
return indexOfNaN(array, fromIndex);
|
||||||
}
|
}
|
||||||
var index = (fromIndex || 0) - 1,
|
var index = fromIndex - 1,
|
||||||
length = array.length;
|
length = array.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
|
|||||||
15
internal/baseIsFunction.js
Normal file
15
internal/baseIsFunction.js
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = baseIsFunction;
|
||||||
10
internal/baseLodash.js
Normal file
10
internal/baseLodash.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* The function whose prototype all chaining wrappers inherit from.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
function baseLodash() {
|
||||||
|
// No operation performed.
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = baseLodash;
|
||||||
@@ -3,6 +3,7 @@ var arrayEach = require('./arrayEach'),
|
|||||||
baseMergeDeep = require('./baseMergeDeep'),
|
baseMergeDeep = require('./baseMergeDeep'),
|
||||||
isArray = require('../lang/isArray'),
|
isArray = require('../lang/isArray'),
|
||||||
isLength = require('./isLength'),
|
isLength = require('./isLength'),
|
||||||
|
isObject = require('../lang/isObject'),
|
||||||
isObjectLike = require('./isObjectLike'),
|
isObjectLike = require('./isObjectLike'),
|
||||||
isTypedArray = require('../lang/isTypedArray');
|
isTypedArray = require('../lang/isTypedArray');
|
||||||
|
|
||||||
@@ -19,8 +20,10 @@ var arrayEach = require('./arrayEach'),
|
|||||||
* @returns {Object} Returns the destination object.
|
* @returns {Object} Returns the destination object.
|
||||||
*/
|
*/
|
||||||
function baseMerge(object, source, customizer, stackA, stackB) {
|
function baseMerge(object, source, customizer, stackA, stackB) {
|
||||||
|
if (!isObject(object)) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
|
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
|
||||||
|
|
||||||
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
|
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
|
||||||
if (isObjectLike(srcValue)) {
|
if (isObjectLike(srcValue)) {
|
||||||
stackA || (stackA = []);
|
stackA || (stackA = []);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* The base implementation of `_.sortBy` and `_.sortByAll` which uses `comparer`
|
* The base implementation of `_.sortBy` which uses `comparer` to define
|
||||||
* to define the sort order of `array` and replaces criteria objects with their
|
* the sort order of `array` and replaces criteria objects with their
|
||||||
* corresponding values.
|
* corresponding values.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
35
internal/baseSortByOrder.js
Normal file
35
internal/baseSortByOrder.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
var baseEach = require('./baseEach'),
|
||||||
|
baseSortBy = require('./baseSortBy'),
|
||||||
|
compareMultiple = require('./compareMultiple'),
|
||||||
|
isLength = require('./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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = baseSortByOrder;
|
||||||
@@ -17,7 +17,7 @@ function baseUniq(array, iteratee) {
|
|||||||
length = array.length,
|
length = array.length,
|
||||||
isCommon = true,
|
isCommon = true,
|
||||||
isLarge = isCommon && length >= 200,
|
isLarge = isCommon && length >= 200,
|
||||||
seen = isLarge && createCache(),
|
seen = isLarge ? createCache() : null,
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
if (seen) {
|
if (seen) {
|
||||||
@@ -44,7 +44,7 @@ function baseUniq(array, iteratee) {
|
|||||||
}
|
}
|
||||||
result.push(value);
|
result.push(value);
|
||||||
}
|
}
|
||||||
else if (indexOf(seen, computed) < 0) {
|
else if (indexOf(seen, computed, 0) < 0) {
|
||||||
if (iteratee || isLarge) {
|
if (iteratee || isLarge) {
|
||||||
seen.push(computed);
|
seen.push(computed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,34 @@
|
|||||||
var baseCompareAscending = require('./baseCompareAscending');
|
var baseCompareAscending = require('./baseCompareAscending');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `_.sortByAll` to compare multiple properties of each element
|
* Used by `_.sortByOrder` to compare multiple properties of each element
|
||||||
* in a collection and stable sort them in ascending order.
|
* 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
|
* @private
|
||||||
* @param {Object} object The object to compare to `other`.
|
* @param {Object} object The object to compare to `other`.
|
||||||
* @param {Object} other The object to compare to `object`.
|
* @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`.
|
* @returns {number} Returns the sort order indicator for `object`.
|
||||||
*/
|
*/
|
||||||
function compareMultipleAscending(object, other) {
|
function compareMultiple(object, other, orders) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
objCriteria = object.criteria,
|
objCriteria = object.criteria,
|
||||||
othCriteria = other.criteria,
|
othCriteria = other.criteria,
|
||||||
length = objCriteria.length;
|
length = objCriteria.length,
|
||||||
|
ordersLength = orders.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
|
var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
if (index >= ordersLength) {
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return orders[index] ? result : result * -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
||||||
@@ -31,4 +41,4 @@ function compareMultipleAscending(object, other) {
|
|||||||
return object.index - other.index;
|
return object.index - other.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = compareMultipleAscending;
|
module.exports = compareMultiple;
|
||||||
@@ -11,24 +11,31 @@ var bindCallback = require('./bindCallback'),
|
|||||||
*/
|
*/
|
||||||
function createAssigner(assigner) {
|
function createAssigner(assigner) {
|
||||||
return function() {
|
return function() {
|
||||||
var length = arguments.length,
|
var args = arguments,
|
||||||
object = arguments[0];
|
length = args.length,
|
||||||
|
object = args[0];
|
||||||
|
|
||||||
if (length < 2 || object == null) {
|
if (length < 2 || object == null) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
if (length > 3 && isIterateeCall(arguments[1], arguments[2], arguments[3])) {
|
var customizer = args[length - 2],
|
||||||
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 (guard && isIterateeCall(args[1], args[2], guard)) {
|
||||||
if (length > 3 && typeof arguments[length - 2] == 'function') {
|
customizer = length == 3 ? null : customizer;
|
||||||
var customizer = bindCallback(arguments[--length - 1], arguments[length--], 5);
|
length = 2;
|
||||||
} else if (length > 2 && typeof arguments[length - 1] == 'function') {
|
|
||||||
customizer = arguments[--length];
|
|
||||||
}
|
}
|
||||||
var index = 0;
|
var index = 0;
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var source = arguments[index];
|
var source = args[index];
|
||||||
if (source) {
|
if (source) {
|
||||||
assigner(object, source, customizer);
|
assigner(object, source, customizer);
|
||||||
}
|
}
|
||||||
|
|||||||
39
internal/createComposer.js
Normal file
39
internal/createComposer.js
Normal 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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = createComposer;
|
||||||
@@ -4,13 +4,13 @@
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Array} array The array to search.
|
* @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.
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
||||||
* @returns {number} Returns the index of the matched `NaN`, else `-1`.
|
* @returns {number} Returns the index of the matched `NaN`, else `-1`.
|
||||||
*/
|
*/
|
||||||
function indexOfNaN(array, fromIndex, fromRight) {
|
function indexOfNaN(array, fromIndex, fromRight) {
|
||||||
var length = array.length,
|
var length = array.length,
|
||||||
index = fromRight ? (fromIndex || length) : ((fromIndex || 0) - 1);
|
index = fromIndex + (fromRight ? 0 : -1);
|
||||||
|
|
||||||
while ((fromRight ? index-- : ++index < length)) {
|
while ((fromRight ? index-- : ++index < length)) {
|
||||||
var other = array[index];
|
var other = array[index];
|
||||||
|
|||||||
@@ -22,7 +22,11 @@ function isIterateeCall(value, index, object) {
|
|||||||
} else {
|
} else {
|
||||||
prereq = type == 'string' && index in object;
|
prereq = type == 'string' && index in object;
|
||||||
}
|
}
|
||||||
return prereq && object[index] === value;
|
if (prereq) {
|
||||||
|
var other = object[index];
|
||||||
|
return value === value ? value === other : other !== other;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = isIterateeCall;
|
module.exports = isIterateeCall;
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ var baseWrapperValue = require('./baseWrapperValue'),
|
|||||||
isArray = require('../lang/isArray');
|
isArray = require('../lang/isArray');
|
||||||
|
|
||||||
/** Used to indicate the type of lazy iteratees. */
|
/** Used to indicate the type of lazy iteratees. */
|
||||||
var LAZY_FILTER_FLAG = 0,
|
var LAZY_DROP_WHILE_FLAG = 0,
|
||||||
LAZY_MAP_FLAG = 1;
|
LAZY_MAP_FLAG = 2,
|
||||||
|
LAZY_TAKE_WHILE_FLAG = 3;
|
||||||
|
|
||||||
/* Native method references for those with the same name as other `lodash` methods. */
|
/* Native method references for those with the same name as other `lodash` methods. */
|
||||||
var nativeMin = Math.min;
|
var nativeMin = Math.min;
|
||||||
@@ -46,16 +47,22 @@ function lazyValue() {
|
|||||||
while (++iterIndex < iterLength) {
|
while (++iterIndex < iterLength) {
|
||||||
var data = iteratees[iterIndex],
|
var data = iteratees[iterIndex],
|
||||||
iteratee = data.iteratee,
|
iteratee = data.iteratee,
|
||||||
computed = iteratee(value, index, array),
|
|
||||||
type = data.type;
|
type = data.type;
|
||||||
|
|
||||||
|
if (type != LAZY_DROP_WHILE_FLAG) {
|
||||||
|
var computed = iteratee(value);
|
||||||
|
} else {
|
||||||
|
data.done = data.done && (isRight ? index < data.index : index > data.index);
|
||||||
|
data.index = index;
|
||||||
|
computed = data.done || (data.done = !iteratee(value));
|
||||||
|
}
|
||||||
if (type == LAZY_MAP_FLAG) {
|
if (type == LAZY_MAP_FLAG) {
|
||||||
value = computed;
|
value = computed;
|
||||||
} else if (!computed) {
|
} else if (!computed) {
|
||||||
if (type == LAZY_FILTER_FLAG) {
|
if (type == LAZY_TAKE_WHILE_FLAG) {
|
||||||
continue outer;
|
|
||||||
} else {
|
|
||||||
break outer;
|
break outer;
|
||||||
|
} else {
|
||||||
|
continue outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,22 +40,26 @@ var baseClone = require('../internal/baseClone'),
|
|||||||
* // => false
|
* // => false
|
||||||
*
|
*
|
||||||
* // using a customizer callback
|
* // using a customizer callback
|
||||||
* var body = _.clone(document.body, function(value) {
|
* var el = _.clone(document.body, function(value) {
|
||||||
* return _.isElement(value) ? value.cloneNode(false) : undefined;
|
* if (_.isElement(value)) {
|
||||||
|
* return value.cloneNode(false);
|
||||||
|
* }
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* body === document.body
|
* el === document.body
|
||||||
* // => false
|
* // => false
|
||||||
* body.nodeName
|
* el.nodeName
|
||||||
* // => BODY
|
* // => BODY
|
||||||
* body.childNodes.length;
|
* el.childNodes.length;
|
||||||
* // => 0
|
* // => 0
|
||||||
*/
|
*/
|
||||||
function clone(value, isDeep, customizer, thisArg) {
|
function clone(value, isDeep, customizer, thisArg) {
|
||||||
// Juggle arguments.
|
if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
|
||||||
if (typeof isDeep != 'boolean' && isDeep != null) {
|
isDeep = false;
|
||||||
|
}
|
||||||
|
else if (typeof isDeep == 'function') {
|
||||||
thisArg = customizer;
|
thisArg = customizer;
|
||||||
customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep;
|
customizer = isDeep;
|
||||||
isDeep = false;
|
isDeep = false;
|
||||||
}
|
}
|
||||||
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
|
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
|
||||||
|
|||||||
@@ -34,14 +34,16 @@ var baseClone = require('../internal/baseClone'),
|
|||||||
*
|
*
|
||||||
* // using a customizer callback
|
* // using a customizer callback
|
||||||
* var el = _.cloneDeep(document.body, function(value) {
|
* var el = _.cloneDeep(document.body, function(value) {
|
||||||
* return _.isElement(value) ? value.cloneNode(true) : undefined;
|
* if (_.isElement(value)) {
|
||||||
|
* return value.cloneNode(true);
|
||||||
|
* }
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* body === document.body
|
* el === document.body
|
||||||
* // => false
|
* // => false
|
||||||
* body.nodeName
|
* el.nodeName
|
||||||
* // => BODY
|
* // => BODY
|
||||||
* body.childNodes.length;
|
* el.childNodes.length;
|
||||||
* // => 20
|
* // => 20
|
||||||
*/
|
*/
|
||||||
function cloneDeep(value, customizer, thisArg) {
|
function cloneDeep(value, customizer, thisArg) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ var objToString = objectProto.toString;
|
|||||||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* (function() { return _.isArguments(arguments); })();
|
* _.isArguments(function() { return arguments; }());
|
||||||
* // => true
|
* // => true
|
||||||
*
|
*
|
||||||
* _.isArguments([1, 2, 3]);
|
* _.isArguments([1, 2, 3]);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray;
|
|||||||
* _.isArray([1, 2, 3]);
|
* _.isArray([1, 2, 3]);
|
||||||
* // => true
|
* // => true
|
||||||
*
|
*
|
||||||
* (function() { return _.isArray(arguments); })();
|
* _.isArray(function() { return arguments; }());
|
||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
var isArray = nativeIsArray || function(value) {
|
var isArray = nativeIsArray || function(value) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var isArguments = require('./isArguments'),
|
|||||||
keys = require('../object/keys');
|
keys = require('../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
|
* `arguments` object, array, string, or jQuery-like collection with a length
|
||||||
* greater than `0` or an object with own enumerable properties.
|
* greater than `0` or an object with own enumerable properties.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ var baseIsEqual = require('../internal/baseIsEqual'),
|
|||||||
* var other = ['hi', 'goodbye'];
|
* var other = ['hi', 'goodbye'];
|
||||||
*
|
*
|
||||||
* _.isEqual(array, other, function(value, other) {
|
* _.isEqual(array, other, function(value, other) {
|
||||||
* return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
|
* if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
|
||||||
|
* return true;
|
||||||
|
* }
|
||||||
* });
|
* });
|
||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
var isNative = require('./isNative');
|
var baseIsFunction = require('../internal/baseIsFunction'),
|
||||||
|
isNative = require('./isNative');
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
/** `Object#toString` result references. */
|
||||||
var funcTag = '[object Function]';
|
var funcTag = '[object Function]';
|
||||||
@@ -32,19 +33,11 @@ var Uint8Array = isNative(Uint8Array = global.Uint8Array) && Uint8Array;
|
|||||||
* _.isFunction(/abc/);
|
* _.isFunction(/abc/);
|
||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isFunction(value) {
|
var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
|
||||||
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
||||||
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
|
// in older versions of Chrome and Safari which return 'function' for regexes
|
||||||
return typeof value == 'function' || false;
|
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
||||||
}
|
return objToString.call(value) == funcTag;
|
||||||
// Fallback for environments that return incorrect `typeof` operator results.
|
};
|
||||||
if (isFunction(/x/) || (Uint8Array && !isFunction(Uint8Array))) {
|
|
||||||
isFunction = function(value) {
|
|
||||||
// The use of `Object#toString` avoids issues with the `typeof` operator
|
|
||||||
// in older versions of Chrome and Safari which return 'function' for regexes
|
|
||||||
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
|
||||||
return objToString.call(value) == funcTag;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = isFunction;
|
module.exports = isFunction;
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ var arrayCopy = require('../internal/arrayCopy'),
|
|||||||
* @returns {Array} Returns the converted array.
|
* @returns {Array} Returns the converted array.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* (function() { return _.toArray(arguments).slice(1); })(1, 2, 3);
|
* (function() {
|
||||||
|
* return _.toArray(arguments).slice(1);
|
||||||
|
* }(1, 2, 3));
|
||||||
* // => [2, 3]
|
* // => [2, 3]
|
||||||
*/
|
*/
|
||||||
function toArray(value) {
|
function toArray(value) {
|
||||||
|
|||||||
6
math.js
Normal file
6
math.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
'add': require('./math/add'),
|
||||||
|
'max': require('./math/max'),
|
||||||
|
'min': require('./math/min'),
|
||||||
|
'sum': require('./math/sum')
|
||||||
|
};
|
||||||
19
math/add.js
Normal file
19
math/add.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = add;
|
||||||
53
math/max.js
Normal file
53
math/max.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
var arrayMax = require('../internal/arrayMax'),
|
||||||
|
createExtremum = require('../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 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);
|
||||||
|
|
||||||
|
module.exports = max;
|
||||||
53
math/min.js
Normal file
53
math/min.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
var arrayMin = require('../internal/arrayMin'),
|
||||||
|
createExtremum = require('../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 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);
|
||||||
|
|
||||||
|
module.exports = min;
|
||||||
33
math/sum.js
Normal file
33
math/sum.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
var isArray = require('../lang/isArray'),
|
||||||
|
toIterable = require('../internal/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;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = sum;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
'inRange': require('./number/inRange'),
|
||||||
'random': require('./number/random')
|
'random': require('./number/random')
|
||||||
};
|
};
|
||||||
|
|||||||
43
number/inRange.js
Normal file
43
number/inRange.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Checks if `n` is between `start` and up to but not including, `end`. If
|
||||||
|
* `end` is not specified it is set to `start` with `start` then set to `0`.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Number
|
||||||
|
* @param {number} n The number to check.
|
||||||
|
* @param {number} [start=0] The start of the range.
|
||||||
|
* @param {number} end The end of the range.
|
||||||
|
* @returns {boolean} Returns `true` if `n` is in the range, else `false`.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _.inRange(3, 2, 4);
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* _.inRange(4, 8);
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* _.inRange(4, 2);
|
||||||
|
* // => false
|
||||||
|
*
|
||||||
|
* _.inRange(2, 2);
|
||||||
|
* // => false
|
||||||
|
*
|
||||||
|
* _.inRange(1.2, 2);
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* _.inRange(5.2, 4);
|
||||||
|
* // => false
|
||||||
|
*/
|
||||||
|
function inRange(value, start, end) {
|
||||||
|
start = +start || 0;
|
||||||
|
if (typeof end === 'undefined') {
|
||||||
|
end = start;
|
||||||
|
start = 0;
|
||||||
|
} else {
|
||||||
|
end = +end || 0;
|
||||||
|
}
|
||||||
|
return value >= start && value < end;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = inRange;
|
||||||
@@ -26,7 +26,9 @@ var baseCopy = require('../internal/baseCopy'),
|
|||||||
* Shape.call(this);
|
* Shape.call(this);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle });
|
* Circle.prototype = _.create(Shape.prototype, {
|
||||||
|
* 'constructor': Circle
|
||||||
|
* });
|
||||||
*
|
*
|
||||||
* var circle = new Circle;
|
* var circle = new Circle;
|
||||||
* circle instanceof Circle;
|
* circle instanceof Circle;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var arrayCopy = require('../internal/arrayCopy'),
|
|||||||
/**
|
/**
|
||||||
* Assigns own enumerable properties of source object(s) to the destination
|
* Assigns own enumerable properties of source object(s) to the destination
|
||||||
* object for all destination properties that resolve to `undefined`. Once a
|
* 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
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* 'pebbles': { 'age': 1, 'active': true }
|
* 'pebbles': { 'age': 1, 'active': true }
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
* _.findKey(users, function(chr) { return chr.age < 40; });
|
* _.findKey(users, function(chr) {
|
||||||
|
* return chr.age < 40;
|
||||||
|
* });
|
||||||
* // => 'barney' (iteration order is not guaranteed)
|
* // => 'barney' (iteration order is not guaranteed)
|
||||||
*
|
*
|
||||||
* // using the `_.matches` callback shorthand
|
* // using the `_.matches` callback shorthand
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ var baseCallback = require('../internal/baseCallback'),
|
|||||||
* 'pebbles': { 'age': 1, 'active': true }
|
* 'pebbles': { 'age': 1, 'active': true }
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
* _.findLastKey(users, function(chr) { return chr.age < 40; });
|
* _.findLastKey(users, function(chr) {
|
||||||
|
* return chr.age < 40;
|
||||||
|
* });
|
||||||
* // => returns `pebbles` assuming `_.findKey` returns `barney`
|
* // => returns `pebbles` assuming `_.findKey` returns `barney`
|
||||||
*
|
*
|
||||||
* // using the `_.matches` callback shorthand
|
* // using the `_.matches` callback shorthand
|
||||||
|
|||||||
@@ -16,10 +16,17 @@ var baseForOwn = require('../internal/baseForOwn'),
|
|||||||
* @returns {Object} Returns `object`.
|
* @returns {Object} Returns `object`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
|
* function Foo() {
|
||||||
|
* this.a = 1;
|
||||||
|
* this.b = 2;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* Foo.prototype.c = 3;
|
||||||
|
*
|
||||||
|
* _.forOwn(new Foo, function(value, key) {
|
||||||
* console.log(key);
|
* console.log(key);
|
||||||
* });
|
* });
|
||||||
* // => logs '0', '1', and 'length' (iteration order is not guaranteed)
|
* // => logs 'a' and 'b' (iteration order is not guaranteed)
|
||||||
*/
|
*/
|
||||||
function forOwn(object, iteratee, thisArg) {
|
function forOwn(object, iteratee, thisArg) {
|
||||||
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
|
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
|
||||||
|
|||||||
@@ -15,10 +15,17 @@ var baseForRight = require('../internal/baseForRight'),
|
|||||||
* @returns {Object} Returns `object`.
|
* @returns {Object} Returns `object`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
|
* function Foo() {
|
||||||
|
* this.a = 1;
|
||||||
|
* this.b = 2;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* Foo.prototype.c = 3;
|
||||||
|
*
|
||||||
|
* _.forOwnRight(new Foo, function(value, key) {
|
||||||
* console.log(key);
|
* console.log(key);
|
||||||
* });
|
* });
|
||||||
* // => logs 'length', '1', and '0' assuming `_.forOwn` logs '0', '1', and 'length'
|
* // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
|
||||||
*/
|
*/
|
||||||
function forOwnRight(object, iteratee, thisArg) {
|
function forOwnRight(object, iteratee, thisArg) {
|
||||||
iteratee = bindCallback(iteratee, thisArg, 3);
|
iteratee = bindCallback(iteratee, thisArg, 3);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user