Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const csv = require('@fast-csv/format');
const csvStream = csv.format({ headers: true, quoteHeaders: true });
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.end();
// Output:
// "header1","header2"
// value1a,value2a
// value1a,value2a
// value1a,value2a
// value1a,value2a
const csv = require('@fast-csv/format');
const csvStream = csv.format({ headers: true, quoteColumns: true });
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.end();
// Output:
// "header1","header2"
// "value1a","value2a"
// "value1a","value2a"
// "value1a","value2a"
// "value1a","value2a"
const csv = require('@fast-csv/format');
const csvStream = csv.format({ headers: ['header2'] });
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write({ header1: 'value1a', header2: 'value1b' });
csvStream.write({ header1: 'value2a', header2: 'value2b' });
csvStream.write({ header1: 'value3a', header2: 'value3b' });
csvStream.write({ header1: 'value4a', header2: 'value4b' });
csvStream.end();
// Output:
// header2
// value1b
// value2b
// value3b
// value4b
const csv = require('@fast-csv/format');
const csvStream = csv.format({
headers: true,
quoteColumns: { header1: true },
quoteHeaders: { header2: true },
});
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.end();
// Output:
// header1,"header2"
// "value1a",value2a
const csv = require('@fast-csv/format');
const csvStream = csv.format({ headers: true, quoteColumns: { header2: true } });
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.end();
// Output:
// header1,"header2"
// value1a,"value2a"
// value1a,"value2a"
// value1a,"value2a"
// value1a,"value2a"
const csv = require('@fast-csv/format');
const csvStream = csv.format({ headers: ['header1', 'header2'] });
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write(['value1a', 'value1b']);
csvStream.write(['value2a', 'value2b']);
csvStream.write(['value3a', 'value3b']);
csvStream.write(['value4a', 'value4b']);
csvStream.end();
// Output:
// header1,header2
// value1a,value1b
// value2a,value2b
// value3a,value3b
// value4a,value4b
const csv = require('@fast-csv/format');
const transform = row => ({
header1: row.header1.toUpperCase(),
header2: row.header2.toUpperCase(),
});
const csvStream = csv.format({ headers: true, transform });
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.end();
// Output:
// header1,header2
// VALUE1A,VALUE2A
// VALUE1A,VALUE2A
// VALUE1A,VALUE2A
// VALUE1A,VALUE2A
const csv = require('@fast-csv/format');
const csvStream = csv.format({ headers: true }).transform((row, cb) => {
setImmediate(() =>
cb(null, {
header1: row.header1.toUpperCase(),
header2: row.header2.toUpperCase(),
}),
);
});
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.write({ header1: 'value1a', header2: 'value2a' });
csvStream.end();
const csv = require('@fast-csv/format');
const csvStream = csv.format({ headers: true });
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write([
['header', 'value1a'],
['header2', 'value2a'],
]);
csvStream.write([
['header', 'value1b'],
['header2', 'value2b'],
]);
csvStream.write([
['header', 'value1c'],
['header2', 'value2c'],
]);
csvStream.write([
const csv = require('@fast-csv/format');
const csvStream = csv.format({ headers: ['header1', 'header2'] });
csvStream.pipe(process.stdout).on('end', process.exit);
csvStream.write([
['h1', 'value1a'],
['h2', 'value1b'],
]);
csvStream.write([
['h1', 'value2a'],
['h2', 'value2b'],
]);
csvStream.write([
['h1', 'value3a'],
['h2', 'value3b'],
]);
csvStream.write([