parent
a773f29eb9
commit
f041fcb775
@ -1,23 +1,35 @@
|
||||
const iter = (obj, stack) => {
|
||||
const key = stack.join('.');
|
||||
const iter = (obj, key, lines) => {
|
||||
if (obj === null) {
|
||||
return `${key}=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") {
|
||||
return `${key}={}`
|
||||
lines.push(`${key}={};`)
|
||||
for (const [k,v] of Object.entries(obj)) {
|
||||
iter(v, `${key}.${k}`, lines);
|
||||
}
|
||||
return
|
||||
}
|
||||
if (typeof obj === "string") {
|
||||
return `${key}=${JSON.stringify(obj)}`
|
||||
lines.push(`${key}=${JSON.stringify(obj)};`);
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
return `${key}=${obj}`
|
||||
|
||||
lines.push(`${key}=${obj};`)
|
||||
}
|
||||
export const gronify = (obj) => {
|
||||
|
||||
export const gronify = (obj) => {
|
||||
const lines = []
|
||||
|
||||
iter(obj, ["json"], lines)
|
||||
|
||||
return iter(obj, ["json"])
|
||||
return lines.join('\n');
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue