Basic backend list and import/export toggle in WebUI.

This commit is contained in:
abdulmohsen
2024-05-01 21:33:29 +03:00
parent c10ebea137
commit a98699269d
10 changed files with 1218 additions and 71 deletions

39
frontend/utils/index.js Normal file
View File

@@ -0,0 +1,39 @@
const ag = (obj, path, defaultValue = null, separator = '.') => {
const keys = path.split(separator);
let at = obj;
for (let key of keys) {
if (typeof at === 'object' && at !== null && key in at) {
at = at[key];
} else {
return defaultValue;
}
}
return at;
}
const ag_set = (obj, path, value, separator = '.') => {
const keys = path.split(separator);
let at = obj;
while (keys.length > 0) {
if (keys.length === 1) {
if (typeof at === 'object' && at !== null) {
at[keys.shift()] = value;
} else {
throw new Error(`Cannot set value at this path (${path}) because it's not an object.`);
}
} else {
const key = keys.shift();
if (!at[key]) {
at[key] = {};
}
at = at[key];
}
}
return obj;
}
export {ag_set, ag}