UNPKG

@iwsio/json-csv-node

Version:

ESM/CJS module that easily converts JSON to CSV. This package supports streaming and buffered conversion to CSV.

21 lines (20 loc) 863 B
import { Writable, WritableOptions } from 'stream'; import { StringDecoder } from 'string_decoder'; /** * This is a writable stream that encodes data to an internal buffered string. It's pulled from Node14 docs and used as a test utility here. * Ex: * ``` * const writer = new StringWriter({defaultEncoding: 'utf8'}) * Readable.from(['1', '2', '3']).pipe(writer).finish(() => { console.log(writer.data) }) * '123' * ``` * See: https://nodejs.org/docs/latest-v14.x/api/stream.html#stream_decoding_buffers_in_a_writable_stream */ export default class StringWriter extends Writable { _decoder: StringDecoder; data: any; constructor(options?: WritableOptions); _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void; _final(callback: (error?: Error | null) => void): void; } export { StringWriter };