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