HomeDashboard/.venv/lib/python3.12/site-packages/nicegui/static/utils/dynamic_properties.js
2026-01-03 14:54:18 +01:00

30 lines
780 B
JavaScript

export function convertDynamicProperties(obj, recursive) {
if (typeof obj !== "object" || obj === null) {
return;
}
if (Array.isArray(obj)) {
if (recursive) {
obj.forEach((v) => convertDynamicProperties(v, true));
}
return;
}
for (const [attr, value] of Object.entries(obj)) {
if (attr.startsWith(":")) {
try {
try {
obj[attr.slice(1)] = new Function(`return (${value})`)();
} catch (e) {
obj[attr.slice(1)] = eval(value);
}
delete obj[attr];
} catch (e) {
console.error(`Error while converting ${attr} attribute to function:`, e);
}
} else {
if (recursive) {
convertDynamicProperties(value, true);
}
}
}
}