Skip to content

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

@alexstrat

Description

@alexstrat

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions