adaltas / node-csv

Full featured CSV parser with simple api and tested against large datasets.
https://csv.js.org
MIT License
4.05k stars 267 forks source link

`csv-stringify/sync` does not output headers when input is an empty array #343

Closed alexstrat closed 2 years ago

alexstrat commented 2 years ago

Describe the bug

Even if used with header: true and columns options, csv-stringify/sync does not output headers when input is an empty array.

The stream or callback API does.

To Reproduce

const { stringify } = require('csv-stringify/sync')

stringify([], { header: true, columns: ['foo', 'bar']})
// ❌ returns '' 
// expected 'foo,bar'

const { stringify } = require('csv-stringify')
stringify([], { header: true, columns: ['foo', 'bar']}, (e, content) => console.log(content))
// ✅ logs 'foo,bar'