Restore createAssigner (fixes compilation of merge and mergeWith) (#4101)

This commit is contained in:
Luiz Américo
2018-12-05 02:09:54 -02:00
committed by John-David Dalton
parent 508d46a7a4
commit 8eccdd098a
2 changed files with 65 additions and 0 deletions

View 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;

View 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