mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Allow _.omit and _.pick to work as a callback for _.map when combined with _.partialRight.
This commit is contained in:
84
dist/lodash.compat.js
vendored
84
dist/lodash.compat.js
vendored
@@ -2377,8 +2377,7 @@
|
||||
callback = isShallow;
|
||||
isShallow = false;
|
||||
|
||||
// allows working with functions like `_.map` without using
|
||||
// their `index` argument as a callback
|
||||
// enables use as a callback for functions like `_.map`
|
||||
if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === array) {
|
||||
callback = null;
|
||||
}
|
||||
@@ -3059,8 +3058,7 @@
|
||||
callback = isSorted;
|
||||
isSorted = false;
|
||||
|
||||
// allows working with functions like `_.map` without using
|
||||
// their `index` argument as a callback
|
||||
// enables use as a callback for functions like `_.map`
|
||||
if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === array) {
|
||||
callback = null;
|
||||
}
|
||||
@@ -3342,8 +3340,7 @@
|
||||
length = props.length,
|
||||
type = typeof guard;
|
||||
|
||||
// allows working with functions like `_.map` without using
|
||||
// their `index` arguments
|
||||
// enables use as a callback for functions like `_.map`
|
||||
if ((type == 'number' || type == 'string') && args[2] && args[2][guard] === collection) {
|
||||
length = 1;
|
||||
}
|
||||
@@ -3980,8 +3977,7 @@
|
||||
result = computed,
|
||||
type = typeof callback;
|
||||
|
||||
// allows working with functions like `_.map` without using
|
||||
// their `index` argument as a callback
|
||||
// enables use as a callback for functions like `_.map`
|
||||
if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) {
|
||||
callback = null;
|
||||
}
|
||||
@@ -4056,8 +4052,7 @@
|
||||
result = computed,
|
||||
type = typeof callback;
|
||||
|
||||
// allows working with functions like `_.map` without using
|
||||
// their `index` argument as a callback
|
||||
// enables use as a callback for functions like `_.map`
|
||||
if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === collection) {
|
||||
callback = null;
|
||||
}
|
||||
@@ -4247,8 +4242,7 @@
|
||||
* @category Collections
|
||||
* @param {Array|Object|string} collection The collection to sample.
|
||||
* @param {number} [n] The number of elements to sample.
|
||||
* @param- {Object} [guard] Allows working with functions like `_.map`
|
||||
* without using their `index` arguments as `n`.
|
||||
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
||||
* @returns {*} Returns the random sample(s) of `collection`.
|
||||
* @example
|
||||
*
|
||||
@@ -5209,8 +5203,7 @@
|
||||
* return typeof a == 'undefined' ? b : a;
|
||||
* });
|
||||
*
|
||||
* var object = { 'name': 'barney' };
|
||||
* defaults(object, { 'name': 'fred', 'employer': 'slate' });
|
||||
* defaults({ 'name': 'barney' }, { 'name': 'fred', 'employer': 'slate' });
|
||||
* // => { 'name': 'barney', 'employer': 'slate' }
|
||||
*/
|
||||
function assign(object, source, guard) {
|
||||
@@ -5219,8 +5212,7 @@
|
||||
argsLength = args.length,
|
||||
type = typeof guard;
|
||||
|
||||
// allows working with functions like `_.reduce` without using their
|
||||
// `key` and `object` arguments as sources
|
||||
// enables use as a callback for functions like `_.reduce`
|
||||
if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) {
|
||||
argsLength = 2;
|
||||
}
|
||||
@@ -5301,8 +5293,7 @@
|
||||
callback = isDeep;
|
||||
isDeep = false;
|
||||
|
||||
// allows working with functions like `_.map` without using
|
||||
// their `index` argument as a callback
|
||||
// enables use as a callback for functions like `_.map`
|
||||
if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === value) {
|
||||
callback = null;
|
||||
}
|
||||
@@ -5402,13 +5393,11 @@
|
||||
* @category Objects
|
||||
* @param {Object} object The destination object.
|
||||
* @param {...Object} [source] The source objects.
|
||||
* @param- {Object} [guard] Allows working with functions like `_.reduce`
|
||||
* without using their `key` and `object` arguments as sources.
|
||||
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
|
||||
* @returns {Object} Returns the destination object.
|
||||
* @example
|
||||
*
|
||||
* var object = { 'name': 'barney' };
|
||||
* _.defaults(object, { 'name': 'fred', 'employer': 'slate' });
|
||||
* _.defaults({ 'name': 'barney' }, { 'name': 'fred', 'employer': 'slate' });
|
||||
* // => { 'name': 'barney', 'employer': 'slate' }
|
||||
*/
|
||||
function defaults(object, source, guard) {
|
||||
@@ -5417,8 +5406,7 @@
|
||||
argsLength = args.length,
|
||||
type = typeof guard;
|
||||
|
||||
// allows working with functions like `_.reduce` without using their
|
||||
// `key` and `object` arguments as sources
|
||||
// enables use as a callback for functions like `_.reduce`
|
||||
if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) {
|
||||
argsLength = 2;
|
||||
}
|
||||
@@ -6320,8 +6308,7 @@
|
||||
length = args.length,
|
||||
type = typeof guard;
|
||||
|
||||
// allows working with functions like `_.reduce` without using their
|
||||
// `key` and `object` arguments as sources
|
||||
// enables use as a callback for functions like `_.reduce`
|
||||
if ((type == 'number' || type == 'string') && args[3] && args[3][guard] === source) {
|
||||
length = 2;
|
||||
}
|
||||
@@ -6356,8 +6343,9 @@
|
||||
* @memberOf _
|
||||
* @category Objects
|
||||
* @param {Object} object The source object.
|
||||
* @param {Function|...string|string[]} [callback] The properties to omit or the
|
||||
* function called per iteration.
|
||||
* @param {Function|...string|string[]} [callback] The function called per
|
||||
* iteration or property names to omit, specified as individual property
|
||||
* names or arrays of property names.
|
||||
* @param {*} [thisArg] The `this` binding of `callback`.
|
||||
* @returns {Object} Returns an object without the omitted properties.
|
||||
* @example
|
||||
@@ -6371,16 +6359,31 @@
|
||||
* // => { 'name': 'fred' }
|
||||
*/
|
||||
function omit(object, callback, thisArg) {
|
||||
var result = {};
|
||||
if (typeof callback != 'function') {
|
||||
var result = {},
|
||||
type = typeof callback;
|
||||
|
||||
if (type != 'function') {
|
||||
// enables use as a callback for functions like `_.map`
|
||||
// when combined with `_.partialRight`
|
||||
var args = arguments;
|
||||
if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === object) {
|
||||
args = slice(args);
|
||||
splice.call(args, 1, 2);
|
||||
}
|
||||
var omitProps = baseFlatten(args, true, false, 1),
|
||||
length = omitProps.length;
|
||||
|
||||
while (length--) {
|
||||
omitProps[length] = String(omitProps[length]);
|
||||
}
|
||||
var props = [];
|
||||
baseForIn(object, function(value, key) {
|
||||
props.push(key);
|
||||
});
|
||||
props = baseDifference(props, baseFlatten(arguments, true, false, 1));
|
||||
|
||||
var index = -1,
|
||||
length = props.length;
|
||||
var index = -1;
|
||||
props = baseDifference(props, omitProps);
|
||||
length = props.length;
|
||||
|
||||
while (++index < length) {
|
||||
var key = props[index];
|
||||
@@ -6452,10 +6455,19 @@
|
||||
* // => { 'name': 'fred' }
|
||||
*/
|
||||
function pick(object, callback, thisArg) {
|
||||
var result = {};
|
||||
if (typeof callback != 'function') {
|
||||
var result = {},
|
||||
type = typeof callback;
|
||||
|
||||
if (type != 'function') {
|
||||
// enables use as a callback for functions like `_.map`
|
||||
// when combined with `_.partialRight`
|
||||
var args = arguments;
|
||||
if ((type == 'number' || type == 'string') && thisArg && thisArg[callback] === object) {
|
||||
args = slice(args);
|
||||
splice.call(args, 1, 2);
|
||||
}
|
||||
var index = -1,
|
||||
props = baseFlatten(arguments, true, false, 1),
|
||||
props = baseFlatten(args, true, false, 1),
|
||||
length = isObject(object) ? props.length : 0;
|
||||
|
||||
while (++index < length) {
|
||||
|
||||
Reference in New Issue
Block a user