parent
a773f29eb9
commit
f041fcb775
@ -1,23 +1,35 @@
|
|||||||
const iter = (obj, stack) => {
|
const iter = (obj, key, lines) => {
|
||||||
const key = stack.join('.');
|
|
||||||
if (obj === null) {
|
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") {
|
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") {
|
if (typeof obj === "string") {
|
||||||
return `${key}=${JSON.stringify(obj)}`
|
lines.push(`${key}=${JSON.stringify(obj)};`);
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lines.push(`${key}=${obj};`)
|
||||||
return `${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