mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Bump to v3.7.0.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import baseCallback from '../internal/baseCallback';
|
||||
import isIterateeCall from '../internal/isIterateeCall';
|
||||
import isObjectLike from '../internal/isObjectLike';
|
||||
import matches from './matches';
|
||||
|
||||
/**
|
||||
* Creates a function that invokes `func` with the `this` binding of `thisArg`
|
||||
@@ -45,9 +43,7 @@ function callback(func, thisArg, guard) {
|
||||
if (guard && isIterateeCall(func, thisArg, guard)) {
|
||||
thisArg = null;
|
||||
}
|
||||
return isObjectLike(func)
|
||||
? matches(func)
|
||||
: baseCallback(func, thisArg);
|
||||
return baseCallback(func, thisArg);
|
||||
}
|
||||
|
||||
export default callback;
|
||||
|
||||
@@ -2,7 +2,7 @@ import baseClone from '../internal/baseClone';
|
||||
import baseMatchesProperty from '../internal/baseMatchesProperty';
|
||||
|
||||
/**
|
||||
* Creates a function which compares the property value of `key` on a given
|
||||
* Creates a function which compares the property value of `path` on a given
|
||||
* object to `value`.
|
||||
*
|
||||
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
|
||||
@@ -12,7 +12,7 @@ import baseMatchesProperty from '../internal/baseMatchesProperty';
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utility
|
||||
* @param {string} key The key of the property to get.
|
||||
* @param {Array|string} path The path of the property to get.
|
||||
* @param {*} value The value to compare.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
@@ -25,8 +25,8 @@ import baseMatchesProperty from '../internal/baseMatchesProperty';
|
||||
* _.find(users, _.matchesProperty('user', 'fred'));
|
||||
* // => { 'user': 'fred' }
|
||||
*/
|
||||
function matchesProperty(key, value) {
|
||||
return baseMatchesProperty(key + '', baseClone(value, true));
|
||||
function matchesProperty(path, value) {
|
||||
return baseMatchesProperty(path, baseClone(value, true));
|
||||
}
|
||||
|
||||
export default matchesProperty;
|
||||
|
||||
31
utility/method.js
Normal file
31
utility/method.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import invokePath from '../internal/invokePath';
|
||||
import restParam from '../function/restParam';
|
||||
|
||||
/**
|
||||
* Creates a function which invokes the method at `path` on a given object.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utility
|
||||
* @param {Array|string} path The path of the method to invoke.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var objects = [
|
||||
* { 'a': { 'b': { 'c': _.constant(2) } } },
|
||||
* { 'a': { 'b': { 'c': _.constant(1) } } }
|
||||
* ];
|
||||
*
|
||||
* _.map(objects, _.method('a.b.c'));
|
||||
* // => [2, 1]
|
||||
*
|
||||
* _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
|
||||
* // => [1, 2]
|
||||
*/
|
||||
var method = restParam(function(path, args) {
|
||||
return function(object) {
|
||||
return invokePath(object, path, args);
|
||||
}
|
||||
});
|
||||
|
||||
export default method;
|
||||
30
utility/methodOf.js
Normal file
30
utility/methodOf.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import invokePath from '../internal/invokePath';
|
||||
import restParam from '../function/restParam';
|
||||
|
||||
/**
|
||||
* The opposite of `_.method`; this method creates a function which invokes
|
||||
* the method at a given path on `object`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utility
|
||||
* @param {Object} object The object to query.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var array = _.times(3, _.constant),
|
||||
* object = { 'a': array, 'b': array, 'c': array };
|
||||
*
|
||||
* _.map(['a[2]', 'c[0]'], _.methodOf(object));
|
||||
* // => [2, 0]
|
||||
*
|
||||
* _.map([['a', '2'], ['c', '0']], _.methodOf(object));
|
||||
* // => [2, 0]
|
||||
*/
|
||||
var methodOf = restParam(function(object, args) {
|
||||
return function(path) {
|
||||
return invokePath(object, path, args);
|
||||
};
|
||||
});
|
||||
|
||||
export default methodOf;
|
||||
@@ -15,13 +15,13 @@ var push = arrayProto.push;
|
||||
* destination object. If `object` is a function then methods are added to
|
||||
* its prototype as well.
|
||||
*
|
||||
* **Note:** Use `_.runInContext` to create a pristine `lodash` function
|
||||
* for mixins to avoid conflicts caused by modifying the original.
|
||||
* **Note:** Use `_.runInContext` to create a pristine `lodash` function to
|
||||
* avoid conflicts caused by modifying the original.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utility
|
||||
* @param {Function|Object} [object=this] object The destination object.
|
||||
* @param {Function|Object} [object=lodash] The destination object.
|
||||
* @param {Object} source The object of functions to add.
|
||||
* @param {Object} [options] The options object.
|
||||
* @param {boolean} [options.chain=true] Specify whether the functions added
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
import baseProperty from '../internal/baseProperty';
|
||||
import basePropertyDeep from '../internal/basePropertyDeep';
|
||||
import isKey from '../internal/isKey';
|
||||
|
||||
/**
|
||||
* Creates a function which returns the property value of `key` on a given object.
|
||||
* Creates a function which returns the property value at `path` on a
|
||||
* given object.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utility
|
||||
* @param {string} key The key of the property to get.
|
||||
* @param {Array|string} path The path of the property to get.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var users = [
|
||||
* { 'user': 'fred' },
|
||||
* { 'user': 'barney' }
|
||||
* var objects = [
|
||||
* { 'a': { 'b': { 'c': 2 } } },
|
||||
* { 'a': { 'b': { 'c': 1 } } }
|
||||
* ];
|
||||
*
|
||||
* var getName = _.property('user');
|
||||
* _.map(objects, _.property('a.b.c'));
|
||||
* // => [2, 1]
|
||||
*
|
||||
* _.map(users, getName);
|
||||
* // => ['fred', 'barney']
|
||||
*
|
||||
* _.pluck(_.sortBy(users, getName), 'user');
|
||||
* // => ['barney', 'fred']
|
||||
* _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
|
||||
* // => [1, 2]
|
||||
*/
|
||||
function property(key) {
|
||||
return baseProperty(key + '');
|
||||
function property(path) {
|
||||
return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
|
||||
}
|
||||
|
||||
export default property;
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
import baseGet from '../internal/baseGet';
|
||||
import toPath from '../internal/toPath';
|
||||
|
||||
/**
|
||||
* The opposite of `_.property`; this method creates a function which returns
|
||||
* the property value of a given key on `object`.
|
||||
* the property value at a given path on `object`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utility
|
||||
* @param {Object} object The object to inspect.
|
||||
* @param {Object} object The object to query.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var object = { 'a': 3, 'b': 1, 'c': 2 };
|
||||
* var array = [0, 1, 2],
|
||||
* object = { 'a': array, 'b': array, 'c': array };
|
||||
*
|
||||
* _.map(['a', 'c'], _.propertyOf(object));
|
||||
* // => [3, 2]
|
||||
* _.map(['a[2]', 'c[0]'], _.propertyOf(object));
|
||||
* // => [2, 0]
|
||||
*
|
||||
* _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
|
||||
* // => ['b', 'c', 'a']
|
||||
* _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
|
||||
* // => [2, 0]
|
||||
*/
|
||||
function propertyOf(object) {
|
||||
return function(key) {
|
||||
return object == null ? undefined : object[key];
|
||||
return function(path) {
|
||||
return baseGet(object, toPath(path), path + '');
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ var nativeMax = Math.max;
|
||||
/**
|
||||
* Creates an array of numbers (positive and/or negative) progressing from
|
||||
* `start` up to, but not including, `end`. If `end` is not specified it is
|
||||
* set to `start` with `start` then set to `0`. If `start` is less than `end`
|
||||
* set to `start` with `start` then set to `0`. If `end` is less than `start`
|
||||
* a zero-length range is created unless a negative `step` is specified.
|
||||
*
|
||||
* @static
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import bindCallback from '../internal/bindCallback';
|
||||
import root from '../internal/root';
|
||||
|
||||
/** Native method references. */
|
||||
var floor = Math.floor;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeIsFinite = root.isFinite,
|
||||
nativeMin = Math.min;
|
||||
@@ -28,7 +31,7 @@ var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1;
|
||||
* _.times(3, function(n) {
|
||||
* mage.castSpell(n);
|
||||
* });
|
||||
* // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2` respectively
|
||||
* // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
|
||||
*
|
||||
* _.times(3, function(n) {
|
||||
* this.cast(n);
|
||||
@@ -36,7 +39,7 @@ var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1;
|
||||
* // => also invokes `mage.castSpell(n)` three times
|
||||
*/
|
||||
function times(n, iteratee, thisArg) {
|
||||
n = +n;
|
||||
n = floor(n);
|
||||
|
||||
// Exit early to avoid a JSC JIT bug in Safari 8
|
||||
// where `Array(0)` is treated as `Array(1)`.
|
||||
|
||||
Reference in New Issue
Block a user