@polgubau/utils
Version:
A collection of utility functions for TypeScript
24 lines • 728 B
JavaScript
// src/objects/merge/merge.ts
function isObjectLike(value) {
return typeof value === "object" && value !== null;
}
function merge(target, source) {
const sourceKeys = Object.keys(source);
for (const key of sourceKeys) {
const sourceValue = source[key];
const targetValue = target[key];
if (Array.isArray(sourceValue)) {
target[key] = merge(targetValue ?? [], sourceValue);
} else if (isObjectLike(targetValue) && isObjectLike(sourceValue)) {
target[key] = merge(targetValue ?? {}, sourceValue);
} else if (targetValue === void 0 || sourceValue !== void 0) {
target[key] = sourceValue;
}
}
return target;
}
export {
isObjectLike,
merge
};
//# sourceMappingURL=merge.mjs.map