|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
916 bytes
|
| Rev | Line | |
|---|
| [a762898] | 1 | import { clone } from './clone.mjs';
|
|---|
| 2 | import { mergeWith } from './mergeWith.mjs';
|
|---|
| 3 | import { isPlainObject } from '../predicate/isPlainObject.mjs';
|
|---|
| 4 |
|
|---|
| 5 | function toMerged(target, source) {
|
|---|
| 6 | return mergeWith(clone(target), source, function mergeRecursively(targetValue, sourceValue) {
|
|---|
| 7 | if (Array.isArray(sourceValue)) {
|
|---|
| 8 | if (Array.isArray(targetValue)) {
|
|---|
| 9 | return mergeWith(clone(targetValue), sourceValue, mergeRecursively);
|
|---|
| 10 | }
|
|---|
| 11 | else {
|
|---|
| 12 | return mergeWith([], sourceValue, mergeRecursively);
|
|---|
| 13 | }
|
|---|
| 14 | }
|
|---|
| 15 | else if (isPlainObject(sourceValue)) {
|
|---|
| 16 | if (isPlainObject(targetValue)) {
|
|---|
| 17 | return mergeWith(clone(targetValue), sourceValue, mergeRecursively);
|
|---|
| 18 | }
|
|---|
| 19 | else {
|
|---|
| 20 | return mergeWith({}, sourceValue, mergeRecursively);
|
|---|
| 21 | }
|
|---|
| 22 | }
|
|---|
| 23 | });
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | export { toMerged };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.