MultiLoader-Template/node_modules/es-toolkit/dist/object/toMerged.mjs
3944Realms 768f38fc97 feat: 可使用的构建模板
修改了脚本,使其可以推给Maven仓库
2026-05-03 13:02:19 +08: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 };