mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8e4370129 | ||
|
|
3ccb5e7da3 |
@@ -1,4 +1,4 @@
|
||||
# lodash v3.1.0
|
||||
# lodash v3.3.0
|
||||
|
||||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) exported as [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules.
|
||||
|
||||
|
||||
3
array.js
3
array.js
@@ -1,4 +1,4 @@
|
||||
define(['./array/chunk', './array/compact', './array/difference', './array/drop', './array/dropRight', './array/dropRightWhile', './array/dropWhile', './array/findIndex', './array/findLastIndex', './array/first', './array/flatten', './array/flattenDeep', './array/head', './array/indexOf', './array/initial', './array/intersection', './array/last', './array/lastIndexOf', './array/object', './array/pull', './array/pullAt', './array/remove', './array/rest', './array/slice', './array/sortedIndex', './array/sortedLastIndex', './array/tail', './array/take', './array/takeRight', './array/takeRightWhile', './array/takeWhile', './array/union', './array/uniq', './array/unique', './array/unzip', './array/without', './array/xor', './array/zip', './array/zipObject'], function(chunk, compact, difference, drop, dropRight, dropRightWhile, dropWhile, findIndex, findLastIndex, first, flatten, flattenDeep, head, indexOf, initial, intersection, last, lastIndexOf, object, pull, pullAt, remove, rest, slice, sortedIndex, sortedLastIndex, tail, take, takeRight, takeRightWhile, takeWhile, union, uniq, unique, unzip, without, xor, zip, zipObject) {
|
||||
define(['./array/chunk', './array/compact', './array/difference', './array/drop', './array/dropRight', './array/dropRightWhile', './array/dropWhile', './array/fill', './array/findIndex', './array/findLastIndex', './array/first', './array/flatten', './array/flattenDeep', './array/head', './array/indexOf', './array/initial', './array/intersection', './array/last', './array/lastIndexOf', './array/object', './array/pull', './array/pullAt', './array/remove', './array/rest', './array/slice', './array/sortedIndex', './array/sortedLastIndex', './array/tail', './array/take', './array/takeRight', './array/takeRightWhile', './array/takeWhile', './array/union', './array/uniq', './array/unique', './array/unzip', './array/without', './array/xor', './array/zip', './array/zipObject'], function(chunk, compact, difference, drop, dropRight, dropRightWhile, dropWhile, fill, findIndex, findLastIndex, first, flatten, flattenDeep, head, indexOf, initial, intersection, last, lastIndexOf, object, pull, pullAt, remove, rest, slice, sortedIndex, sortedLastIndex, tail, take, takeRight, takeRightWhile, takeWhile, union, uniq, unique, unzip, without, xor, zip, zipObject) {
|
||||
return {
|
||||
'chunk': chunk,
|
||||
'compact': compact,
|
||||
@@ -7,6 +7,7 @@ define(['./array/chunk', './array/compact', './array/difference', './array/drop'
|
||||
'dropRight': dropRight,
|
||||
'dropRightWhile': dropRightWhile,
|
||||
'dropWhile': dropWhile,
|
||||
'fill': fill,
|
||||
'findIndex': findIndex,
|
||||
'findLastIndex': findLastIndex,
|
||||
'first': first,
|
||||
|
||||
@@ -15,7 +15,7 @@ define(['../internal/baseSlice', '../internal/isIterateeCall'], function(baseSli
|
||||
* @memberOf _
|
||||
* @category Array
|
||||
* @param {Array} array The array to process.
|
||||
* @param {numer} [size=1] The length of each chunk.
|
||||
* @param {number} [size=1] The length of each chunk.
|
||||
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
||||
* @returns {Array} Returns the new array containing chunks.
|
||||
* @example
|
||||
|
||||
@@ -17,7 +17,7 @@ define(['../internal/baseDifference', '../internal/baseFlatten', '../lang/isArgu
|
||||
* @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() {
|
||||
|
||||
@@ -5,7 +5,6 @@ define(['../internal/baseSlice', '../internal/isIterateeCall'], function(baseSli
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @category Array
|
||||
* @param {Array} array The array to query.
|
||||
* @param {number} [n=1] The number of elements to drop.
|
||||
|
||||
@@ -5,7 +5,6 @@ define(['../internal/baseSlice', '../internal/isIterateeCall'], function(baseSli
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @category Array
|
||||
* @param {Array} array The array to query.
|
||||
* @param {number} [n=1] The number of elements to drop.
|
||||
|
||||
@@ -5,40 +5,49 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb
|
||||
* Elements are dropped until `predicate` returns falsey. The predicate is
|
||||
* bound to `thisArg` and invoked with three arguments; (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* callback returns `true` for elements that have the properties of the given
|
||||
* 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 match the properties of the given
|
||||
* object, else `false`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @category Array
|
||||
* @param {Array} array The array to query.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per element.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @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 = [
|
||||
* { 'user': 'barney', 'status': 'busy', 'active': false },
|
||||
* { 'user': 'fred', 'status': 'busy', 'active': true },
|
||||
* { 'user': 'pebbles', 'status': 'away', 'active': true }
|
||||
* { 'user': 'barney', 'active': true },
|
||||
* { 'user': 'fred', 'active': false },
|
||||
* { 'user': 'pebbles', 'active': false }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.pluck(_.dropRightWhile(users, 'active'), 'user');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.pluck(_.dropRightWhile(users, { 'user': pebbles, 'active': false }), 'user');
|
||||
* // => ['barney', 'fred']
|
||||
*
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.pluck(_.dropRightWhile(users, 'active', false), 'user');
|
||||
* // => ['barney']
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user');
|
||||
* // => ['barney', 'fred']
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.pluck(_.dropRightWhile(users, 'active'), 'user');
|
||||
* // => ['barney', 'fred', 'pebbles']
|
||||
*/
|
||||
function dropRightWhile(array, predicate, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
|
||||
@@ -5,40 +5,49 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb
|
||||
* Elements are dropped until `predicate` returns falsey. The predicate is
|
||||
* bound to `thisArg` and invoked with three arguments; (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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 _
|
||||
* @type Function
|
||||
* @category Array
|
||||
* @param {Array} array The array to query.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per element.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @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 = [
|
||||
* { 'user': 'barney', 'status': 'busy', 'active': true },
|
||||
* { 'user': 'fred', 'status': 'busy', 'active': false },
|
||||
* { 'user': 'pebbles', 'status': 'away', 'active': true }
|
||||
* { 'user': 'barney', 'active': false },
|
||||
* { 'user': 'fred', 'active': false },
|
||||
* { 'user': 'pebbles', 'active': true }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.pluck(_.dropWhile(users, 'active'), 'user');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
|
||||
* // => ['fred', 'pebbles']
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user');
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.pluck(_.dropWhile(users, 'active', false), 'user');
|
||||
* // => ['pebbles']
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.pluck(_.dropWhile(users, 'active'), 'user');
|
||||
* // => ['barney', 'fred', 'pebbles']
|
||||
*/
|
||||
function dropWhile(array, predicate, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
|
||||
31
array/fill.js
Normal file
31
array/fill.js
Normal file
@@ -0,0 +1,31 @@
|
||||
define(['../internal/baseFill', '../internal/isIterateeCall'], function(baseFill, isIterateeCall) {
|
||||
|
||||
/**
|
||||
* Fills elements of `array` with `value` from `start` up to, but not
|
||||
* including, `end`.
|
||||
*
|
||||
* **Note:** This method mutates `array`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Array
|
||||
* @param {Array} array The array to fill.
|
||||
* @param {*} value The value to fill `array` with.
|
||||
* @param {number} [start=0] The start position.
|
||||
* @param {number} [end=array.length] The end position.
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function fill(array, value, start, end) {
|
||||
var length = array ? array.length : 0;
|
||||
if (!length) {
|
||||
return [];
|
||||
}
|
||||
if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
|
||||
start = 0;
|
||||
end = length;
|
||||
}
|
||||
return baseFill(array, value, start, end);
|
||||
}
|
||||
|
||||
return fill;
|
||||
});
|
||||
@@ -4,10 +4,14 @@ define(['../internal/baseCallback'], function(baseCallback) {
|
||||
* This method is like `_.find` except that it returns the index of the first
|
||||
* element `predicate` returns truthy for, instead of the element itself.
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -16,28 +20,33 @@ define(['../internal/baseCallback'], function(baseCallback) {
|
||||
* @category Array
|
||||
* @param {Array} array The array to search.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @returns {number} Returns the index of the found element, else `-1`.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 36, 'active': false },
|
||||
* { 'user': 'fred', 'age': 40, 'active': true },
|
||||
* { 'user': 'pebbles', 'age': 1, 'active': false }
|
||||
* { 'user': 'barney', 'active': false },
|
||||
* { 'user': 'fred', 'active': false },
|
||||
* { 'user': 'pebbles', 'active': true }
|
||||
* ];
|
||||
*
|
||||
* _.findIndex(users, function(chr) { return chr.age < 40; });
|
||||
* _.findIndex(users, function(chr) {
|
||||
* return chr.user == 'barney';
|
||||
* });
|
||||
* // => 0
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.findIndex(users, { 'age': 1 });
|
||||
* // => 2
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.findIndex(users, 'active');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.findIndex(users, { 'user': 'fred', 'active': false });
|
||||
* // => 1
|
||||
*
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.findIndex(users, 'active', false);
|
||||
* // => 0
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.findIndex(users, 'active');
|
||||
* // => 2
|
||||
*/
|
||||
function findIndex(array, predicate, thisArg) {
|
||||
var index = -1,
|
||||
|
||||
@@ -4,10 +4,14 @@ define(['../internal/baseCallback'], function(baseCallback) {
|
||||
* This method is like `_.findIndex` except that it iterates over elements
|
||||
* of `collection` from right to left.
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -16,26 +20,31 @@ define(['../internal/baseCallback'], function(baseCallback) {
|
||||
* @category Array
|
||||
* @param {Array} array The array to search.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @returns {number} Returns the index of the found element, else `-1`.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 36, 'active': true },
|
||||
* { 'user': 'fred', 'age': 40, 'active': false },
|
||||
* { 'user': 'pebbles', 'age': 1, 'active': false }
|
||||
* { 'user': 'barney', 'active': true },
|
||||
* { 'user': 'fred', 'active': false },
|
||||
* { 'user': 'pebbles', 'active': false }
|
||||
* ];
|
||||
*
|
||||
* _.findLastIndex(users, function(chr) { return chr.age < 40; });
|
||||
* _.findLastIndex(users, function(chr) {
|
||||
* return chr.user == 'pebbles';
|
||||
* });
|
||||
* // => 2
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.findLastIndex(users, { 'age': 40 });
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.findLastIndex(users, { user': 'barney', 'active': true });
|
||||
* // => 0
|
||||
*
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.findLastIndex(users, 'active', false);
|
||||
* // => 1
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.findLastIndex(users, 'active');
|
||||
* // => 0
|
||||
*/
|
||||
|
||||
@@ -13,11 +13,11 @@ define(['../internal/baseFlatten', '../internal/isIterateeCall'], function(baseF
|
||||
* @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 @@ define(['../internal/baseFlatten'], function(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) {
|
||||
|
||||
@@ -24,15 +24,15 @@ define(['../internal/baseIndexOf', '../internal/binaryIndex'], function(baseInde
|
||||
* @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) {
|
||||
|
||||
@@ -15,9 +15,8 @@ define(['../internal/baseIndexOf', '../internal/cacheIndexOf', '../internal/crea
|
||||
* @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 = [],
|
||||
|
||||
@@ -18,15 +18,15 @@ define(['../internal/binaryIndex', '../internal/indexOfNaN'], function(binaryInd
|
||||
* @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 @@ define(['../internal/baseIndexOf'], function(baseIndexOf) {
|
||||
* @example
|
||||
*
|
||||
* var array = [1, 2, 3, 1, 2, 3];
|
||||
*
|
||||
* _.pull(array, 2, 3);
|
||||
* console.log(array);
|
||||
* // => [1, 1]
|
||||
|
||||
@@ -17,7 +17,7 @@ define(['../internal/baseFlatten', '../internal/basePullAt'], function(baseFlatt
|
||||
* @example
|
||||
*
|
||||
* var array = [5, 10, 15, 20];
|
||||
* var evens = _.pullAt(array, [1, 3]);
|
||||
* var evens = _.pullAt(array, 1, 3);
|
||||
*
|
||||
* console.log(array);
|
||||
* // => [5, 15]
|
||||
|
||||
@@ -11,10 +11,14 @@ define(['../internal/baseCallback'], function(baseCallback) {
|
||||
* and returns an array of the removed elements. The predicate is bound to
|
||||
* `thisArg` and invoked with three arguments; (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -25,14 +29,15 @@ define(['../internal/baseCallback'], function(baseCallback) {
|
||||
* @category Array
|
||||
* @param {Array} array The array to modify.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @returns {Array} Returns the new array of removed elements.
|
||||
* @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]
|
||||
|
||||
@@ -7,10 +7,14 @@ define(['../internal/baseCallback', '../internal/binaryIndex', '../internal/bina
|
||||
* to compute their sort ranking. The iteratee is bound to `thisArg` and
|
||||
* invoked with one argument; (value).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -20,8 +24,7 @@ define(['../internal/baseCallback', '../internal/binaryIndex', '../internal/bina
|
||||
* @param {Array} array The sorted array to inspect.
|
||||
* @param {*} value The value to evaluate.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {number} Returns the index at which `value` should be inserted
|
||||
* into `array`.
|
||||
@@ -30,7 +33,7 @@ define(['../internal/baseCallback', '../internal/binaryIndex', '../internal/bina
|
||||
* _.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 } };
|
||||
@@ -41,7 +44,7 @@ define(['../internal/baseCallback', '../internal/binaryIndex', '../internal/bina
|
||||
* }, dict);
|
||||
* // => 1
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
|
||||
* // => 1
|
||||
*/
|
||||
|
||||
@@ -11,14 +11,13 @@ define(['../internal/baseCallback', '../internal/binaryIndex', '../internal/bina
|
||||
* @param {Array} array The sorted array to inspect.
|
||||
* @param {*} value The value to evaluate.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {number} Returns the index at which `value` should be inserted
|
||||
* into `array`.
|
||||
* @example
|
||||
*
|
||||
* _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5);
|
||||
* _.sortedLastIndex([4, 4, 5, 5], 5);
|
||||
* // => 4
|
||||
*/
|
||||
function sortedLastIndex(array, value, iteratee, thisArg) {
|
||||
|
||||
@@ -5,7 +5,6 @@ define(['../internal/baseSlice', '../internal/isIterateeCall'], function(baseSli
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @category Array
|
||||
* @param {Array} array The array to query.
|
||||
* @param {number} [n=1] The number of elements to take.
|
||||
|
||||
@@ -5,7 +5,6 @@ define(['../internal/baseSlice', '../internal/isIterateeCall'], function(baseSli
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @category Array
|
||||
* @param {Array} array The array to query.
|
||||
* @param {number} [n=1] The number of elements to take.
|
||||
|
||||
@@ -5,40 +5,49 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb
|
||||
* taken until `predicate` returns falsey. The predicate is bound to `thisArg`
|
||||
* and invoked with three arguments; (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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 _
|
||||
* @type Function
|
||||
* @category Array
|
||||
* @param {Array} array The array to query.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per element.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @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 = [
|
||||
* { 'user': 'barney', 'status': 'busy', 'active': false },
|
||||
* { 'user': 'fred', 'status': 'busy', 'active': true },
|
||||
* { 'user': 'pebbles', 'status': 'away', 'active': true }
|
||||
* { 'user': 'barney', 'active': true },
|
||||
* { 'user': 'fred', 'active': false },
|
||||
* { 'user': 'pebbles', 'active': false }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.pluck(_.takeRightWhile(users, 'active'), 'user');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
|
||||
* // => ['pebbles']
|
||||
*
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.pluck(_.takeRightWhile(users, 'active', false), 'user');
|
||||
* // => ['fred', 'pebbles']
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.pluck(_.takeRightWhile(users, { 'status': 'away' }), 'user');
|
||||
* // => ['pebbles']
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.pluck(_.takeRightWhile(users, 'active'), 'user');
|
||||
* // => []
|
||||
*/
|
||||
function takeRightWhile(array, predicate, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
|
||||
@@ -5,40 +5,49 @@ define(['../internal/baseCallback', '../internal/baseSlice'], function(baseCallb
|
||||
* are taken until `predicate` returns falsey. The predicate is bound to
|
||||
* `thisArg` and invoked with three arguments; (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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 _
|
||||
* @type Function
|
||||
* @category Array
|
||||
* @param {Array} array The array to query.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per element.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @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 = [
|
||||
* { 'user': 'barney', 'status': 'busy', 'active': true },
|
||||
* { 'user': 'fred', 'status': 'busy', 'active': false },
|
||||
* { 'user': 'pebbles', 'status': 'away', 'active': true }
|
||||
* { 'user': 'barney', 'active': false },
|
||||
* { 'user': 'fred', 'active': false},
|
||||
* { 'user': 'pebbles', 'active': true }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.pluck(_.takeWhile(users, 'active'), 'user');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
|
||||
* // => ['barney']
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.pluck(_.takeWhile(users, { 'status': 'busy' }), 'user');
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.pluck(_.takeWhile(users, 'active', false), 'user');
|
||||
* // => ['barney', 'fred']
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.pluck(_.takeWhile(users, 'active'), 'user');
|
||||
* // => []
|
||||
*/
|
||||
function takeWhile(array, predicate, thisArg) {
|
||||
var length = array ? array.length : 0;
|
||||
|
||||
@@ -16,8 +16,8 @@ define(['../internal/baseFlatten', '../internal/baseUniq'], function(baseFlatten
|
||||
* @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));
|
||||
|
||||
@@ -8,10 +8,14 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera
|
||||
* uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked
|
||||
* with three arguments; (value, index, array).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -27,8 +31,6 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera
|
||||
* @param {Array} array The array to inspect.
|
||||
* @param {boolean} [isSorted] Specify the array is sorted.
|
||||
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
|
||||
* If a property name or object is provided it is used to create a "_.property"
|
||||
* or "_.matches" style callback respectively.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {Array} Returns the new duplicate-value-free array.
|
||||
* @example
|
||||
@@ -41,10 +43,12 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera
|
||||
* // => [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
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
|
||||
* // => [{ 'x': 1 }, { 'x': 2 }]
|
||||
*/
|
||||
@@ -53,8 +57,7 @@ define(['../internal/baseCallback', '../internal/baseUniq', '../internal/isItera
|
||||
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;
|
||||
|
||||
@@ -17,8 +17,8 @@ define(['../internal/baseDifference', '../internal/baseSlice'], function(baseDif
|
||||
* @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));
|
||||
|
||||
@@ -12,11 +12,8 @@ define(['../internal/baseDifference', '../internal/baseUniq', '../lang/isArgumen
|
||||
* @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,
|
||||
|
||||
5
chain.js
5
chain.js
@@ -1,8 +1,11 @@
|
||||
define(['./chain/chain', './chain/lodash', './chain/reverse', './chain/tap', './chain/thru', './chain/toJSON', './chain/toString', './chain/value', './chain/valueOf', './chain/wrapperChain'], function(chain, lodash, reverse, tap, thru, toJSON, toString, value, valueOf, wrapperChain) {
|
||||
define(['./chain/chain', './chain/commit', './chain/lodash', './chain/plant', './chain/reverse', './chain/run', './chain/tap', './chain/thru', './chain/toJSON', './chain/toString', './chain/value', './chain/valueOf', './chain/wrapperChain'], function(chain, commit, lodash, plant, reverse, run, tap, thru, toJSON, toString, value, valueOf, wrapperChain) {
|
||||
return {
|
||||
'chain': chain,
|
||||
'commit': commit,
|
||||
'lodash': lodash,
|
||||
'plant': plant,
|
||||
'reverse': reverse,
|
||||
'run': run,
|
||||
'tap': tap,
|
||||
'thru': thru,
|
||||
'toJSON': toJSON,
|
||||
|
||||
@@ -8,7 +8,7 @@ define(['./lodash'], function(lodash) {
|
||||
* @memberOf _
|
||||
* @category Chain
|
||||
* @param {*} value The value to wrap.
|
||||
* @returns {Object} Returns the new `lodash` object.
|
||||
* @returns {Object} Returns the new `lodash` wrapper instance.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
@@ -19,7 +19,9 @@ define(['./lodash'], function(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'
|
||||
|
||||
3
chain/commit.js
Normal file
3
chain/commit.js
Normal file
@@ -0,0 +1,3 @@
|
||||
define(["./wrapperCommit"], function(wrapperCommit) {
|
||||
return wrapperCommit;
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['../internal/LodashWrapper', '../internal/arrayCopy', '../lang/isArray', '../internal/isObjectLike'], function(LodashWrapper, arrayCopy, isArray, isObjectLike) {
|
||||
define(['../internal/LazyWrapper', '../internal/LodashWrapper', '../internal/baseLodash', '../lang/isArray', '../internal/isObjectLike', '../internal/wrapperClone'], function(LazyWrapper, LodashWrapper, baseLodash, isArray, isObjectLike, wrapperClone) {
|
||||
|
||||
/** Used for native method references. */
|
||||
var objectProto = Object.prototype;
|
||||
@@ -7,7 +7,7 @@ define(['../internal/LodashWrapper', '../internal/arrayCopy', '../lang/isArray',
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* Creates a `lodash` object which wraps `value` to enable intuitive chaining.
|
||||
* Creates a `lodash` object which wraps `value` to enable implicit chaining.
|
||||
* Methods that operate on and return arrays, collections, and functions can
|
||||
* be chained together. Methods that return a boolean or single value will
|
||||
* automatically end the chain returning the unwrapped value. Explicit chaining
|
||||
@@ -26,29 +26,31 @@ define(['../internal/LodashWrapper', '../internal/arrayCopy', '../lang/isArray',
|
||||
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
|
||||
* and `unshift`
|
||||
*
|
||||
* The wrapper functions that support shortcut fusion are:
|
||||
* `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `first`,
|
||||
* `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, `slice`,
|
||||
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `where`
|
||||
* The wrapper methods that support shortcut fusion are:
|
||||
* `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
|
||||
* `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
|
||||
* `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
|
||||
* and `where`
|
||||
*
|
||||
* The chainable wrapper functions are:
|
||||
* The chainable wrapper methods are:
|
||||
* `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
|
||||
* `callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`,
|
||||
* `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`,
|
||||
* `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`,
|
||||
* `flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`,
|
||||
* `forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`,
|
||||
* `initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`,
|
||||
* `mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`,
|
||||
* `omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`,
|
||||
* `pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`,
|
||||
* `rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
|
||||
* `sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`,
|
||||
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
|
||||
* `transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`,
|
||||
* `where`, `without`, `wrap`, `xor`, `zip`, and `zipObject`
|
||||
* `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
|
||||
* `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`,
|
||||
* `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`,
|
||||
* `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`,
|
||||
* `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`,
|
||||
* `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`,
|
||||
* `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`,
|
||||
* `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
||||
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
|
||||
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
|
||||
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `splice`, `spread`,
|
||||
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
|
||||
* `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`,
|
||||
* `unshift`, `unzip`, `values`, `valuesIn`, `where`, `without`, `wrap`, `xor`,
|
||||
* `zip`, and `zipObject`
|
||||
*
|
||||
* The wrapper functions that are **not** chainable by default are:
|
||||
* The wrapper methods that are **not** chainable by default are:
|
||||
* `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`,
|
||||
* `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
|
||||
* `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`,
|
||||
@@ -63,24 +65,28 @@ define(['../internal/LodashWrapper', '../internal/arrayCopy', '../lang/isArray',
|
||||
* `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`,
|
||||
* `trunc`, `unescape`, `uniqueId`, `value`, and `words`
|
||||
*
|
||||
* The wrapper function `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.
|
||||
*
|
||||
* @name _
|
||||
* @constructor
|
||||
* @category Chain
|
||||
* @param {*} value The value to wrap in a `lodash` instance.
|
||||
* @returns {Object} Returns a `lodash` instance.
|
||||
* @returns {Object} Returns the new `lodash` wrapper instance.
|
||||
* @example
|
||||
*
|
||||
* 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
|
||||
@@ -89,19 +95,19 @@ define(['../internal/LodashWrapper', '../internal/arrayCopy', '../lang/isArray',
|
||||
* // => true
|
||||
*/
|
||||
function lodash(value) {
|
||||
if (isObjectLike(value) && !isArray(value)) {
|
||||
if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
|
||||
if (value instanceof LodashWrapper) {
|
||||
return value;
|
||||
}
|
||||
if (hasOwnProperty.call(value, '__wrapped__')) {
|
||||
return new LodashWrapper(value.__wrapped__, value.__chain__, arrayCopy(value.__actions__));
|
||||
if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
|
||||
return wrapperClone(value);
|
||||
}
|
||||
}
|
||||
return new LodashWrapper(value);
|
||||
}
|
||||
|
||||
// Ensure `new LodashWrapper` is an instance of `lodash`.
|
||||
LodashWrapper.prototype = lodash.prototype;
|
||||
// Ensure wrappers are instances of `baseLodash`.
|
||||
lodash.prototype = baseLodash.prototype;
|
||||
|
||||
return lodash;
|
||||
});
|
||||
|
||||
3
chain/plant.js
Normal file
3
chain/plant.js
Normal file
@@ -0,0 +1,3 @@
|
||||
define(["./wrapperPlant"], function(wrapperPlant) {
|
||||
return wrapperPlant;
|
||||
});
|
||||
3
chain/run.js
Normal file
3
chain/run.js
Normal file
@@ -0,0 +1,3 @@
|
||||
define(["./wrapperValue"], function(wrapperValue) {
|
||||
return wrapperValue;
|
||||
});
|
||||
@@ -16,7 +16,9 @@ define([], function() {
|
||||
* @example
|
||||
*
|
||||
* _([1, 2, 3])
|
||||
* .tap(function(array) { array.pop(); })
|
||||
* .tap(function(array) {
|
||||
* array.pop();
|
||||
* })
|
||||
* .reverse()
|
||||
* .value();
|
||||
* // => [2, 1]
|
||||
|
||||
@@ -14,7 +14,9 @@ define([], function() {
|
||||
*
|
||||
* _([1, 2, 3])
|
||||
* .last()
|
||||
* .thru(function(value) { return [value]; })
|
||||
* .thru(function(value) {
|
||||
* return [value];
|
||||
* })
|
||||
* .value();
|
||||
* // => [3]
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@ define(['./chain'], function(chain) {
|
||||
* @name chain
|
||||
* @memberOf _
|
||||
* @category Chain
|
||||
* @returns {*} Returns the `lodash` object.
|
||||
* @returns {Object} Returns the new `lodash` wrapper instance.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
|
||||
33
chain/wrapperCommit.js
Normal file
33
chain/wrapperCommit.js
Normal file
@@ -0,0 +1,33 @@
|
||||
define(['../internal/LodashWrapper'], function(LodashWrapper) {
|
||||
|
||||
/**
|
||||
* Executes the chained sequence and returns the wrapped result.
|
||||
*
|
||||
* @name commit
|
||||
* @memberOf _
|
||||
* @category Chain
|
||||
* @returns {Object} Returns the new `lodash` wrapper instance.
|
||||
* @example
|
||||
*
|
||||
* var array = [1, 2];
|
||||
* var wrapper = _(array).push(3);
|
||||
*
|
||||
* console.log(array);
|
||||
* // => [1, 2]
|
||||
*
|
||||
* wrapper = wrapper.commit();
|
||||
* console.log(array);
|
||||
* // => [1, 2, 3]
|
||||
*
|
||||
* wrapper.last();
|
||||
* // => 3
|
||||
*
|
||||
* console.log(array);
|
||||
* // => [1, 2, 3]
|
||||
*/
|
||||
function wrapperCommit() {
|
||||
return new LodashWrapper(this.value(), this.__chain__);
|
||||
}
|
||||
|
||||
return wrapperCommit;
|
||||
});
|
||||
45
chain/wrapperPlant.js
Normal file
45
chain/wrapperPlant.js
Normal file
@@ -0,0 +1,45 @@
|
||||
define(['../internal/baseLodash', '../internal/wrapperClone'], function(baseLodash, wrapperClone) {
|
||||
|
||||
/**
|
||||
* Creates a clone of the chained sequence planting `value` as the wrapped value.
|
||||
*
|
||||
* @name plant
|
||||
* @memberOf _
|
||||
* @category Chain
|
||||
* @returns {Object} Returns the new `lodash` wrapper instance.
|
||||
* @example
|
||||
*
|
||||
* var array = [1, 2];
|
||||
* var wrapper = _(array).map(function(value) {
|
||||
* return Math.pow(value, 2);
|
||||
* });
|
||||
*
|
||||
* var other = [3, 4];
|
||||
* var otherWrapper = wrapper.plant(other);
|
||||
*
|
||||
* otherWrapper.value();
|
||||
* // => [9, 16]
|
||||
*
|
||||
* wrapper.value();
|
||||
* // => [1, 4]
|
||||
*/
|
||||
function wrapperPlant(value) {
|
||||
var result,
|
||||
parent = this;
|
||||
|
||||
while (parent instanceof baseLodash) {
|
||||
var clone = wrapperClone(parent);
|
||||
if (result) {
|
||||
previous.__wrapped__ = clone;
|
||||
} else {
|
||||
result = clone;
|
||||
}
|
||||
var previous = clone;
|
||||
parent = parent.__wrapped__;
|
||||
}
|
||||
previous.__wrapped__ = value;
|
||||
return result;
|
||||
}
|
||||
|
||||
return wrapperPlant;
|
||||
});
|
||||
@@ -9,7 +9,7 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', './thru'], funct
|
||||
* @name reverse
|
||||
* @memberOf _
|
||||
* @category Chain
|
||||
* @returns {Object} Returns the new reversed `lodash` object.
|
||||
* @returns {Object} Returns the new reversed `lodash` wrapper instance.
|
||||
* @example
|
||||
*
|
||||
* var array = [1, 2, 3];
|
||||
@@ -26,7 +26,7 @@ define(['../internal/LazyWrapper', '../internal/LodashWrapper', './thru'], funct
|
||||
if (this.__actions__.length) {
|
||||
value = new LazyWrapper(this);
|
||||
}
|
||||
return new LodashWrapper(value.reverse());
|
||||
return new LodashWrapper(value.reverse(), this.__chain__);
|
||||
}
|
||||
return this.thru(function(value) {
|
||||
return value.reverse();
|
||||
|
||||
@@ -5,7 +5,7 @@ define(['../internal/baseWrapperValue'], function(baseWrapperValue) {
|
||||
*
|
||||
* @name value
|
||||
* @memberOf _
|
||||
* @alias toJSON, valueOf
|
||||
* @alias run, toJSON, valueOf
|
||||
* @category Chain
|
||||
* @returns {*} Returns the resolved unwrapped value.
|
||||
* @example
|
||||
|
||||
@@ -14,8 +14,8 @@ define(['../internal/baseAt', '../internal/baseFlatten', '../internal/isLength',
|
||||
* @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']
|
||||
|
||||
@@ -13,10 +13,14 @@ define(['../internal/createAggregator'], function(createAggregator) {
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -25,16 +29,19 @@ define(['../internal/createAggregator'], function(createAggregator) {
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @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');
|
||||
|
||||
@@ -5,10 +5,14 @@ define(['../internal/arrayEvery', '../internal/baseCallback', '../internal/baseE
|
||||
* The predicate is bound to `thisArg` and invoked with three arguments;
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -18,27 +22,30 @@ define(['../internal/arrayEvery', '../internal/baseCallback', '../internal/baseE
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @returns {boolean} Returns `true` if all elements pass the predicate check,
|
||||
* else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.every([true, 1, null, 'yes']);
|
||||
* _.every([true, 1, null, 'yes'], Boolean);
|
||||
* // => false
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 36 },
|
||||
* { 'user': 'fred', 'age': 40 }
|
||||
* { 'user': 'barney', 'active': false },
|
||||
* { 'user': 'fred', 'active': false }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.every(users, 'age');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.every(users, { 'user': 'barney', 'active': false });
|
||||
* // => false
|
||||
*
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.every(users, 'active', false);
|
||||
* // => true
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.every(users, { 'age': 36 });
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.every(users, 'active');
|
||||
* // => false
|
||||
*/
|
||||
function every(collection, predicate, thisArg) {
|
||||
|
||||
@@ -5,10 +5,14 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base
|
||||
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
|
||||
* invoked with three arguments; (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -18,26 +22,31 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @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': false },
|
||||
* { 'user': 'fred', 'age': 40, 'active': true }
|
||||
* { 'user': 'barney', 'age': 36, 'active': true },
|
||||
* { 'user': 'fred', 'age': 40, 'active': false }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.pluck(_.filter(users, 'active'), 'user');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
|
||||
* // => ['barney']
|
||||
*
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.pluck(_.filter(users, 'active', false), 'user');
|
||||
* // => ['fred']
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.pluck(_.filter(users, { 'age': 36 }), 'user');
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.pluck(_.filter(users, 'active'), 'user');
|
||||
* // => ['barney']
|
||||
*/
|
||||
function filter(collection, predicate, thisArg) {
|
||||
|
||||
@@ -8,10 +8,14 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseFin
|
||||
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
|
||||
* invoked with three arguments; (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -21,28 +25,33 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseFin
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to search.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @returns {*} Returns the matched element, else `undefined`.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 36, 'active': false },
|
||||
* { 'user': 'fred', 'age': 40, 'active': true },
|
||||
* { 'user': 'pebbles', 'age': 1, 'active': false }
|
||||
* { 'user': 'barney', 'age': 36, 'active': true },
|
||||
* { 'user': 'fred', 'age': 40, 'active': false },
|
||||
* { '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
|
||||
* _.result(_.find(users, { 'age': 1 }), 'user');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
|
||||
* // => 'pebbles'
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.result(_.find(users, 'active'), 'user');
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.result(_.find(users, 'active', false), 'user');
|
||||
* // => 'fred'
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.result(_.find(users, 'active'), 'user');
|
||||
* // => 'barney'
|
||||
*/
|
||||
function find(collection, predicate, thisArg) {
|
||||
if (isArray(collection)) {
|
||||
|
||||
@@ -9,13 +9,14 @@ define(['../internal/baseCallback', '../internal/baseEachRight', '../internal/ba
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to search.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @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) {
|
||||
|
||||
@@ -5,6 +5,11 @@ define(['../internal/baseMatches', './find'], function(baseMatches, find) {
|
||||
* source object, returning the first element that has equivalent property
|
||||
* values.
|
||||
*
|
||||
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
|
||||
* numbers, `Object` objects, regexes, and strings. Objects are compared by
|
||||
* their own, not inherited, enumerable properties. For comparing a single
|
||||
* own or inherited property value see `_.matchesProperty`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
@@ -14,14 +19,14 @@ define(['../internal/baseMatches', './find'], function(baseMatches, find) {
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 36, 'status': 'busy' },
|
||||
* { 'user': 'fred', 'age': 40, 'status': 'busy' }
|
||||
* { 'user': 'barney', 'age': 36, 'active': true },
|
||||
* { 'user': 'fred', 'age': 40, 'active': false }
|
||||
* ];
|
||||
*
|
||||
* _.result(_.findWhere(users, { 'status': 'busy' }), 'user');
|
||||
* _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
|
||||
* // => 'barney'
|
||||
*
|
||||
* _.result(_.findWhere(users, { 'age': 40 }), 'user');
|
||||
* _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
|
||||
* // => 'fred'
|
||||
*/
|
||||
function findWhere(collection, source) {
|
||||
|
||||
@@ -20,10 +20,14 @@ define(['../internal/arrayEach', '../internal/baseEach', '../internal/bindCallba
|
||||
* @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) {
|
||||
|
||||
@@ -14,7 +14,9 @@ define(['../internal/arrayEachRight', '../internal/baseEachRight', '../internal/
|
||||
* @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) {
|
||||
|
||||
@@ -13,10 +13,14 @@ define(['../internal/createAggregator'], function(createAggregator) {
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -25,19 +29,22 @@ define(['../internal/createAggregator'], function(createAggregator) {
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @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
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.groupBy(['one', 'two', 'three'], 'length');
|
||||
* // => { '3': ['one', 'two'], '5': ['three'] }
|
||||
*/
|
||||
|
||||
@@ -7,10 +7,14 @@ define(['../internal/createAggregator'], function(createAggregator) {
|
||||
* iteratee function is bound to `thisArg` and invoked with three arguments;
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -19,8 +23,7 @@ define(['../internal/createAggregator'], function(createAggregator) {
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {Object} Returns the composed aggregate object.
|
||||
* @example
|
||||
@@ -33,10 +36,14 @@ define(['../internal/createAggregator'], function(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) {
|
||||
|
||||
@@ -5,37 +5,54 @@ define(['../internal/arrayMap', '../internal/baseCallback', '../internal/baseMap
|
||||
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
|
||||
* arguments; (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
* Many lodash methods are guarded to work as interatees for methods like
|
||||
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
||||
*
|
||||
* The guarded methods are:
|
||||
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`,
|
||||
* `dropRight`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, `slice`,
|
||||
* `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, `trimRight`,
|
||||
* `trunc`, `random`, `range`, `sample`, `uniq`, and `words`
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @alias collect
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* create a `_.property` or `_.matches` style callback respectively.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @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' },
|
||||
* { 'user': 'fred' }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.map(users, 'user');
|
||||
* // => ['barney', 'fred']
|
||||
*/
|
||||
|
||||
@@ -7,10 +7,14 @@ define(['../internal/arrayMax', '../internal/createExtremum'], function(arrayMax
|
||||
* 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"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -19,8 +23,6 @@ define(['../internal/arrayMax', '../internal/createExtremum'], function(arrayMax
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
|
||||
* If a property name or object is provided it is used to create a "_.property"
|
||||
* or "_.matches" style callback respectively.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {*} Returns the maximum value.
|
||||
* @example
|
||||
@@ -36,10 +38,12 @@ define(['../internal/arrayMax', '../internal/createExtremum'], function(arrayMax
|
||||
* { '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
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.max(users, 'age');
|
||||
* // => { 'user': 'fred', 'age': 40 };
|
||||
*/
|
||||
|
||||
@@ -7,10 +7,14 @@ define(['../internal/arrayMin', '../internal/createExtremum'], function(arrayMin
|
||||
* 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"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -19,8 +23,6 @@ define(['../internal/arrayMin', '../internal/createExtremum'], function(arrayMin
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
|
||||
* If a property name or object is provided it is used to create a "_.property"
|
||||
* or "_.matches" style callback respectively.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @returns {*} Returns the minimum value.
|
||||
* @example
|
||||
@@ -36,10 +38,12 @@ define(['../internal/arrayMin', '../internal/createExtremum'], function(arrayMin
|
||||
* { '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
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.min(users, 'age');
|
||||
* // => { 'user': 'barney', 'age': 36 };
|
||||
*/
|
||||
|
||||
@@ -6,10 +6,14 @@ define(['../internal/createAggregator'], function(createAggregator) {
|
||||
* contains elements `predicate` returns falsey for. The predicate is bound
|
||||
* to `thisArg` and invoked with three arguments; (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -18,16 +22,19 @@ define(['../internal/createAggregator'], function(createAggregator) {
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @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 = [
|
||||
@@ -36,12 +43,20 @@ define(['../internal/createAggregator'], function(createAggregator) {
|
||||
* { 'user': 'pebbles', 'age': 1, 'active': false }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.map(_.partition(users, { 'age': 1 }), 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);
|
||||
* // => [['pebbles'], ['barney', 'fred']]
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.map(_.partition(users, 'active'), function(array) { return _.pluck(array, 'user'); });
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.map(_.partition(users, 'active', false), mapper);
|
||||
* // => [['barney', 'pebbles'], ['fred']]
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.map(_.partition(users, 'active'), mapper);
|
||||
* // => [['fred'], ['barney', 'pebbles']]
|
||||
*/
|
||||
var partition = createAggregator(function(result, value, key) {
|
||||
|
||||
@@ -24,7 +24,7 @@ define(['../internal/baseProperty', './map'], function(baseProperty, map) {
|
||||
* // => [36, 40] (iteration order is not guaranteed)
|
||||
*/
|
||||
function pluck(collection, key) {
|
||||
return map(collection, baseProperty(key + ''));
|
||||
return map(collection, baseProperty(key));
|
||||
}
|
||||
|
||||
return pluck;
|
||||
|
||||
@@ -8,6 +8,12 @@ define(['../internal/arrayReduce', '../internal/baseCallback', '../internal/base
|
||||
* value. The `iteratee` is bound to `thisArg`and invoked with four arguments;
|
||||
* (accumulator, value, index|key, collection).
|
||||
*
|
||||
* Many lodash methods are guarded to work as interatees for methods like
|
||||
* `_.reduce`, `_.reduceRight`, and `_.transform`.
|
||||
*
|
||||
* The guarded methods are:
|
||||
* `assign`, `defaults`, `merge`, and `sortAllBy`
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @alias foldl, inject
|
||||
@@ -19,14 +25,16 @@ define(['../internal/arrayReduce', '../internal/baseCallback', '../internal/base
|
||||
* @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;
|
||||
|
||||
@@ -16,7 +16,10 @@ define(['../internal/arrayReduceRight', '../internal/baseCallback', '../internal
|
||||
* @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) {
|
||||
|
||||
@@ -4,10 +4,14 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base
|
||||
* The opposite of `_.filter`; this method returns the elements of `collection`
|
||||
* that `predicate` does **not** return truthy for.
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -16,13 +20,14 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @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 = [
|
||||
@@ -30,13 +35,17 @@ define(['../internal/arrayFilter', '../internal/baseCallback', '../internal/base
|
||||
* { 'user': 'fred', 'age': 40, 'active': true }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.pluck(_.reject(users, 'active'), 'user');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
|
||||
* // => ['barney']
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.pluck(_.reject(users, { 'age': 36 }), 'user');
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.pluck(_.reject(users, 'active', false), 'user');
|
||||
* // => ['fred']
|
||||
*
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.pluck(_.reject(users, 'active'), 'user');
|
||||
* // => ['barney']
|
||||
*/
|
||||
function reject(collection, predicate, thisArg) {
|
||||
var func = isArray(collection) ? arrayFilter : baseFilter;
|
||||
|
||||
@@ -11,12 +11,12 @@ define(['../internal/isLength', '../object/keys'], function(isLength, 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
|
||||
*/
|
||||
|
||||
@@ -6,10 +6,14 @@ define(['../internal/arraySome', '../internal/baseCallback', '../internal/baseSo
|
||||
* over the entire collection. The predicate is bound to `thisArg` and invoked
|
||||
* with three arguments; (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -19,8 +23,7 @@ define(['../internal/arraySome', '../internal/baseCallback', '../internal/baseSo
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
||||
* per iteration. If a property name or object is provided it is used to
|
||||
* create a "_.property" or "_.matches" style callback respectively.
|
||||
* per iteration.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @returns {boolean} Returns `true` if any element passes the predicate check,
|
||||
* else `false`.
|
||||
@@ -30,17 +33,21 @@ define(['../internal/arraySome', '../internal/baseCallback', '../internal/baseSo
|
||||
* // => true
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 36, 'active': false },
|
||||
* { 'user': 'fred', 'age': 40, 'active': true }
|
||||
* { 'user': 'barney', 'active': true },
|
||||
* { 'user': 'fred', 'active': false }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* _.some(users, 'active');
|
||||
* // using the `_.matches` callback shorthand
|
||||
* _.some(users, { user': 'barney', 'active': false });
|
||||
* // => false
|
||||
*
|
||||
* // using the `_.matchesProperty` callback shorthand
|
||||
* _.some(users, 'active', false);
|
||||
* // => true
|
||||
*
|
||||
* // using the "_.matches" callback shorthand
|
||||
* _.some(users, { 'age': 1 });
|
||||
* // => false
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.some(users, 'active');
|
||||
* // => true
|
||||
*/
|
||||
function some(collection, predicate, thisArg) {
|
||||
var func = isArray(collection) ? arraySome : baseSome;
|
||||
|
||||
@@ -7,10 +7,14 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseSor
|
||||
* The `iteratee` is bound to `thisArg` and invoked with three arguments;
|
||||
* (value, index|key, collection).
|
||||
*
|
||||
* If a property name is provided for `predicate` the created "_.property"
|
||||
* If a property name is provided for `predicate` the created `_.property`
|
||||
* style callback returns the property value of the given element.
|
||||
*
|
||||
* If an object is provided for `predicate` the created "_.matches" style
|
||||
* 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`.
|
||||
*
|
||||
@@ -20,15 +24,19 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseSor
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Array|Function|Object|string} [iteratee=_.identity] The function
|
||||
* invoked per iteration. If a property name or an object is provided it is
|
||||
* used to create a "_.property" or "_.matches" style callback respectively.
|
||||
* used to create a `_.property` or `_.matches` style callback respectively.
|
||||
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
||||
* @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 = [
|
||||
@@ -37,7 +45,7 @@ define(['../internal/baseCallback', '../internal/baseEach', '../internal/baseSor
|
||||
* { 'user': 'barney' }
|
||||
* ];
|
||||
*
|
||||
* // using the "_.property" callback shorthand
|
||||
* // using the `_.property` callback shorthand
|
||||
* _.pluck(_.sortBy(users, 'user'), 'user');
|
||||
* // => ['barney', 'fred', 'pebbles']
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,7 @@ define(['../internal/baseEach', '../internal/baseFlatten', '../internal/baseSort
|
||||
props = baseFlatten(args, false, false, 1),
|
||||
result = isLength(length) ? Array(length) : [];
|
||||
|
||||
baseEach(collection, function(value, key, collection) {
|
||||
baseEach(collection, function(value) {
|
||||
var length = props.length,
|
||||
criteria = Array(length);
|
||||
|
||||
|
||||
@@ -5,6 +5,11 @@ define(['../internal/baseMatches', './filter'], function(baseMatches, filter) {
|
||||
* source object, returning an array of all elements that have equivalent
|
||||
* property values.
|
||||
*
|
||||
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
|
||||
* numbers, `Object` objects, regexes, and strings. Objects are compared by
|
||||
* their own, not inherited, enumerable properties. For comparing a single
|
||||
* own or inherited property value see `_.matchesProperty`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
@@ -14,18 +19,15 @@ define(['../internal/baseMatches', './filter'], function(baseMatches, filter) {
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'barney', 'age': 36, 'status': 'busy', 'pets': ['hoppy'] },
|
||||
* { 'user': 'fred', 'age': 40, 'status': 'busy', 'pets': ['baby puss', 'dino'] }
|
||||
* { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
|
||||
* { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
|
||||
* ];
|
||||
*
|
||||
* _.pluck(_.where(users, { 'age': 36 }), 'user');
|
||||
* _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
|
||||
* // => ['barney']
|
||||
*
|
||||
* _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
|
||||
* // => ['fred']
|
||||
*
|
||||
* _.pluck(_.where(users, { 'status': 'busy' }), 'user');
|
||||
* // => ['barney', 'fred']
|
||||
*/
|
||||
function where(collection, source) {
|
||||
return filter(collection, baseMatches(source));
|
||||
|
||||
@@ -12,7 +12,9 @@ define(['../lang/isNative'], function(isNative) {
|
||||
* @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() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['./function/after', './function/ary', './function/backflow', './function/before', './function/bind', './function/bindAll', './function/bindKey', './function/compose', './function/curry', './function/curryRight', './function/debounce', './function/defer', './function/delay', './function/flow', './function/flowRight', './function/memoize', './function/negate', './function/once', './function/partial', './function/partialRight', './function/rearg', './function/throttle', './function/wrap'], function(after, ary, backflow, before, bind, bindAll, bindKey, compose, curry, curryRight, debounce, defer, delay, flow, flowRight, memoize, negate, once, partial, partialRight, rearg, throttle, wrap) {
|
||||
define(['./function/after', './function/ary', './function/backflow', './function/before', './function/bind', './function/bindAll', './function/bindKey', './function/compose', './function/curry', './function/curryRight', './function/debounce', './function/defer', './function/delay', './function/flow', './function/flowRight', './function/memoize', './function/negate', './function/once', './function/partial', './function/partialRight', './function/rearg', './function/spread', './function/throttle', './function/wrap'], function(after, ary, backflow, before, bind, bindAll, bindKey, compose, curry, curryRight, debounce, defer, delay, flow, flowRight, memoize, negate, once, partial, partialRight, rearg, spread, throttle, wrap) {
|
||||
return {
|
||||
'after': after,
|
||||
'ary': ary,
|
||||
@@ -21,6 +21,7 @@ define(['./function/after', './function/ary', './function/backflow', './function
|
||||
'partial': partial,
|
||||
'partialRight': partialRight,
|
||||
'rearg': rearg,
|
||||
'spread': spread,
|
||||
'throttle': throttle,
|
||||
'wrap': wrap
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['../lang/isFunction', '../internal/root'], function(isFunction, root) {
|
||||
define(['../internal/root'], function(root) {
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -30,8 +30,8 @@ define(['../lang/isFunction', '../internal/root'], function(isFunction, root) {
|
||||
* // => logs 'done saving!' after the two async saves have completed
|
||||
*/
|
||||
function after(n, func) {
|
||||
if (!isFunction(func)) {
|
||||
if (isFunction(n)) {
|
||||
if (typeof func != 'function') {
|
||||
if (typeof n == 'function') {
|
||||
var temp = n;
|
||||
n = func;
|
||||
func = temp;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['../lang/isFunction'], function(isFunction) {
|
||||
define([], function() {
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -21,8 +21,8 @@ define(['../lang/isFunction'], function(isFunction) {
|
||||
*/
|
||||
function before(n, func) {
|
||||
var result;
|
||||
if (!isFunction(func)) {
|
||||
if (isFunction(n)) {
|
||||
if (typeof func != 'function') {
|
||||
if (typeof n == 'function') {
|
||||
var temp = n;
|
||||
n = func;
|
||||
func = temp;
|
||||
|
||||
@@ -19,7 +19,9 @@ define(['../internal/baseBindAll', '../internal/baseFlatten', '../object/functio
|
||||
*
|
||||
* var view = {
|
||||
* 'label': 'docs',
|
||||
* 'onClick': function() { console.log('clicked ' + this.label); }
|
||||
* 'onClick': function() {
|
||||
* console.log('clicked ' + this.label);
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* _.bindAll(view);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['../lang/isFunction', '../lang/isObject', '../date/now'], function(isFunction, isObject, now) {
|
||||
define(['../lang/isObject', '../date/now'], function(isObject, now) {
|
||||
|
||||
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
||||
var undefined;
|
||||
@@ -83,7 +83,7 @@ define(['../lang/isFunction', '../lang/isObject', '../date/now'], function(isFun
|
||||
maxWait = false,
|
||||
trailing = true;
|
||||
|
||||
if (!isFunction(func)) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
wait = wait < 0 ? 0 : wait;
|
||||
|
||||
@@ -12,7 +12,9 @@ define(['../internal/baseDelay'], function(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 @@ define(['../internal/baseDelay'], function(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,4 +1,4 @@
|
||||
define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, isFunction) {
|
||||
define(['../internal/arrayEvery', '../internal/baseIsFunction'], function(arrayEvery, baseIsFunction) {
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -32,9 +32,9 @@ define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, is
|
||||
length = funcs.length;
|
||||
|
||||
if (!length) {
|
||||
return function() {};
|
||||
return function() { return arguments[0]; };
|
||||
}
|
||||
if (!arrayEvery(funcs, isFunction)) {
|
||||
if (!arrayEvery(funcs, baseIsFunction)) {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, isFunction) {
|
||||
define(['../internal/arrayEvery', '../internal/baseIsFunction'], function(arrayEvery, baseIsFunction) {
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -32,9 +32,9 @@ define(['../internal/arrayEvery', '../lang/isFunction'], function(arrayEvery, is
|
||||
fromIndex = funcs.length - 1;
|
||||
|
||||
if (fromIndex < 0) {
|
||||
return function() {};
|
||||
return function() { return arguments[0]; };
|
||||
}
|
||||
if (!arrayEvery(funcs, isFunction)) {
|
||||
if (!arrayEvery(funcs, baseIsFunction)) {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['../internal/MapCache', '../lang/isFunction'], function(MapCache, isFunction) {
|
||||
define(['../internal/MapCache'], function(MapCache) {
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -57,7 +57,7 @@ define(['../internal/MapCache', '../lang/isFunction'], function(MapCache, isFunc
|
||||
* // => { 'user': 'barney' }
|
||||
*/
|
||||
function memoize(func, resolver) {
|
||||
if (!isFunction(func) || (resolver && !isFunction(resolver))) {
|
||||
if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
var memoized = function() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['../lang/isFunction'], function(isFunction) {
|
||||
define([], function() {
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -23,7 +23,7 @@ define(['../lang/isFunction'], function(isFunction) {
|
||||
* // => [1, 3, 5]
|
||||
*/
|
||||
function negate(predicate) {
|
||||
if (!isFunction(predicate)) {
|
||||
if (typeof predicate != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return function() {
|
||||
|
||||
@@ -7,7 +7,6 @@ define(['./before'], function(before) {
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @type Function
|
||||
* @category Function
|
||||
* @param {Function} func The function to restrict.
|
||||
* @returns {Function} Returns the new restricted function.
|
||||
|
||||
@@ -26,7 +26,9 @@ define(['../internal/baseFlatten', '../internal/createWrapper'], function(baseFl
|
||||
* // => ['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) {
|
||||
|
||||
46
function/spread.js
Normal file
46
function/spread.js
Normal file
@@ -0,0 +1,46 @@
|
||||
define([], function() {
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
/**
|
||||
* Creates a function that invokes `func` with the `this` binding of the
|
||||
* created function and the array of arguments provided to the created
|
||||
* function much like [Function#apply](http://es5.github.io/#x15.3.4.3).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Function
|
||||
* @param {Function} func The function to spread arguments over.
|
||||
* @returns {*} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var spread = _.spread(function(who, what) {
|
||||
* return who + ' says ' + what;
|
||||
* });
|
||||
*
|
||||
* spread(['Fred', 'hello']);
|
||||
* // => 'Fred says hello'
|
||||
*
|
||||
* // with a Promise
|
||||
* var numbers = Promise.all([
|
||||
* Promise.resolve(40),
|
||||
* Promise.resolve(36)
|
||||
* ]);
|
||||
*
|
||||
* numbers.then(_.spread(function(x, y) {
|
||||
* return x + y;
|
||||
* }));
|
||||
* // => a Promise of 76
|
||||
*/
|
||||
function spread(func) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return function(array) {
|
||||
return func.apply(this, array);
|
||||
};
|
||||
}
|
||||
|
||||
return spread;
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['./debounce', '../lang/isFunction', '../lang/isObject'], function(debounce, isFunction, isObject) {
|
||||
define(['./debounce', '../lang/isObject'], function(debounce, isObject) {
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
@@ -42,8 +42,9 @@ define(['./debounce', '../lang/isFunction', '../lang/isObject'], function(deboun
|
||||
* 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);
|
||||
@@ -52,7 +53,7 @@ define(['./debounce', '../lang/isFunction', '../lang/isObject'], function(deboun
|
||||
var leading = true,
|
||||
trailing = true;
|
||||
|
||||
if (!isFunction(func)) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
if (options === false) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define([], function() {
|
||||
define(['./baseCreate', './baseLodash'], function(baseCreate, baseLodash) {
|
||||
|
||||
/** Used as references for `-Infinity` and `Infinity`. */
|
||||
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
||||
@@ -10,15 +10,18 @@ define([], function() {
|
||||
* @param {*} value The value to wrap.
|
||||
*/
|
||||
function LazyWrapper(value) {
|
||||
this.actions = null;
|
||||
this.dir = 1;
|
||||
this.dropCount = 0;
|
||||
this.filtered = false;
|
||||
this.iteratees = null;
|
||||
this.takeCount = POSITIVE_INFINITY;
|
||||
this.views = null;
|
||||
this.wrapped = value;
|
||||
this.__wrapped__ = value;
|
||||
this.__actions__ = null;
|
||||
this.__dir__ = 1;
|
||||
this.__dropCount__ = 0;
|
||||
this.__filtered__ = false;
|
||||
this.__iteratees__ = null;
|
||||
this.__takeCount__ = POSITIVE_INFINITY;
|
||||
this.__views__ = null;
|
||||
}
|
||||
|
||||
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||
LazyWrapper.prototype.constructor = LazyWrapper;
|
||||
|
||||
return LazyWrapper;
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define([], function() {
|
||||
define(['./baseCreate', './baseLodash'], function(baseCreate, baseLodash) {
|
||||
|
||||
/**
|
||||
* The base constructor for creating `lodash` wrapper objects.
|
||||
@@ -9,10 +9,13 @@ define([], function() {
|
||||
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
|
||||
*/
|
||||
function LodashWrapper(value, chainAll, actions) {
|
||||
this.__wrapped__ = value;
|
||||
this.__actions__ = actions || [];
|
||||
this.__chain__ = !!chainAll;
|
||||
this.__wrapped__ = value;
|
||||
}
|
||||
|
||||
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
|
||||
LodashWrapper.prototype.constructor = LodashWrapper;
|
||||
|
||||
return LodashWrapper;
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ define(['./baseCopy', '../object/keys'], function(baseCopy, keys) {
|
||||
return baseCopy(source, object, props);
|
||||
}
|
||||
var index = -1,
|
||||
length = props.length
|
||||
length = props.length;
|
||||
|
||||
while (++index < length) {
|
||||
var key = props[index],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['./baseMatches', './baseProperty', './bindCallback', '../utility/identity', './isBindable'], function(baseMatches, baseProperty, bindCallback, identity, isBindable) {
|
||||
define(['./baseMatches', './baseMatchesProperty', './baseProperty', './bindCallback', '../utility/identity', './isBindable'], function(baseMatches, baseMatchesProperty, baseProperty, bindCallback, identity, isBindable) {
|
||||
|
||||
/**
|
||||
* The base implementation of `_.callback` which supports specifying the
|
||||
@@ -20,10 +20,12 @@ define(['./baseMatches', './baseProperty', './bindCallback', '../utility/identit
|
||||
if (func == null) {
|
||||
return identity;
|
||||
}
|
||||
// Handle "_.property" and "_.matches" style callback shorthands.
|
||||
return type == 'object'
|
||||
? baseMatches(func)
|
||||
: baseProperty(func + '');
|
||||
if (type == 'object') {
|
||||
return baseMatches(func);
|
||||
}
|
||||
return typeof thisArg == 'undefined'
|
||||
? baseProperty(func + '')
|
||||
: baseMatchesProperty(func + '', thisArg);
|
||||
}
|
||||
|
||||
return baseCallback;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['./baseSlice', '../lang/isFunction'], function(baseSlice, isFunction) {
|
||||
define(['./baseSlice'], function(baseSlice) {
|
||||
|
||||
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
||||
var undefined;
|
||||
@@ -17,7 +17,7 @@ define(['./baseSlice', '../lang/isFunction'], function(baseSlice, isFunction) {
|
||||
* @returns {number} Returns the timer id.
|
||||
*/
|
||||
function baseDelay(func, wait, args, fromIndex) {
|
||||
if (!isFunction(func)) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait);
|
||||
|
||||
34
internal/baseFill.js
Normal file
34
internal/baseFill.js
Normal file
@@ -0,0 +1,34 @@
|
||||
define([], function() {
|
||||
|
||||
/**
|
||||
* The base implementation of `_.fill` without an iteratee call guard.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to fill.
|
||||
* @param {*} value The value to fill `array` with.
|
||||
* @param {number} [start=0] The start position.
|
||||
* @param {number} [end=array.length] The end position.
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function baseFill(array, value, start, end) {
|
||||
var length = array.length;
|
||||
|
||||
start = start == null ? 0 : (+start || 0);
|
||||
if (start < 0) {
|
||||
start = -start > length ? 0 : (length + start);
|
||||
}
|
||||
end = (typeof end == 'undefined' || end > length) ? length : (+end || 0);
|
||||
if (end < 0) {
|
||||
end += length;
|
||||
}
|
||||
length = start > end ? 0 : end >>> 0;
|
||||
start >>>= 0;
|
||||
|
||||
while (start < length) {
|
||||
array[start++] = value;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
return baseFill;
|
||||
});
|
||||
18
internal/baseIsFunction.js
Normal file
18
internal/baseIsFunction.js
Normal file
@@ -0,0 +1,18 @@
|
||||
define([], function() {
|
||||
|
||||
/**
|
||||
* The base implementation of `_.isFunction` without support for environments
|
||||
* with incorrect `typeof` results.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
||||
*/
|
||||
function baseIsFunction(value) {
|
||||
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
|
||||
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
|
||||
return typeof value == 'function' || false;
|
||||
}
|
||||
|
||||
return baseIsFunction;
|
||||
});
|
||||
@@ -14,7 +14,7 @@ define(['./baseIsEqual'], function(baseIsEqual) {
|
||||
* shorthands or `this` binding.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} source The object to inspect.
|
||||
* @param {Object} object The object to inspect.
|
||||
* @param {Array} props The source property names to match.
|
||||
* @param {Array} values The source values to match.
|
||||
* @param {Array} strictCompareFlags Strict comparison flags for source values.
|
||||
|
||||
13
internal/baseLodash.js
Normal file
13
internal/baseLodash.js
Normal file
@@ -0,0 +1,13 @@
|
||||
define([], function() {
|
||||
|
||||
/**
|
||||
* The function whose prototype all chaining wrappers inherit from.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function baseLodash() {
|
||||
// No operation performed.
|
||||
}
|
||||
|
||||
return baseLodash;
|
||||
});
|
||||
@@ -7,8 +7,7 @@ define(['./baseIsMatch', './isStrictComparable', '../object/keys'], function(bas
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.matches` which supports specifying whether
|
||||
* `source` should be cloned.
|
||||
* The base implementation of `_.matches` which does not clone `source`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} source The object of property values to match.
|
||||
@@ -24,7 +23,7 @@ define(['./baseIsMatch', './isStrictComparable', '../object/keys'], function(bas
|
||||
|
||||
if (isStrictComparable(value)) {
|
||||
return function(object) {
|
||||
return object != null && value === object[key] && hasOwnProperty.call(object, key);
|
||||
return object != null && object[key] === value && hasOwnProperty.call(object, key);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
24
internal/baseMatchesProperty.js
Normal file
24
internal/baseMatchesProperty.js
Normal file
@@ -0,0 +1,24 @@
|
||||
define(['./baseIsEqual', './isStrictComparable'], function(baseIsEqual, isStrictComparable) {
|
||||
|
||||
/**
|
||||
* The base implementation of `_.matchesProperty` which does not coerce `key`
|
||||
* to a string.
|
||||
*
|
||||
* @private
|
||||
* @param {string} key The key of the property to get.
|
||||
* @param {*} value The value to compare.
|
||||
* @returns {Function} Returns the new function.
|
||||
*/
|
||||
function baseMatchesProperty(key, value) {
|
||||
if (isStrictComparable(value)) {
|
||||
return function(object) {
|
||||
return object != null && object[key] === value;
|
||||
};
|
||||
}
|
||||
return function(object) {
|
||||
return object != null && baseIsEqual(value, object[key], null, true);
|
||||
};
|
||||
}
|
||||
|
||||
return baseMatchesProperty;
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './isLength', './isObjectLike', '../lang/isTypedArray'], function(arrayEach, baseForOwn, baseMergeDeep, isArray, isLength, isObjectLike, isTypedArray) {
|
||||
define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './isLength', '../lang/isObject', './isObjectLike', '../lang/isTypedArray'], function(arrayEach, baseForOwn, baseMergeDeep, isArray, isLength, isObject, isObjectLike, isTypedArray) {
|
||||
|
||||
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
||||
var undefined;
|
||||
@@ -16,8 +16,10 @@ define(['./arrayEach', './baseForOwn', './baseMergeDeep', '../lang/isArray', './
|
||||
* @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 = []);
|
||||
|
||||
@@ -18,7 +18,7 @@ define([], function() {
|
||||
eachFunc(collection, function(value, index, collection) {
|
||||
accumulator = initFromCollection
|
||||
? (initFromCollection = false, value)
|
||||
: iteratee(accumulator, value, index, collection)
|
||||
: iteratee(accumulator, value, index, collection);
|
||||
});
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ define(['./baseCallback', './baseEach', '../lang/isArray'], function(baseCallbac
|
||||
/**
|
||||
* Creates a function that aggregates a collection, creating an accumulator
|
||||
* object composed from the results of running each element in the collection
|
||||
* through an iteratee. The `setter` sets the keys and values of the accumulator
|
||||
* object. If `initializer` is provided initializes the accumulator object.
|
||||
* through an iteratee.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} setter The function to set keys and values of the accumulator object.
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
define(['./baseSetData', './createBindWrapper', './createHybridWrapper', './createPartialWrapper', './getData', '../lang/isFunction', './mergeData', './setData'], function(baseSetData, createBindWrapper, createHybridWrapper, createPartialWrapper, getData, isFunction, mergeData, setData) {
|
||||
define(['./baseSetData', './createBindWrapper', './createHybridWrapper', './createPartialWrapper', './getData', './mergeData', './setData'], function(baseSetData, createBindWrapper, createHybridWrapper, createPartialWrapper, getData, mergeData, setData) {
|
||||
|
||||
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
||||
var undefined;
|
||||
|
||||
/** Used to compose bitmasks for wrapper metadata. */
|
||||
var BIND_FLAG = 1,
|
||||
@@ -39,7 +42,7 @@ define(['./baseSetData', './createBindWrapper', './createHybridWrapper', './crea
|
||||
*/
|
||||
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
|
||||
var isBindKey = bitmask & BIND_KEY_FLAG;
|
||||
if (!isBindKey && !isFunction(func)) {
|
||||
if (!isBindKey && typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
var length = partials ? partials.length : 0;
|
||||
@@ -69,9 +72,9 @@ define(['./baseSetData', './createBindWrapper', './createHybridWrapper', './crea
|
||||
if (bitmask == BIND_FLAG) {
|
||||
var result = createBindWrapper(newData[0], newData[2]);
|
||||
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
|
||||
result = createPartialWrapper.apply(null, newData);
|
||||
result = createPartialWrapper.apply(undefined, newData);
|
||||
} else {
|
||||
result = createHybridWrapper.apply(null, newData);
|
||||
result = createHybridWrapper.apply(undefined, newData);
|
||||
}
|
||||
var setter = data ? baseSetData : setData;
|
||||
return setter(result, newData);
|
||||
|
||||
@@ -20,7 +20,8 @@ define(['./isIndex', './isLength', '../lang/isObject'], function(isIndex, isLeng
|
||||
} else {
|
||||
prereq = type == 'string' && index in object;
|
||||
}
|
||||
return prereq && object[index] === value;
|
||||
var other = object[index];
|
||||
return prereq && (value === value ? value === other : other !== other);
|
||||
}
|
||||
|
||||
return isIterateeCall;
|
||||
|
||||
@@ -9,18 +9,18 @@ define(['./LazyWrapper', './arrayCopy'], function(LazyWrapper, arrayCopy) {
|
||||
* @returns {Object} Returns the cloned `LazyWrapper` object.
|
||||
*/
|
||||
function lazyClone() {
|
||||
var actions = this.actions,
|
||||
iteratees = this.iteratees,
|
||||
views = this.views,
|
||||
result = new LazyWrapper(this.wrapped);
|
||||
var actions = this.__actions__,
|
||||
iteratees = this.__iteratees__,
|
||||
views = this.__views__,
|
||||
result = new LazyWrapper(this.__wrapped__);
|
||||
|
||||
result.actions = actions ? arrayCopy(actions) : null;
|
||||
result.dir = this.dir;
|
||||
result.dropCount = this.dropCount;
|
||||
result.filtered = this.filtered;
|
||||
result.iteratees = iteratees ? arrayCopy(iteratees) : null;
|
||||
result.takeCount = this.takeCount;
|
||||
result.views = views ? arrayCopy(views) : null;
|
||||
result.__actions__ = actions ? arrayCopy(actions) : null;
|
||||
result.__dir__ = this.__dir__;
|
||||
result.__dropCount__ = this.__dropCount__;
|
||||
result.__filtered__ = this.__filtered__;
|
||||
result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null;
|
||||
result.__takeCount__ = this.__takeCount__;
|
||||
result.__views__ = views ? arrayCopy(views) : null;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ define(['./LazyWrapper'], function(LazyWrapper) {
|
||||
* @returns {Object} Returns the new reversed `LazyWrapper` object.
|
||||
*/
|
||||
function lazyReverse() {
|
||||
if (this.filtered) {
|
||||
if (this.__filtered__) {
|
||||
var result = new LazyWrapper(this);
|
||||
result.dir = -1;
|
||||
result.filtered = true;
|
||||
result.__dir__ = -1;
|
||||
result.__filtered__ = true;
|
||||
} else {
|
||||
result = this.clone();
|
||||
result.dir *= -1;
|
||||
result.__dir__ *= -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user