import { Readable } from "node:stream"; const objType = (obj) => { if (obj === null) { return 'null' } if (Array.isArray(obj)) { return 'array' } return typeof obj } function* gronGenerator(obj, root = `json`) { switch (objType(obj)) { case 'object': yield `${root}={};\n`; for (const key in obj) { yield* gronGenerator(obj[key], `${root}.${key}`); } break; case 'array': yield `${root}=[];\n`; for (let i = 0; i < obj.length; i++) { yield* gronGenerator(obj[i], `${root}[${i}]`); } break; default: yield `${root}=${JSON.stringify(obj)};\n`; } } export const gronReadStream = (obj) => { return Readable.from(gronGenerator(obj)); }