This commit is contained in:
znetsixe
2026-02-23 13:17:47 +01:00
parent 1cfb36f604
commit c60aa40666
17 changed files with 358 additions and 53 deletions

View File

@@ -73,17 +73,25 @@ class ConfigUtils {
return updatedConfig;
}
_isPlainObject(value) {
return Object.prototype.toString.call(value) === '[object Object]';
}
// loop through objects and merge them obj1 will be updated with obj2 values
mergeObjects(obj1, obj2) {
for (let key in obj2) {
if (obj2.hasOwnProperty(key)) {
if (typeof obj2[key] === 'object') {
if (!obj1[key]) {
const nextValue = obj2[key];
if (Array.isArray(nextValue)) {
obj1[key] = [...nextValue];
} else if (this._isPlainObject(nextValue)) {
if (!this._isPlainObject(obj1[key])) {
obj1[key] = {};
}
this.mergeObjects(obj1[key], obj2[key]);
this.mergeObjects(obj1[key], nextValue);
} else {
obj1[key] = obj2[key];
obj1[key] = nextValue;
}
}
}