mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Restore createAssigner (fixes compilation of merge and mergeWith) (#4101)
This commit is contained in:
committed by
John-David Dalton
parent
508d46a7a4
commit
8eccdd098a
36
.internal/createAssigner.js
Normal file
36
.internal/createAssigner.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import isIterateeCall from './isIterateeCall.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function like `assign`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Function} assigner The function to assign values.
|
||||||
|
* @returns {Function} Returns the new assigner function.
|
||||||
|
*/
|
||||||
|
function createAssigner(assigner) {
|
||||||
|
return (object, ...sources) => {
|
||||||
|
let index = -1;
|
||||||
|
let length = sources.length;
|
||||||
|
let customizer = length > 1 ? sources[length - 1] : undefined;
|
||||||
|
const guard = length > 2 ? sources[2] : undefined;
|
||||||
|
|
||||||
|
customizer = (assigner.length > 3 && typeof customizer == 'function')
|
||||||
|
? (length--, customizer)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
if (guard && isIterateeCall(sources[0], sources[1], guard)) {
|
||||||
|
customizer = length < 3 ? undefined : customizer;
|
||||||
|
length = 1;
|
||||||
|
}
|
||||||
|
object = Object(object);
|
||||||
|
while (++index < length) {
|
||||||
|
const source = sources[index];
|
||||||
|
if (source) {
|
||||||
|
assigner(object, source, index, customizer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createAssigner;
|
||||||
29
.internal/isIterateeCall.js
Normal file
29
.internal/isIterateeCall.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import isArrayLike from '../isArrayLike.js'
|
||||||
|
import isIndex from './isIndex.js'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given arguments are from an iteratee call.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {*} value The potential iteratee value argument.
|
||||||
|
* @param {*} index The potential iteratee index or key argument.
|
||||||
|
* @param {*} object The potential iteratee object argument.
|
||||||
|
* @returns {boolean} Returns `true` if the arguments are from an iteratee call,
|
||||||
|
* else `false`.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function isIterateeCall(value, index, object) {
|
||||||
|
if (!isObject(object)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const type = typeof index;
|
||||||
|
if (type == 'number'
|
||||||
|
? (isArrayLike(object) && isIndex(index, object.length))
|
||||||
|
: (type == 'string' && index in object)
|
||||||
|
) {
|
||||||
|
return eq(object[index], value);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default isIterateeCall
|
||||||
Reference in New Issue
Block a user