MIT License
A utility for stream-writing CSV and JSON files.
npm i structured-stream-writer
import { StructuredStreamWriter, StructuredFormat } from 'structured-stream-writer';
const sswJSON = new StructuredStreamWriter(StructuredFormat.JSON, outPath);
await sswJSON.writeItem({
item: 1,
text: 'hello',
});
sswJSON.done();
console.log(
readFileSync(outPath, 'UTF8'),
);
/*
* [{item:1,text:"hello"}]
*/
const sswCSV = new StructuredStreamWriter(StructuredFormat.CSV, outPath, ['item', 'text']);
await sswCSV.writeItem({
item: 1,
text: 'hello',
});
sswCSV.done();
console.log(
readFileSync(outPath, 'UTF8'),
);
/*
* item,text
* 1,hello
*/