Skip to content

Commit 8eccdd0

Browse files
blikblumjdalton
authored andcommitted
Restore createAssigner (fixes compilation of merge and mergeWith) (#4101)
1 parent 508d46a commit 8eccdd0

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

.internal/createAssigner.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import isIterateeCall from './isIterateeCall.js';
2+
3+
/**
4+
* Creates a function like `assign`.
5+
*
6+
* @private
7+
* @param {Function} assigner The function to assign values.
8+
* @returns {Function} Returns the new assigner function.
9+
*/
10+
function createAssigner(assigner) {
11+
return (object, ...sources) => {
12+
let index = -1;
13+
let length = sources.length;
14+
let customizer = length > 1 ? sources[length - 1] : undefined;
15+
const guard = length > 2 ? sources[2] : undefined;
16+
17+
customizer = (assigner.length > 3 && typeof customizer == 'function')
18+
? (length--, customizer)
19+
: undefined;
20+
21+
if (guard && isIterateeCall(sources[0], sources[1], guard)) {
22+
customizer = length < 3 ? undefined : customizer;
23+
length = 1;
24+
}
25+
object = Object(object);
26+
while (++index < length) {
27+
const source = sources[index];
28+
if (source) {
29+
assigner(object, source, index, customizer);
30+
}
31+
}
32+
return object;
33+
};
34+
}
35+
36+
export default createAssigner;

.internal/isIterateeCall.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import isArrayLike from '../isArrayLike.js'
2+
import isIndex from './isIndex.js'
3+
4+
/**
5+
* Checks if the given arguments are from an iteratee call.
6+
*
7+
* @private
8+
* @param {*} value The potential iteratee value argument.
9+
* @param {*} index The potential iteratee index or key argument.
10+
* @param {*} object The potential iteratee object argument.
11+
* @returns {boolean} Returns `true` if the arguments are from an iteratee call,
12+
* else `false`.
13+
*/
14+
15+
function isIterateeCall(value, index, object) {
16+
if (!isObject(object)) {
17+
return false;
18+
}
19+
const type = typeof index;
20+
if (type == 'number'
21+
? (isArrayLike(object) && isIndex(index, object.length))
22+
: (type == 'string' && index in object)
23+
) {
24+
return eq(object[index], value);
25+
}
26+
return false;
27+
}
28+
29+
export default isIterateeCall

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy