Files
2025-11-28 19:45:44 -07:00

27 lines
916 B
JavaScript

import { clone } from './clone.mjs';
import { mergeWith } from './mergeWith.mjs';
import { isPlainObject } from '../predicate/isPlainObject.mjs';
function toMerged(target, source) {
return mergeWith(clone(target), source, function mergeRecursively(targetValue, sourceValue) {
if (Array.isArray(sourceValue)) {
if (Array.isArray(targetValue)) {
return mergeWith(clone(targetValue), sourceValue, mergeRecursively);
}
else {
return mergeWith([], sourceValue, mergeRecursively);
}
}
else if (isPlainObject(sourceValue)) {
if (isPlainObject(targetValue)) {
return mergeWith(clone(targetValue), sourceValue, mergeRecursively);
}
else {
return mergeWith({}, sourceValue, mergeRecursively);
}
}
});
}
export { toMerged };