You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
666 B

1 year ago
const iter = (obj, key, lines) => {
1 year ago
if (obj === null) {
1 year ago
lines.push(`${key}=null;`)
return
}
if (Array.isArray(obj)) {
lines.push(`${key}=[];`)
obj.forEach((v, idx) => {
iter(v, `${key}[${idx}]`, lines);
});
return
1 year ago
}
if (typeof obj === "object") {
1 year ago
lines.push(`${key}={};`)
for (const [k,v] of Object.entries(obj)) {
iter(v, `${key}.${k}`, lines);
}
return
1 year ago
}
if (typeof obj === "string") {
1 year ago
lines.push(`${key}=${JSON.stringify(obj)};`);
return
1 year ago
}
1 year ago
lines.push(`${key}=${obj};`)
1 year ago
}
1 year ago
export const gronify = (obj) => {
const lines = []
1 year ago
1 year ago
iter(obj, "json", lines)
1 year ago
1 year ago
return lines.join('\n');
1 year ago
}