source: node_modules/es-toolkit/dist/object/toMerged.mjs@ a762898

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

Added visualizations

  • Property mode set to 100644
File size: 916 bytes
Line 
1import { clone } from './clone.mjs';
2import { mergeWith } from './mergeWith.mjs';
3import { isPlainObject } from '../predicate/isPlainObject.mjs';
4
5function 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
26export { toMerged };
Note: See TracBrowser for help on using the repository browser.