|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
987 bytes
|
| Line | |
|---|
| 1 | import { keys } from './keys.mjs';
|
|---|
| 2 | import { isEqualsSameValueZero } from '../../_internal/isEqualsSameValueZero.mjs';
|
|---|
| 3 |
|
|---|
| 4 | function assignWith(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 | assignWithImpl(object, sources[i], getValueToAssign);
|
|---|
| 14 | }
|
|---|
| 15 | return object;
|
|---|
| 16 | }
|
|---|
| 17 | function assignWithImpl(object, source, getValueToAssign) {
|
|---|
| 18 | const keys$1 = keys(source);
|
|---|
| 19 | for (let i = 0; i < keys$1.length; i++) {
|
|---|
| 20 | const key = keys$1[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 |
|
|---|
| 30 | export { assignWith };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.