mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 14:37:49 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebf61a1bd9 |
@@ -1,4 +1,4 @@
|
||||
# lodash-es v3.2.0
|
||||
# lodash-es v3.3.0
|
||||
|
||||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [ES](https://people.mozilla.org/~jorendorff/es6-draft.html) modules.
|
||||
|
||||
@@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli):
|
||||
$ lodash modularize modern exports=es -o ./
|
||||
```
|
||||
|
||||
See the [package source](https://github.com/lodash/lodash/tree/3.2.0-es) for more details.
|
||||
See the [package source](https://github.com/lodash/lodash/tree/3.3.0-es) for more details.
|
||||
|
||||
@@ -20,7 +20,7 @@ import isArray from '../lang/isArray';
|
||||
* @returns {Array} Returns the new array of filtered values.
|
||||
* @example
|
||||
*
|
||||
* _.difference([1, 2, 3], [5, 2, 10]);
|
||||
* _.difference([1, 2, 3], [4, 2]);
|
||||
* // => [1, 3]
|
||||
*/
|
||||
function difference() {
|
||||
|
||||
@@ -27,7 +27,9 @@ import baseSlice from '../internal/baseSlice';
|
||||
* @returns {Array} Returns the slice of `array`.
|
||||
* @example
|
||||
*
|
||||
* _.dropRightWhile([1, 2, 3], function(n) { return n > 1; });
|
||||
* _.dropRightWhile([1, 2, 3], function(n) {
|
||||
* return n > 1;
|
||||
* });
|
||||
* // => [1]
|
||||
*
|
||||
* var users = [
|
||||
|
||||
@@ -27,7 +27,9 @@ import baseSlice from '../internal/baseSlice';
|
||||
* @returns {Array} Returns the slice of `array`.
|
||||
* @example
|
||||
*
|
||||
* _.dropWhile([1, 2, 3], function(n) { return n < 3; });
|
||||
* _.dropWhile([1, 2, 3], function(n) {
|
||||
* return n < 3;
|
||||
* });
|
||||
* // => [3]
|
||||
*
|
||||
* var users = [
|
||||
|
||||
@@ -31,7 +31,9 @@ import baseCallback from '../internal/baseCallback';
|
||||
* { 'user': 'pebbles', 'active': true }
|
||||
* ];
|
||||
*
|
||||
* _.findIndex(users, function(chr) { return chr.user == 'barney'; });
|
||||
* _.findIndex(users, function(chr) {
|
||||
* return chr.user == 'barney';
|
||||
* });
|
||||
* // => 0
|
||||
*
|
||||
* // using the `_.matches` callback shorthand
|
||||
|
||||
@@ -31,7 +31,9 @@ import baseCallback from '../internal/baseCallback';
|
||||
* { 'user': 'pebbles', 'active': false }
|
||||
* ];
|
||||
*
|
||||
* _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; });
|
||||
* _.findLastIndex(users, function(chr) {
|
||||
* return chr.user == 'pebbles';
|
||||
* });
|
||||
* // => 2
|
||||
*
|
||||
* // using the `_.matches` callback shorthand
|
||||
|
||||
@@ -14,11 +14,11 @@ import isIterateeCall from '../internal/isIterateeCall';
|
||||
* @returns {Array} Returns the new flattened array.
|
||||
* @example
|
||||
*
|
||||
* _.flatten([1, [2], [3, [[4]]]]);
|
||||
* // => [1, 2, 3, [[4]]];
|
||||
* _.flatten([1, [2, 3, [4]]]);
|
||||
* // => [1, 2, 3, [4]];
|
||||
*
|
||||
* // using `isDeep`
|
||||
* _.flatten([1, [2], [3, [[4]]]], true);
|
||||
* _.flatten([1, [2, 3, [4]]], true);
|
||||
* // => [1, 2, 3, 4];
|
||||
*/
|
||||
function flatten(array, isDeep, guard) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import baseFlatten from '../internal/baseFlatten';
|
||||
* @returns {Array} Returns the new flattened array.
|
||||
* @example
|
||||
*
|
||||
* _.flattenDeep([1, [2], [3, [[4]]]]);
|
||||
* _.flattenDeep([1, [2, 3, [4]]]);
|
||||
* // => [1, 2, 3, 4];
|
||||
*/
|
||||
function flattenDeep(array) {
|
||||
|
||||
@@ -25,15 +25,15 @@ var nativeMax = Math.max;
|
||||
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||
* @example
|
||||
*
|
||||
* _.indexOf([1, 2, 3, 1, 2, 3], 2);
|
||||
* // => 1
|
||||
* _.indexOf([1, 2, 1, 2], 2);
|
||||
* // => 2
|
||||
*
|
||||
* // using `fromIndex`
|
||||
* _.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
|
||||
* // => 4
|
||||
* _.indexOf([1, 2, 1, 2], 2, 2);
|
||||
* // => 3
|
||||
*
|
||||
* // performing a binary search
|
||||
* _.indexOf([4, 4, 5, 5, 6, 6], 5, true);
|
||||
* _.indexOf([1, 1, 2, 2], 2, true);
|
||||
* // => 2
|
||||
*/
|
||||
function indexOf(array, value, fromIndex) {
|
||||
|
||||
@@ -19,9 +19,8 @@ import isArray from '../lang/isArray';
|
||||
* @param {...Array} [arrays] The arrays to inspect.
|
||||
* @returns {Array} Returns the new array of shared values.
|
||||
* @example
|
||||
*
|
||||
* _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]);
|
||||
* // => [1, 2]
|
||||
* _.intersection([1, 2], [4, 2], [2, 1]);
|
||||
* // => [2]
|
||||
*/
|
||||
function intersection() {
|
||||
var args = [],
|
||||
|
||||
@@ -19,15 +19,15 @@ var nativeMax = Math.max,
|
||||
* @returns {number} Returns the index of the matched value, else `-1`.
|
||||
* @example
|
||||
*
|
||||
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
|
||||
* // => 4
|
||||
* _.lastIndexOf([1, 2, 1, 2], 2);
|
||||
* // => 3
|
||||
*
|
||||
* // using `fromIndex`
|
||||
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
|
||||
* _.lastIndexOf([1, 2, 1, 2], 2, 2);
|
||||
* // => 1
|
||||
*
|
||||
* // performing a binary search
|
||||
* _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true);
|
||||
* _.lastIndexOf([1, 1, 2, 2], 2, true);
|
||||
* // => 3
|
||||
*/
|
||||
function lastIndexOf(array, value, fromIndex) {
|
||||
|
||||
@@ -25,6 +25,7 @@ var splice = arrayProto.splice;
|
||||
* @example
|
||||
*
|
||||
* var array = [1, 2, 3, 1, 2, 3];
|
||||
*
|
||||
* _.pull(array, 2, 3);
|
||||
* console.log(array);
|
||||
* // => [1, 1]
|
||||
|
||||
@@ -18,7 +18,7 @@ import basePullAt from '../internal/basePullAt';
|
||||
* @example
|
||||
*
|
||||
* var array = [5, 10, 15, 20];
|
||||
* var evens = _.pullAt(array, [1, 3]);
|
||||
* var evens = _.pullAt(array, 1, 3);
|
||||
*
|
||||
* console.log(array);
|
||||
* // => [5, 15]
|
||||
|
||||
@@ -35,7 +35,9 @@ var splice = arrayProto.splice;
|
||||
* @example
|
||||
*
|
||||
* var array = [1, 2, 3, 4];
|
||||
* var evens = _.remove(array, function(n) { return n % 2 == 0; });
|
||||
* var evens = _.remove(array, function(n) {
|
||||
* return n % 2 == 0;
|
||||
* });
|
||||
*
|
||||
* console.log(array);
|
||||
* // => [1, 3]
|
||||
|
||||
@@ -35,7 +35,7 @@ import binaryIndexBy from '../internal/binaryIndexBy';
|
||||
* _.sortedIndex([30, 50], 40);
|
||||
* // => 1
|
||||
*
|
||||
* _.sortedIndex([4, 4, 5, 5, 6, 6], 5);
|
||||
* _.sortedIndex([4, 4, 5, 5], 5);
|
||||
* // => 2
|
||||
*
|
||||
* var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
|
||||
|
||||
@@ -19,7 +19,7 @@ import binaryIndexBy from '../internal/binaryIndexBy';
|
||||
* into `array`.
|
||||
* @example
|
||||
*
|
||||
* _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5);
|
||||
* _.sortedLastIndex([4, 4, 5, 5], 5);
|
||||
* // => 4
|
||||
*/
|
||||
function sortedLastIndex(array, value, iteratee, thisArg) {
|
||||
|
||||
@@ -27,7 +27,9 @@ import baseSlice from '../internal/baseSlice';
|
||||
* @returns {Array} Returns the slice of `array`.
|
||||
* @example
|
||||
*
|
||||
* _.takeRightWhile([1, 2, 3], function(n) { return n > 1; });
|
||||
* _.takeRightWhile([1, 2, 3], function(n) {
|
||||
* return n > 1;
|
||||
* });
|
||||
* // => [2, 3]
|
||||
*
|
||||
* var users = [
|
||||
|
||||
@@ -27,7 +27,9 @@ import baseSlice from '../internal/baseSlice';
|
||||
* @returns {Array} Returns the slice of `array`.
|
||||
* @example
|
||||
*
|
||||
* _.takeWhile([1, 2, 3], function(n) { return n < 3; });
|
||||
* _.takeWhile([1, 2, 3], function(n) {
|
||||
* return n < 3;
|
||||
* });
|
||||
* // => [1, 2]
|
||||
*
|
||||
* var users = [
|
||||
|
||||
@@ -17,8 +17,8 @@ import baseUniq from '../internal/baseUniq';
|
||||
* @returns {Array} Returns the new array of combined values.
|
||||
* @example
|
||||
*
|
||||
* _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]);
|
||||
* // => [1, 2, 3, 5, 4]
|
||||
* _.union([1, 2], [4, 2], [2, 1]);
|
||||
* // => [1, 2, 4]
|
||||
*/
|
||||
function union() {
|
||||
return baseUniq(baseFlatten(arguments, false, true));
|
||||
|
||||
@@ -46,7 +46,9 @@ import sortedUniq from '../internal/sortedUniq';
|
||||
* // => [1, 2]
|
||||
*
|
||||
* // using an iteratee function
|
||||
* _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math);
|
||||
* _.uniq([1, 2.5, 1.5, 2], function(n) {
|
||||
* return this.floor(n);
|
||||
* }, Math);
|
||||
* // => [1, 2.5]
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
@@ -58,8 +60,7 @@ function uniq(array, isSorted, iteratee, thisArg) {
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
// Juggle arguments.
|
||||
if (typeof isSorted != 'boolean' && isSorted != null) {
|
||||
if (isSorted != null && typeof isSorted != 'boolean') {
|
||||
thisArg = iteratee;
|
||||
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
|
||||
isSorted = false;
|
||||
|
||||
@@ -18,8 +18,8 @@ import baseSlice from '../internal/baseSlice';
|
||||
* @returns {Array} Returns the new array of filtered values.
|
||||
* @example
|
||||
*
|
||||
* _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
|
||||
* // => [2, 3, 4]
|
||||
* _.without([1, 2, 1, 3], 1, 2);
|
||||
* // => [3]
|
||||
*/
|
||||
function without(array) {
|
||||
return baseDifference(array, baseSlice(arguments, 1));
|
||||
|
||||
@@ -15,11 +15,8 @@ import isArray from '../lang/isArray';
|
||||
* @returns {Array} Returns the new array of values.
|
||||
* @example
|
||||
*
|
||||
* _.xor([1, 2, 3], [5, 2, 1, 4]);
|
||||
* // => [3, 5, 4]
|
||||
*
|
||||
* _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
|
||||
* // => [1, 4, 5]
|
||||
* _.xor([1, 2], [4, 2]);
|
||||
* // => [1, 4]
|
||||
*/
|
||||
function xor() {
|
||||
var index = -1,
|
||||
|
||||
@@ -19,7 +19,9 @@ import lodash from './lodash';
|
||||
*
|
||||
* var youngest = _.chain(users)
|
||||
* .sortBy('age')
|
||||
* .map(function(chr) { return chr.user + ' is ' + chr.age; })
|
||||
* .map(function(chr) {
|
||||
* return chr.user + ' is ' + chr.age;
|
||||
* })
|
||||
* .first()
|
||||
* .value();
|
||||
* // => 'pebbles is 1'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import LazyWrapper from '../internal/LazyWrapper';
|
||||
import LodashWrapper from '../internal/LodashWrapper';
|
||||
import baseLodash from '../internal/baseLodash';
|
||||
import isArray from '../lang/isArray';
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
import wrapperClone from '../internal/wrapperClone';
|
||||
@@ -82,11 +83,15 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* var wrapped = _([1, 2, 3]);
|
||||
*
|
||||
* // returns an unwrapped value
|
||||
* wrapped.reduce(function(sum, n) { return sum + n; });
|
||||
* wrapped.reduce(function(sum, n) {
|
||||
* return sum + n;
|
||||
* });
|
||||
* // => 6
|
||||
*
|
||||
* // returns a wrapped value
|
||||
* var squares = wrapped.map(function(n) { return n * n; });
|
||||
* var squares = wrapped.map(function(n) {
|
||||
* return n * n;
|
||||
* });
|
||||
*
|
||||
* _.isArray(squares);
|
||||
* // => false
|
||||
@@ -106,4 +111,7 @@ function lodash(value) {
|
||||
return new LodashWrapper(value);
|
||||
}
|
||||
|
||||
// Ensure wrappers are instances of `baseLodash`.
|
||||
lodash.prototype = baseLodash.prototype;
|
||||
|
||||
export default lodash;
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
* @example
|
||||
*
|
||||
* _([1, 2, 3])
|
||||
* .tap(function(array) { array.pop(); })
|
||||
* .tap(function(array) {
|
||||
* array.pop();
|
||||
* })
|
||||
* .reverse()
|
||||
* .value();
|
||||
* // => [2, 1]
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
*
|
||||
* _([1, 2, 3])
|
||||
* .last()
|
||||
* .thru(function(value) { return [value]; })
|
||||
* .thru(function(value) {
|
||||
* return [value];
|
||||
* })
|
||||
* .value();
|
||||
* // => [3]
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import LodashWrapper from '../internal/LodashWrapper';
|
||||
import baseLodash from '../internal/baseLodash';
|
||||
import wrapperClone from '../internal/wrapperClone';
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ function wrapperPlant(value) {
|
||||
var result,
|
||||
parent = this;
|
||||
|
||||
while (parent instanceof LodashWrapper) {
|
||||
while (parent instanceof baseLodash) {
|
||||
var clone = wrapperClone(parent);
|
||||
if (result) {
|
||||
previous.__wrapped__ = clone;
|
||||
|
||||
@@ -17,8 +17,8 @@ import toIterable from '../internal/toIterable';
|
||||
* @returns {Array} Returns the new array of picked elements.
|
||||
* @example
|
||||
*
|
||||
* _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
|
||||
* // => ['a', 'c', 'e']
|
||||
* _.at(['a', 'b', 'c'], [0, 2]);
|
||||
* // => ['a', 'c']
|
||||
*
|
||||
* _.at(['fred', 'barney', 'pebbles'], 0, 2);
|
||||
* // => ['fred', 'pebbles']
|
||||
|
||||
@@ -34,10 +34,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* @returns {Object} Returns the composed aggregate object.
|
||||
* @example
|
||||
*
|
||||
* _.countBy([4.3, 6.1, 6.4], function(n) { return Math.floor(n); });
|
||||
* _.countBy([4.3, 6.1, 6.4], function(n) {
|
||||
* return Math.floor(n);
|
||||
* });
|
||||
* // => { '4': 1, '6': 2 }
|
||||
*
|
||||
* _.countBy([4.3, 6.1, 6.4], function(n) { return this.floor(n); }, Math);
|
||||
* _.countBy([4.3, 6.1, 6.4], function(n) {
|
||||
* return this.floor(n);
|
||||
* }, Math);
|
||||
* // => { '4': 1, '6': 2 }
|
||||
*
|
||||
* _.countBy(['one', 'two', 'three'], 'length');
|
||||
|
||||
@@ -30,8 +30,10 @@ import isArray from '../lang/isArray';
|
||||
* @returns {Array} Returns the new filtered array.
|
||||
* @example
|
||||
*
|
||||
* var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; });
|
||||
* // => [2, 4]
|
||||
* _.filter([4, 5, 6], function(n) {
|
||||
* return n % 2 == 0;
|
||||
* });
|
||||
* // => [4, 6]
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 36, 'active': true },
|
||||
|
||||
@@ -37,7 +37,9 @@ import isArray from '../lang/isArray';
|
||||
* { 'user': 'pebbles', 'age': 1, 'active': true }
|
||||
* ];
|
||||
*
|
||||
* _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user');
|
||||
* _.result(_.find(users, function(chr) {
|
||||
* return chr.age < 40;
|
||||
* }), 'user');
|
||||
* // => 'barney'
|
||||
*
|
||||
* // using the `_.matches` callback shorthand
|
||||
|
||||
@@ -16,7 +16,9 @@ import baseFind from '../internal/baseFind';
|
||||
* @returns {*} Returns the matched element, else `undefined`.
|
||||
* @example
|
||||
*
|
||||
* _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; });
|
||||
* _.findLast([1, 2, 3, 4], function(n) {
|
||||
* return n % 2 == 1;
|
||||
* });
|
||||
* // => 3
|
||||
*/
|
||||
function findLast(collection, predicate, thisArg) {
|
||||
|
||||
@@ -23,10 +23,14 @@ import isArray from '../lang/isArray';
|
||||
* @returns {Array|Object|string} Returns `collection`.
|
||||
* @example
|
||||
*
|
||||
* _([1, 2, 3]).forEach(function(n) { console.log(n); }).value();
|
||||
* _([1, 2]).forEach(function(n) {
|
||||
* console.log(n);
|
||||
* }).value();
|
||||
* // => logs each value from left to right and returns the array
|
||||
*
|
||||
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });
|
||||
* _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
|
||||
* console.log(n, key);
|
||||
* });
|
||||
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
|
||||
*/
|
||||
function forEach(collection, iteratee, thisArg) {
|
||||
|
||||
@@ -17,7 +17,9 @@ import isArray from '../lang/isArray';
|
||||
* @returns {Array|Object|string} Returns `collection`.
|
||||
* @example
|
||||
*
|
||||
* _([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(',');
|
||||
* _([1, 2]).forEachRight(function(n) {
|
||||
* console.log(n);
|
||||
* }).join(',');
|
||||
* // => logs each value from right to left and returns the array
|
||||
*/
|
||||
function forEachRight(collection, iteratee, thisArg) {
|
||||
|
||||
@@ -34,10 +34,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* @returns {Object} Returns the composed aggregate object.
|
||||
* @example
|
||||
*
|
||||
* _.groupBy([4.2, 6.1, 6.4], function(n) { return Math.floor(n); });
|
||||
* _.groupBy([4.2, 6.1, 6.4], function(n) {
|
||||
* return Math.floor(n);
|
||||
* });
|
||||
* // => { '4': [4.2], '6': [6.1, 6.4] }
|
||||
*
|
||||
* _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math);
|
||||
* _.groupBy([4.2, 6.1, 6.4], function(n) {
|
||||
* return this.floor(n);
|
||||
* }, Math);
|
||||
* // => { '4': [4.2], '6': [6.1, 6.4] }
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
|
||||
@@ -36,10 +36,14 @@ import createAggregator from '../internal/createAggregator';
|
||||
* _.indexBy(keyData, 'dir');
|
||||
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
|
||||
*
|
||||
* _.indexBy(keyData, function(object) { return String.fromCharCode(object.code); });
|
||||
* _.indexBy(keyData, function(object) {
|
||||
* return String.fromCharCode(object.code);
|
||||
* });
|
||||
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
||||
*
|
||||
* _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, String);
|
||||
* _.indexBy(keyData, function(object) {
|
||||
* return this.fromCharCode(object.code);
|
||||
* }, String);
|
||||
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
||||
*/
|
||||
var indexBy = createAggregator(function(result, value, key) {
|
||||
|
||||
@@ -40,11 +40,15 @@ import isArray from '../lang/isArray';
|
||||
* @returns {Array} Returns the new mapped array.
|
||||
* @example
|
||||
*
|
||||
* _.map([1, 2, 3], function(n) { return n * 3; });
|
||||
* // => [3, 6, 9]
|
||||
* function timesThree(n) {
|
||||
* return n * 3;
|
||||
* }
|
||||
*
|
||||
* _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; });
|
||||
* // => [3, 6, 9] (iteration order is not guaranteed)
|
||||
* _.map([1, 2], timesThree);
|
||||
* // => [3, 6]
|
||||
*
|
||||
* _.map({ 'a': 1, 'b': 2 }, timesThree);
|
||||
* // => [3, 6] (iteration order is not guaranteed)
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney' },
|
||||
|
||||
@@ -39,7 +39,9 @@ import createExtremum from '../internal/createExtremum';
|
||||
* { 'user': 'fred', 'age': 40 }
|
||||
* ];
|
||||
*
|
||||
* _.max(users, function(chr) { return chr.age; });
|
||||
* _.max(users, function(chr) {
|
||||
* return chr.age;
|
||||
* });
|
||||
* // => { 'user': 'fred', 'age': 40 };
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
|
||||
@@ -39,7 +39,9 @@ import createExtremum from '../internal/createExtremum';
|
||||
* { 'user': 'fred', 'age': 40 }
|
||||
* ];
|
||||
*
|
||||
* _.min(users, function(chr) { return chr.age; });
|
||||
* _.min(users, function(chr) {
|
||||
* return chr.age;
|
||||
* });
|
||||
* // => { 'user': 'barney', 'age': 36 };
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
|
||||
@@ -27,10 +27,14 @@ import createAggregator from '../internal/createAggregator';
|
||||
* @returns {Array} Returns the array of grouped elements.
|
||||
* @example
|
||||
*
|
||||
* _.partition([1, 2, 3], function(n) { return n % 2; });
|
||||
* _.partition([1, 2, 3], function(n) {
|
||||
* return n % 2;
|
||||
* });
|
||||
* // => [[1, 3], [2]]
|
||||
*
|
||||
* _.partition([1.2, 2.3, 3.4], function(n) { return this.floor(n) % 2; }, Math);
|
||||
* _.partition([1.2, 2.3, 3.4], function(n) {
|
||||
* return this.floor(n) % 2;
|
||||
* }, Math);
|
||||
* // => [[1, 3], [2]]
|
||||
*
|
||||
* var users = [
|
||||
@@ -39,7 +43,9 @@ import createAggregator from '../internal/createAggregator';
|
||||
* { 'user': 'pebbles', 'age': 1, 'active': false }
|
||||
* ];
|
||||
*
|
||||
* var mapper = function(array) { return _.pluck(array, 'user'); };
|
||||
* var mapper = function(array) {
|
||||
* return _.pluck(array, 'user');
|
||||
* };
|
||||
*
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
|
||||
|
||||
@@ -29,14 +29,16 @@ import isArray from '../lang/isArray';
|
||||
* @returns {*} Returns the accumulated value.
|
||||
* @example
|
||||
*
|
||||
* var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; });
|
||||
* // => 6
|
||||
* _.reduce([1, 2], function(sum, n) {
|
||||
* return sum + n;
|
||||
* });
|
||||
* // => 3
|
||||
*
|
||||
* var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) {
|
||||
* _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
|
||||
* result[key] = n * 3;
|
||||
* return result;
|
||||
* }, {});
|
||||
* // => { 'a': 3, 'b': 6, 'c': 9 } (iteration order is not guaranteed)
|
||||
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
|
||||
*/
|
||||
function reduce(collection, iteratee, accumulator, thisArg) {
|
||||
var func = isArray(collection) ? arrayReduce : baseReduce;
|
||||
|
||||
@@ -20,7 +20,10 @@ import isArray from '../lang/isArray';
|
||||
* @example
|
||||
*
|
||||
* var array = [[0, 1], [2, 3], [4, 5]];
|
||||
* _.reduceRight(array, function(flattened, other) { return flattened.concat(other); }, []);
|
||||
*
|
||||
* _.reduceRight(array, function(flattened, other) {
|
||||
* return flattened.concat(other);
|
||||
* }, []);
|
||||
* // => [4, 5, 2, 3, 0, 1]
|
||||
*/
|
||||
function reduceRight(collection, iteratee, accumulator, thisArg) {
|
||||
|
||||
@@ -28,7 +28,9 @@ import isArray from '../lang/isArray';
|
||||
* @returns {Array} Returns the new filtered array.
|
||||
* @example
|
||||
*
|
||||
* var odds = _.reject([1, 2, 3, 4], function(n) { return n % 2 == 0; });
|
||||
* _.reject([1, 2, 3, 4], function(n) {
|
||||
* return n % 2 == 0;
|
||||
* });
|
||||
* // => [1, 3]
|
||||
*
|
||||
* var users = [
|
||||
|
||||
@@ -12,12 +12,12 @@ import keys from '../object/keys';
|
||||
* @returns {number} Returns the size of `collection`.
|
||||
* @example
|
||||
*
|
||||
* _.size([1, 2]);
|
||||
* // => 2
|
||||
*
|
||||
* _.size({ 'one': 1, 'two': 2, 'three': 3 });
|
||||
* _.size([1, 2, 3]);
|
||||
* // => 3
|
||||
*
|
||||
* _.size({ 'a': 1, 'b': 2 });
|
||||
* // => 2
|
||||
*
|
||||
* _.size('pebbles');
|
||||
* // => 7
|
||||
*/
|
||||
|
||||
@@ -34,10 +34,14 @@ import isLength from '../internal/isLength';
|
||||
* @returns {Array} Returns the new sorted array.
|
||||
* @example
|
||||
*
|
||||
* _.sortBy([1, 2, 3], function(n) { return Math.sin(n); });
|
||||
* _.sortBy([1, 2, 3], function(n) {
|
||||
* return Math.sin(n);
|
||||
* });
|
||||
* // => [3, 1, 2]
|
||||
*
|
||||
* _.sortBy([1, 2, 3], function(n) { return this.sin(n); }, Math);
|
||||
* _.sortBy([1, 2, 3], function(n) {
|
||||
* return this.sin(n);
|
||||
* }, Math);
|
||||
* // => [3, 1, 2]
|
||||
*
|
||||
* var users = [
|
||||
|
||||
@@ -12,7 +12,9 @@ var nativeNow = isNative(nativeNow = Date.now) && nativeNow;
|
||||
* @category Date
|
||||
* @example
|
||||
*
|
||||
* _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now());
|
||||
* _.defer(function(stamp) {
|
||||
* console.log(_.now() - stamp);
|
||||
* }, _.now());
|
||||
* // => logs the number of milliseconds it took for the deferred function to be invoked
|
||||
*/
|
||||
var now = nativeNow || function() {
|
||||
|
||||
@@ -21,7 +21,9 @@ import functions from '../object/functions';
|
||||
*
|
||||
* var view = {
|
||||
* 'label': 'docs',
|
||||
* 'onClick': function() { console.log('clicked ' + this.label); }
|
||||
* 'onClick': function() {
|
||||
* console.log('clicked ' + this.label);
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* _.bindAll(view);
|
||||
|
||||
@@ -12,7 +12,9 @@ import baseDelay from '../internal/baseDelay';
|
||||
* @returns {number} Returns the timer id.
|
||||
* @example
|
||||
*
|
||||
* _.defer(function(text) { console.log(text); }, 'deferred');
|
||||
* _.defer(function(text) {
|
||||
* console.log(text);
|
||||
* }, 'deferred');
|
||||
* // logs 'deferred' after one or more milliseconds
|
||||
*/
|
||||
function defer(func) {
|
||||
|
||||
@@ -13,7 +13,9 @@ import baseDelay from '../internal/baseDelay';
|
||||
* @returns {number} Returns the timer id.
|
||||
* @example
|
||||
*
|
||||
* _.delay(function(text) { console.log(text); }, 1000, 'later');
|
||||
* _.delay(function(text) {
|
||||
* console.log(text);
|
||||
* }, 1000, 'later');
|
||||
* // => logs 'later' after one second
|
||||
*/
|
||||
function delay(func, wait) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import arrayEvery from '../internal/arrayEvery';
|
||||
import isFunction from '../lang/isFunction';
|
||||
import baseIsFunction from '../internal/baseIsFunction';
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -35,7 +35,7 @@ function flow() {
|
||||
if (!length) {
|
||||
return function() { return arguments[0]; };
|
||||
}
|
||||
if (!arrayEvery(funcs, isFunction)) {
|
||||
if (!arrayEvery(funcs, baseIsFunction)) {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return function() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import arrayEvery from '../internal/arrayEvery';
|
||||
import isFunction from '../lang/isFunction';
|
||||
import baseIsFunction from '../internal/baseIsFunction';
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -35,7 +35,7 @@ function flowRight() {
|
||||
if (fromIndex < 0) {
|
||||
return function() { return arguments[0]; };
|
||||
}
|
||||
if (!arrayEvery(funcs, isFunction)) {
|
||||
if (!arrayEvery(funcs, baseIsFunction)) {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return function() {
|
||||
|
||||
@@ -27,7 +27,9 @@ var REARG_FLAG = 128;
|
||||
* // => ['a', 'b', 'c']
|
||||
*
|
||||
* var map = _.rearg(_.map, [1, 0]);
|
||||
* map(function(n) { return n * 3; }, [1, 2, 3]);
|
||||
* map(function(n) {
|
||||
* return n * 3;
|
||||
* }, [1, 2, 3]);
|
||||
* // => [3, 6, 9]
|
||||
*/
|
||||
function rearg(func) {
|
||||
|
||||
@@ -43,8 +43,9 @@ var debounceOptions = {
|
||||
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
||||
*
|
||||
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
|
||||
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false })
|
||||
* jQuery('.interactive').on('click', throttled);
|
||||
* jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
|
||||
* 'trailing': false
|
||||
* }));
|
||||
*
|
||||
* // cancel a trailing throttled call
|
||||
* jQuery(window).on('popstate', throttled.cancel);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import baseCreate from './baseCreate';
|
||||
import baseLodash from './baseLodash';
|
||||
|
||||
/** Used as references for `-Infinity` and `Infinity`. */
|
||||
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
||||
|
||||
@@ -18,4 +21,7 @@ function LazyWrapper(value) {
|
||||
this.__views__ = null;
|
||||
}
|
||||
|
||||
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||
LazyWrapper.prototype.constructor = LazyWrapper;
|
||||
|
||||
export default LazyWrapper;
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import baseCreate from './baseCreate';
|
||||
import baseLodash from './baseLodash';
|
||||
|
||||
/**
|
||||
* The base constructor for creating `lodash` wrapper objects.
|
||||
*
|
||||
@@ -12,4 +15,7 @@ function LodashWrapper(value, chainAll, actions) {
|
||||
this.__chain__ = !!chainAll;
|
||||
}
|
||||
|
||||
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||
LodashWrapper.prototype.constructor = LodashWrapper;
|
||||
|
||||
export default LodashWrapper;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export default 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.
|
||||
}
|
||||
|
||||
export default baseLodash;
|
||||
@@ -3,6 +3,7 @@ import baseForOwn from './baseForOwn';
|
||||
import baseMergeDeep from './baseMergeDeep';
|
||||
import isArray from '../lang/isArray';
|
||||
import isLength from './isLength';
|
||||
import isObject from '../lang/isObject';
|
||||
import isObjectLike from './isObjectLike';
|
||||
import isTypedArray from '../lang/isTypedArray';
|
||||
|
||||
@@ -19,8 +20,10 @@ import isTypedArray from '../lang/isTypedArray';
|
||||
* @returns {Object} Returns the destination object.
|
||||
*/
|
||||
function baseMerge(object, source, customizer, stackA, stackB) {
|
||||
if (!isObject(object)) {
|
||||
return object;
|
||||
}
|
||||
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
|
||||
|
||||
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
|
||||
if (isObjectLike(srcValue)) {
|
||||
stackA || (stackA = []);
|
||||
|
||||
@@ -22,7 +22,8 @@ function isIterateeCall(value, index, object) {
|
||||
} else {
|
||||
prereq = type == 'string' && index in object;
|
||||
}
|
||||
return prereq && object[index] === value;
|
||||
var other = object[index];
|
||||
return prereq && (value === value ? value === other : other !== other);
|
||||
}
|
||||
|
||||
export default isIterateeCall;
|
||||
|
||||
@@ -40,22 +40,26 @@ import isIterateeCall from '../internal/isIterateeCall';
|
||||
* // => false
|
||||
*
|
||||
* // using a customizer callback
|
||||
* var body = _.clone(document.body, function(value) {
|
||||
* return _.isElement(value) ? value.cloneNode(false) : undefined;
|
||||
* var el = _.clone(document.body, function(value) {
|
||||
* if (_.isElement(value)) {
|
||||
* return value.cloneNode(false);
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* body === document.body
|
||||
* el === document.body
|
||||
* // => false
|
||||
* body.nodeName
|
||||
* el.nodeName
|
||||
* // => BODY
|
||||
* body.childNodes.length;
|
||||
* el.childNodes.length;
|
||||
* // => 0
|
||||
*/
|
||||
function clone(value, isDeep, customizer, thisArg) {
|
||||
// Juggle arguments.
|
||||
if (typeof isDeep != 'boolean' && isDeep != null) {
|
||||
if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
|
||||
isDeep = false;
|
||||
}
|
||||
else if (typeof isDeep == 'function') {
|
||||
thisArg = customizer;
|
||||
customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep;
|
||||
customizer = isDeep;
|
||||
isDeep = false;
|
||||
}
|
||||
customizer = typeof customizer == 'function' && bindCallback(customizer, thisArg, 1);
|
||||
|
||||
@@ -34,14 +34,16 @@ import bindCallback from '../internal/bindCallback';
|
||||
*
|
||||
* // using a customizer callback
|
||||
* var el = _.cloneDeep(document.body, function(value) {
|
||||
* return _.isElement(value) ? value.cloneNode(true) : undefined;
|
||||
* if (_.isElement(value)) {
|
||||
* return value.cloneNode(true);
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* body === document.body
|
||||
* el === document.body
|
||||
* // => false
|
||||
* body.nodeName
|
||||
* el.nodeName
|
||||
* // => BODY
|
||||
* body.childNodes.length;
|
||||
* el.childNodes.length;
|
||||
* // => 20
|
||||
*/
|
||||
function cloneDeep(value, customizer, thisArg) {
|
||||
|
||||
@@ -24,7 +24,7 @@ var objToString = objectProto.toString;
|
||||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
||||
* @example
|
||||
*
|
||||
* (function() { return _.isArguments(arguments); })();
|
||||
* _.isArguments(function() { return arguments; }());
|
||||
* // => true
|
||||
*
|
||||
* _.isArguments([1, 2, 3]);
|
||||
|
||||
@@ -31,7 +31,7 @@ var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray;
|
||||
* _.isArray([1, 2, 3]);
|
||||
* // => true
|
||||
*
|
||||
* (function() { return _.isArray(arguments); })();
|
||||
* _.isArray(function() { return arguments; }());
|
||||
* // => false
|
||||
*/
|
||||
var isArray = nativeIsArray || function(value) {
|
||||
|
||||
@@ -39,7 +39,9 @@ import isStrictComparable from '../internal/isStrictComparable';
|
||||
* var other = ['hi', 'goodbye'];
|
||||
*
|
||||
* _.isEqual(array, other, function(value, other) {
|
||||
* return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
|
||||
* if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
|
||||
* return true;
|
||||
* }
|
||||
* });
|
||||
* // => true
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import baseIsFunction from '../internal/baseIsFunction';
|
||||
import isNative from './isNative';
|
||||
import root from '../internal/root';
|
||||
|
||||
@@ -33,19 +34,11 @@ var Uint8Array = isNative(Uint8Array = root.Uint8Array) && Uint8Array;
|
||||
* _.isFunction(/abc/);
|
||||
* // => false
|
||||
*/
|
||||
function isFunction(value) {
|
||||
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
|
||||
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
|
||||
return typeof value == 'function' || false;
|
||||
}
|
||||
// Fallback for environments that return incorrect `typeof` operator results.
|
||||
if (isFunction(/x/) || (Uint8Array && !isFunction(Uint8Array))) {
|
||||
isFunction = function(value) {
|
||||
// The use of `Object#toString` avoids issues with the `typeof` operator
|
||||
// in older versions of Chrome and Safari which return 'function' for regexes
|
||||
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
||||
return objToString.call(value) == funcTag;
|
||||
};
|
||||
}
|
||||
var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) {
|
||||
// The use of `Object#toString` avoids issues with the `typeof` operator
|
||||
// in older versions of Chrome and Safari which return 'function' for regexes
|
||||
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
||||
return objToString.call(value) == funcTag;
|
||||
};
|
||||
|
||||
export default isFunction;
|
||||
|
||||
@@ -12,7 +12,9 @@ import values from '../object/values';
|
||||
* @returns {Array} Returns the converted array.
|
||||
* @example
|
||||
*
|
||||
* (function() { return _.toArray(arguments).slice(1); })(1, 2, 3);
|
||||
* (function() {
|
||||
* return _.toArray(arguments).slice(1);
|
||||
* }(1, 2, 3));
|
||||
* // => [2, 3]
|
||||
*/
|
||||
function toArray(value) {
|
||||
|
||||
17
lodash.js
17
lodash.js
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @license
|
||||
* lodash 3.2.0 (Custom Build) <https://lodash.com/>
|
||||
* lodash 3.3.0 (Custom Build) <https://lodash.com/>
|
||||
* Build: `lodash modularize modern exports="es" -o ./`
|
||||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
||||
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
|
||||
@@ -21,7 +21,6 @@ import LazyWrapper from './internal/LazyWrapper';
|
||||
import LodashWrapper from './internal/LodashWrapper';
|
||||
import arrayEach from './internal/arrayEach';
|
||||
import baseCallback from './internal/baseCallback';
|
||||
import baseCreate from './internal/baseCreate';
|
||||
import baseForOwn from './internal/baseForOwn';
|
||||
import baseFunctions from './internal/baseFunctions';
|
||||
import baseMatches from './internal/baseMatches';
|
||||
@@ -39,7 +38,7 @@ import support from './support';
|
||||
import thru from './chain/thru';
|
||||
|
||||
/** Used as the semantic version number. */
|
||||
var VERSION = '3.2.0';
|
||||
var VERSION = '3.3.0';
|
||||
|
||||
/** Used to indicate the type of lazy iteratees. */
|
||||
var LAZY_FILTER_FLAG = 0,
|
||||
@@ -56,13 +55,6 @@ var floor = Math.floor,
|
||||
var nativeMax = Math.max,
|
||||
nativeMin = Math.min;
|
||||
|
||||
// Ensure `new LodashWrapper` is an instance of `lodash`.
|
||||
LodashWrapper.prototype = baseCreate(lodash.prototype);
|
||||
|
||||
// Ensure `new LazyWraper` is an instance of `LodashWrapper`
|
||||
LazyWrapper.prototype = baseCreate(LodashWrapper.prototype);
|
||||
LazyWrapper.prototype.constructor = LazyWrapper;
|
||||
|
||||
// wrap `_.mixin` so it works when provided only one argument
|
||||
var mixin = (function(func) {
|
||||
return function(object, source, options) {
|
||||
@@ -222,6 +214,7 @@ lodash.has = object.has;
|
||||
lodash.identity = identity;
|
||||
lodash.includes = collection.includes;
|
||||
lodash.indexOf = array.indexOf;
|
||||
lodash.inRange = number.inRange;
|
||||
lodash.isArguments = lang.isArguments;
|
||||
lodash.isArray = isArray;
|
||||
lodash.isBoolean = lang.isBoolean;
|
||||
@@ -490,7 +483,7 @@ LazyWrapper.prototype.clone = lazyClone;
|
||||
LazyWrapper.prototype.reverse = lazyReverse;
|
||||
LazyWrapper.prototype.value = lazyValue;
|
||||
|
||||
// Add chaining functions to the lodash wrapper.
|
||||
// Add chaining functions to the `lodash` wrapper.
|
||||
lodash.prototype.chain = chain.wrapperChain;
|
||||
lodash.prototype.commit = chain.commit;
|
||||
lodash.prototype.plant = chain.plant;
|
||||
@@ -498,7 +491,7 @@ lodash.prototype.reverse = chain.reverse;
|
||||
lodash.prototype.toString = chain.toString;
|
||||
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = chain.value;
|
||||
|
||||
// Add function aliases to the lodash wrapper.
|
||||
// Add function aliases to the `lodash` wrapper.
|
||||
lodash.prototype.collect = lodash.prototype.map;
|
||||
lodash.prototype.head = lodash.prototype.first;
|
||||
lodash.prototype.select = lodash.prototype.filter;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import inRange from './number/inRange';
|
||||
import random from './number/random';
|
||||
|
||||
export default {
|
||||
'inRange': inRange,
|
||||
'random': 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 defaults to `start` with `start` becoming `0`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Number
|
||||
* @param {number} n The number to check.
|
||||
* @param {number} [start=0] The start of the range.
|
||||
* @param {number} end The end of the range.
|
||||
* @returns {boolean} Returns `true` if `n` is in the range, else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.inRange(3, 2, 4);
|
||||
* // => true
|
||||
*
|
||||
* _.inRange(4, 8);
|
||||
* // => true
|
||||
*
|
||||
* _.inRange(4, 2);
|
||||
* // => false
|
||||
*
|
||||
* _.inRange(2, 2);
|
||||
* // => false
|
||||
*
|
||||
* _.inRange(1.2, 2);
|
||||
* // => true
|
||||
*
|
||||
* _.inRange(5.2, 4);
|
||||
* // => false
|
||||
*/
|
||||
function inRange(value, start, end) {
|
||||
start = +start || 0;
|
||||
if (typeof end === 'undefined') {
|
||||
end = start;
|
||||
start = 0;
|
||||
} else {
|
||||
end = +end || 0;
|
||||
}
|
||||
return value >= start && value < end;
|
||||
}
|
||||
|
||||
export default inRange;
|
||||
@@ -26,7 +26,9 @@ import keys from './keys';
|
||||
* Shape.call(this);
|
||||
* }
|
||||
*
|
||||
* Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle });
|
||||
* Circle.prototype = _.create(Shape.prototype, {
|
||||
* 'constructor': Circle
|
||||
* });
|
||||
*
|
||||
* var circle = new Circle;
|
||||
* circle instanceof Circle;
|
||||
|
||||
@@ -33,7 +33,9 @@ import baseForOwn from '../internal/baseForOwn';
|
||||
* 'pebbles': { 'age': 1, 'active': true }
|
||||
* };
|
||||
*
|
||||
* _.findKey(users, function(chr) { return chr.age < 40; });
|
||||
* _.findKey(users, function(chr) {
|
||||
* return chr.age < 40;
|
||||
* });
|
||||
* // => 'barney' (iteration order is not guaranteed)
|
||||
*
|
||||
* // using the `_.matches` callback shorthand
|
||||
|
||||
@@ -33,7 +33,9 @@ import baseForOwnRight from '../internal/baseForOwnRight';
|
||||
* 'pebbles': { 'age': 1, 'active': true }
|
||||
* };
|
||||
*
|
||||
* _.findLastKey(users, function(chr) { return chr.age < 40; });
|
||||
* _.findLastKey(users, function(chr) {
|
||||
* return chr.age < 40;
|
||||
* });
|
||||
* // => returns `pebbles` assuming `_.findKey` returns `barney`
|
||||
*
|
||||
* // using the `_.matches` callback shorthand
|
||||
|
||||
@@ -16,10 +16,17 @@ import bindCallback from '../internal/bindCallback';
|
||||
* @returns {Object} Returns `object`.
|
||||
* @example
|
||||
*
|
||||
* _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
|
||||
* function Foo() {
|
||||
* this.a = 1;
|
||||
* this.b = 2;
|
||||
* }
|
||||
*
|
||||
* Foo.prototype.c = 3;
|
||||
*
|
||||
* _.forOwn(new Foo, function(value, key) {
|
||||
* console.log(key);
|
||||
* });
|
||||
* // => logs '0', '1', and 'length' (iteration order is not guaranteed)
|
||||
* // => logs 'a' and 'b' (iteration order is not guaranteed)
|
||||
*/
|
||||
function forOwn(object, iteratee, thisArg) {
|
||||
if (typeof iteratee != 'function' || typeof thisArg != 'undefined') {
|
||||
|
||||
@@ -15,10 +15,17 @@ import keys from './keys';
|
||||
* @returns {Object} Returns `object`.
|
||||
* @example
|
||||
*
|
||||
* _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) {
|
||||
* function Foo() {
|
||||
* this.a = 1;
|
||||
* this.b = 2;
|
||||
* }
|
||||
*
|
||||
* Foo.prototype.c = 3;
|
||||
*
|
||||
* _.forOwnRight(new Foo, function(value, key) {
|
||||
* console.log(key);
|
||||
* });
|
||||
* // => logs 'length', '1', and '0' assuming `_.forOwn` logs '0', '1', and 'length'
|
||||
* // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
|
||||
*/
|
||||
function forOwnRight(object, iteratee, thisArg) {
|
||||
iteratee = bindCallback(iteratee, thisArg, 3);
|
||||
|
||||
@@ -14,7 +14,7 @@ import keysIn from './keysIn';
|
||||
* @example
|
||||
*
|
||||
* _.functions(_);
|
||||
* // => ['all', 'any', 'bind', ...]
|
||||
* // => ['after', 'ary', 'assign', ...]
|
||||
*/
|
||||
function functions(object) {
|
||||
return baseFunctions(object, keysIn(object));
|
||||
|
||||
@@ -16,7 +16,9 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* @returns {boolean} Returns `true` if `key` is a direct property, else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
|
||||
* var object = { 'a': 1, 'b': 2, 'c': 3 };
|
||||
*
|
||||
* _.has(object, 'b');
|
||||
* // => true
|
||||
*/
|
||||
function has(object, key) {
|
||||
|
||||
@@ -21,16 +21,14 @@ var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
* @returns {Object} Returns the new inverted object.
|
||||
* @example
|
||||
*
|
||||
* _.invert({ 'first': 'fred', 'second': 'barney' });
|
||||
* // => { 'fred': 'first', 'barney': 'second' }
|
||||
* var object = { 'a': 1, 'b': 2, 'c': 1 };
|
||||
*
|
||||
* // without `multiValue`
|
||||
* _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' });
|
||||
* // => { 'fred': 'third', 'barney': 'second' }
|
||||
* _.invert(object);
|
||||
* // => { '1': 'c', '2': 'b' }
|
||||
*
|
||||
* // with `multiValue`
|
||||
* _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }, true);
|
||||
* // => { 'fred': ['first', 'third'], 'barney': ['second'] }
|
||||
* _.invert(object, true);
|
||||
* // => { '1': ['a', 'c'], '2': ['b'] }
|
||||
*/
|
||||
function invert(object, multiValue, guard) {
|
||||
if (guard && isIterateeCall(object, multiValue, guard)) {
|
||||
|
||||
@@ -28,8 +28,10 @@ import baseForOwn from '../internal/baseForOwn';
|
||||
* @returns {Object} Returns the new mapped object.
|
||||
* @example
|
||||
*
|
||||
* _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(n) { return n * 3; });
|
||||
* // => { 'a': 3, 'b': 6, 'c': 9 }
|
||||
* _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
|
||||
* return n * 3;
|
||||
* });
|
||||
* // => { 'a': 3, 'b': 6 }
|
||||
*
|
||||
* var users = {
|
||||
* 'fred': { 'user': 'fred', 'age': 40 },
|
||||
|
||||
@@ -43,7 +43,9 @@ import createAssigner from '../internal/createAssigner';
|
||||
* };
|
||||
*
|
||||
* _.merge(object, other, function(a, b) {
|
||||
* return _.isArray(a) ? a.concat(b) : undefined;
|
||||
* if (_.isArray(a)) {
|
||||
* return a.concat(b);
|
||||
* }
|
||||
* });
|
||||
* // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
|
||||
*/
|
||||
|
||||
@@ -25,18 +25,16 @@ import isTypedArray from '../lang/isTypedArray';
|
||||
* @returns {*} Returns the accumulated value.
|
||||
* @example
|
||||
*
|
||||
* var squares = _.transform([1, 2, 3, 4, 5, 6], function(result, n) {
|
||||
* n *= n;
|
||||
* if (n % 2) {
|
||||
* return result.push(n) < 3;
|
||||
* }
|
||||
* _.transform([2, 3, 4], function(result, n) {
|
||||
* result.push(n *= n);
|
||||
* return n % 2 == 0;
|
||||
* });
|
||||
* // => [1, 9, 25]
|
||||
* // => [4, 9]
|
||||
*
|
||||
* var mapped = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) {
|
||||
* _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
|
||||
* result[key] = n * 3;
|
||||
* });
|
||||
* // => { 'a': 3, 'b': 6, 'c': 9 }
|
||||
* // => { 'a': 3, 'b': 6 }
|
||||
*/
|
||||
function transform(object, iteratee, accumulator, thisArg) {
|
||||
var isArr = isArray(object) || isTypedArray(object);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lodash-es",
|
||||
"version": "3.2.0",
|
||||
"version": "3.3.0",
|
||||
"description": "The modern build of lodash exported as ES modules.",
|
||||
"homepage": "https://lodash.com/custom-builds",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import createCompounder from '../internal/createCompounder';
|
||||
|
||||
/**
|
||||
* Converts `string` to kebab case (a.k.a. spinal case).
|
||||
* Converts `string` to kebab case.
|
||||
* See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for
|
||||
* more details.
|
||||
*
|
||||
|
||||
@@ -33,13 +33,21 @@ var reFlags = /\w*$/;
|
||||
* _.trunc('hi-diddly-ho there, neighborino', 24);
|
||||
* // => 'hi-diddly-ho there, n...'
|
||||
*
|
||||
* _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' });
|
||||
* _.trunc('hi-diddly-ho there, neighborino', {
|
||||
* 'length': 24,
|
||||
* 'separator': ' '
|
||||
* });
|
||||
* // => 'hi-diddly-ho there,...'
|
||||
*
|
||||
* _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ });
|
||||
* _.trunc('hi-diddly-ho there, neighborino', {
|
||||
* 'length': 24,
|
||||
* 'separator': /,? +/
|
||||
* });
|
||||
* //=> 'hi-diddly-ho there...'
|
||||
*
|
||||
* _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' });
|
||||
* _.trunc('hi-diddly-ho there, neighborino', {
|
||||
* 'omission': ' [...]'
|
||||
* });
|
||||
* // => 'hi-diddly-ho there, neig [...]'
|
||||
*/
|
||||
function trunc(string, options, guard) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import baseSlice from '../internal/baseSlice';
|
||||
import isError from '../lang/isError';
|
||||
|
||||
/**
|
||||
@@ -21,9 +20,16 @@ import isError from '../lang/isError';
|
||||
* elements = [];
|
||||
* }
|
||||
*/
|
||||
function attempt(func) {
|
||||
function attempt() {
|
||||
var length = arguments.length,
|
||||
func = arguments[0];
|
||||
|
||||
try {
|
||||
return func.apply(undefined, baseSlice(arguments, 1));
|
||||
var args = Array(length ? length - 1 : 0);
|
||||
while (--length > 0) {
|
||||
args[length - 1] = arguments[length];
|
||||
}
|
||||
return func.apply(undefined, args);
|
||||
} catch(e) {
|
||||
return isError(e) ? e : new Error(e);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,9 @@ import matches from './matches';
|
||||
* return callback(func, thisArg);
|
||||
* }
|
||||
* return function(object) {
|
||||
* return match[2] == 'gt' ? object[match[1]] > match[3] : object[match[1]] < match[3];
|
||||
* return match[2] == 'gt'
|
||||
* ? object[match[1]] > match[3]
|
||||
* : object[match[1]] < match[3];
|
||||
* };
|
||||
* });
|
||||
*
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*
|
||||
* var object = { 'user': 'fred' };
|
||||
* var getter = _.constant(object);
|
||||
*
|
||||
* getter() === object;
|
||||
* // => true
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
* @example
|
||||
*
|
||||
* var object = { 'user': 'fred' };
|
||||
*
|
||||
* _.identity(object) === object;
|
||||
* // => true
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* A no-operation function.
|
||||
* A no-operation function which returns `undefined` regardless of the
|
||||
* arguments it receives.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -7,6 +8,7 @@
|
||||
* @example
|
||||
*
|
||||
* var object = { 'user': 'fred' };
|
||||
*
|
||||
* _.noop(object) === undefined;
|
||||
* // => true
|
||||
*/
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var object = { 'user': 'fred', 'age': 40, 'active': true };
|
||||
* _.map(['active', 'user'], _.propertyOf(object));
|
||||
* // => [true, 'fred']
|
||||
*
|
||||
* var object = { 'a': 3, 'b': 1, 'c': 2 };
|
||||
*
|
||||
* _.map(['a', 'c'], _.propertyOf(object));
|
||||
* // => [3, 2]
|
||||
*
|
||||
* _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
|
||||
* // => ['b', 'c', 'a']
|
||||
*/
|
||||
|
||||
@@ -8,8 +8,9 @@ var nativeMax = Math.max;
|
||||
|
||||
/**
|
||||
* Creates an array of numbers (positive and/or negative) progressing from
|
||||
* `start` up to, but not including, `end`. If `start` is less than `end` a
|
||||
* zero-length range is created unless a negative `step` is specified.
|
||||
* `start` up to, but not including, `end`. If `end` is not specified it
|
||||
* defaults to `start` with `start` becoming `0`. If `start` is less than
|
||||
* `end` a zero-length range is created unless a negative `step` is specified.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
|
||||
@@ -25,10 +25,14 @@ var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1;
|
||||
* var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
|
||||
* // => [3, 6, 4]
|
||||
*
|
||||
* _.times(3, function(n) { mage.castSpell(n); });
|
||||
* _.times(3, function(n) {
|
||||
* mage.castSpell(n);
|
||||
* });
|
||||
* // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2` respectively
|
||||
*
|
||||
* _.times(3, function(n) { this.cast(n); }, mage);
|
||||
* _.times(3, function(n) {
|
||||
* this.cast(n);
|
||||
* }, mage);
|
||||
* // => also invokes `mage.castSpell(n)` three times
|
||||
*/
|
||||
function times(n, iteratee, thisArg) {
|
||||
|
||||
Reference in New Issue
Block a user