How to use the @fast-csv/format.writeToString function in @fast-csv/format

To help you get started, we’ve selected a few @fast-csv/format examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github C2FO / fast-csv / examples / formatting-js / examples / write_to_string_no_headers.example.js View on Github external
const csv = require('@fast-csv/format');

const data = [
    { a: 'a1', b: 'b1' },
    { a: 'a2', b: 'b2' },
];
csv.writeToString(data, { headers: false })
    .then(formattedCsv => {
        console.log(formattedCsv);
        process.exit();
    })
    .catch(err => {
        console.error(err.stack);
        process.exit(1);
    });

// Output:
// a1,b1
// a2,b2
github C2FO / fast-csv / examples / formatting-js / examples / write_to_string.example.js View on Github external
const csv = require('@fast-csv/format');

const rows = [
    ['a', 'b'],
    ['a1', 'b1'],
    ['a2', 'b2'],
];
csv.writeToString(rows).then(data => console.log(data));

// Output:
// a,b
// a1,b1
// a2,b2
github C2FO / fast-csv / examples / formatting-js / examples / write_to_string_transform.example.js View on Github external
const csv = require('@fast-csv/format');

const data = [
    { a: 'a1', b: 'b1' },
    { a: 'a2', b: 'b2' },
];

const transform = row => ({
    A: row.a,
    B: row.b,
});

csv.writeToString(data, { headers: true, transform })
    .then(formattedCsv => console.log(formattedCsv))
    .catch(err => console.error(err.stack));

// Output:
// A,B
// a1,b1
// a2,b2