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

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

Added visualizations

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