openwrt_helloworld/nikki/files/ucode/include.uc
gitea-action 43c8983a46 nikki: sync upstream
last commit: f511e3e880
2025-02-24 19:30:22 +08:00

45 lines
715 B
Ucode

export function uci_bool(obj) {
return obj == '1';
};
export function uci_array(obj) {
if (obj == null) {
return [];
}
if (type(obj) == 'array') {
return uniq(obj);
}
return [obj];
};
export function trim_all(obj) {
if (obj == null) {
return null;
}
if (type(obj) == 'string') {
if (length(obj) == 0) {
return null;
}
return obj;
}
if (type(obj) == 'array') {
if (length(obj) == 0) {
return null;
}
return obj;
}
if (type(obj) == 'object') {
const obj_keys = keys(obj);
for (let key in obj_keys) {
obj[key] = trim_all(obj[key]);
if (obj[key] == null) {
delete obj[key];
}
}
if (length(obj_keys) == 0) {
return null;
}
return obj;
}
return obj;
};