max-mapper / csv-write-stream

A CSV encoder stream that produces properly escaped CSVs
BSD 2-Clause "Simplified" License
204 stars 37 forks source link

Specifying Headers, when second item in data has more data. #48

Closed jrgonzalezrios closed 2 years ago

jrgonzalezrios commented 2 years ago

Hi I am trying to specify a list of known headers like this:

var writer = csvWriter({ headers: ["header1", "header2", "header3"]})
writer.pipe(fs.createWriteStream('out.csv'))
writer.write([
{
      header1: 'value1',
      header2: 'value2'
    },
{
      header1: 'value3',
      header2: 'value4',
      header3: 'value5',
    }
])
writer.end()

so the output would have a:

header1, header2, header3 value1, value2, value3, value4, value5

As you can see the first row does not have the header3, but should add an empty value for column 'header3'