@norvento/csv-generator
v2.2.0
Published
Norvento CSV Generator
Downloads
52
Keywords
Readme
Norvento csv generator
Usage
Install the library:
yarn install @norvento/csv-generator
Create the csv headers definition like this:
const csvHeaders = [ {id: "id1", title: "title1"}, {id: "id2", title: "title2"}, {id: "id3", title: "title3"}, ]
Create the CSVGenerator instance and provide the csv headers and a locale. The locale is used to localize the numbers and dates:
const csvGenerator = new CSVGenerator(csvHeaders, 'es-ES');
Call
csvGenerator.generateCsv(content)
, where content is your raw data to be transformed to CSV. The raw data must have the following format:const content = [ { id1: "value id1 row 1", id2: "value id2 row 1", id3: "value id3 row 1", }, { id1: "value id1 row 2", id2: "value id2 row 2", id3: "value id3 row 2", }, ... ]
The csv is returned as a string.