Methods

format

csv.format(options): CsvFormatterStream

This is the main entry point for formatting CSVs. It is used by all other helper methods.

import { format } from '@fast-csv/format';
const stream = format();
stream.pipe(process.stdout);
stream.write(['a', 'b']);
stream.write(['a1', 'b1']);
stream.write(['a2', 'b2']);
stream.end();

write

write(rows[, options]): CsvFormatterStream

Create a formatter, writes the rows and returns the CsvFormatterStream.

import { write } from '@fast-csv/format';
const rows = [
['a', 'b'],
['a1', 'b1'],
['a2', 'b2'],
];
write(rows).pipe(process.stdout);

writeToStream

writeToStream(stream, rows[, options])

Write an array of values to a WritableStream, and returns the original stream

import { writeToStream } from '@fast-csv/format';
const rows = [
['a', 'b'],
['a1', 'b1'],
['a2', 'b2'],
];
writeToStream(process.stdout, rows);

writeToPath

writeToPath(path, rows[, options])

Write an array of values to the specified path

import { writeToPath } from '@fast-csv/format';
const rows = [
['a', 'b'],
['a1', 'b1'],
['a2', 'b2'],
];
writeToPath(path.resolve(__dirname, 'tmp.csv'), rows)
.on('error', err => console.error(err))
.on('finish', () => console.log('Done writing.'));

writeToString

writeToString(arr[, options]): Promise<string>

Formats the rows and returns a Promise that will resolve with the CSV content as a string.

import { writeToString } from '@fast-csv/format';
const rows = [
['a', 'b'],
['a1', 'b1'],
['a2', 'b2'],
];
writeToString(rows).then(data => console.log(data));

writeToBuffer

writeToBuffer(arr[, options]): Promise<Buffer>

Formats the rows and returns a Promise that will resolve with the CSV content as a Buffer.

import { writeToBuffer } from '@fast-csv/format';
const rows = [
['a', 'b'],
['a1', 'b1'],
['a2', 'b2'],
];
writeToBuffer(rows).then(data => console.log(data.toString()));