adaltas / node-csv-stringify

CSV stringifier implementing the Node.js `stream.Transform` API
https://csv.js.org/stringify/
186 stars 52 forks source link

[ help request ] Is it possible to quote values based on their column name ? #90

Closed smonff closed 5 years ago

smonff commented 5 years ago

I have a customer who wan't it's CSV quoted on some columns and not on others. I would have expect to find some stringify quoting option based on the columns names (header).

Expected output:

"Email";"Id";Date
"foo@bar.com";"123456",2019-10-25
...

I would have except something like this with a fictional quoted_columns option:

stringify(data, {
    columns: columns,
    delimiter: ';',
    header: true,
   // column_b won't be quoted
   quoted_columns: ['column_a', 'column_c']  
}, (err, output) => {
    if (err) throw err
    ...
)

Any help appreciated.

wdavidw commented 5 years ago

Have a look at the cast option which allows you to activate/desactive options for each field.

smonff commented 5 years ago

Thank you very much @wdavidw .