source: node_modules/es-toolkit/dist/compat/object/assignInWith.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 995 bytes
Line 
1import { keysIn } from './keysIn.mjs';
2import { isEqualsSameValueZero } from '../../_internal/isEqualsSameValueZero.mjs';
3
4function assignInWith(object, ...sources) {
5 let getValueToAssign = sources[sources.length - 1];
6 if (typeof getValueToAssign === 'function') {
7 sources.pop();
8 }
9 else {
10 getValueToAssign = undefined;
11 }
12 for (let i = 0; i < sources.length; i++) {
13 assignInWithImpl(object, sources[i], getValueToAssign);
14 }
15 return object;
16}
17function assignInWithImpl(object, source, getValueToAssign) {
18 const keys = keysIn(source);
19 for (let i = 0; i < keys.length; i++) {
20 const key = keys[i];
21 const objValue = object[key];
22 const srcValue = source[key];
23 const newValue = getValueToAssign?.(objValue, srcValue, key, object, source) ?? srcValue;
24 if (!(key in object) || !isEqualsSameValueZero(objValue, newValue)) {
25 object[key] = newValue;
26 }
27 }
28}
29
30export { assignInWith };
Note: See TracBrowser for help on using the repository browser.