ISNIT0 / structured-stream-writer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StructuredStreamWriter

A utility for stream-writing CSV and JSON files.

npm CodeFactor Build Status codecov NPM License

Usage

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
*/

Used By

License - MIT

./LICENSE

About

License:MIT License


Languages

Language:TypeScript 79.0%Language:Shell 17.5%Language:JavaScript 3.5%