@modern-js/runtime-utils
Version:
A Progressive React Framework for modern web development.
28 lines (27 loc) • 1.04 kB
JavaScript
import "node:module";
function isObject(obj) {
return obj && 'object' == typeof obj && !Array.isArray(obj);
}
function isComplexInstance(obj) {
if (!isObject(obj)) return false;
const hasMethods = 'function' == typeof obj.init || 'function' == typeof obj.changeLanguage || 'function' == typeof obj.t;
const hasInternalProps = void 0 !== obj.isInitialized || void 0 !== obj.language || void 0 !== obj.store;
return hasMethods || hasInternalProps;
}
function merge(target, ...sources) {
if (!sources.length) return target;
const source = sources.shift();
if (isObject(target) && isObject(source)) for(const key in source)if (isComplexInstance(source[key])) Object.assign(target, {
[key]: source[key]
});
else if (isObject(source[key])) {
if (!target[key]) Object.assign(target, {
[key]: {}
});
merge(target[key], source[key]);
} else Object.assign(target, {
[key]: source[key]
});
return merge(target, ...sources);
}
export { merge };