ryu1kn / csv-writer

Convert objects/arrays into a CSV string or write them into a CSV file
https://www.npmjs.com/package/csv-writer
MIT License
246 stars 39 forks source link

alwaysQuote option doesn't quote null fields #60

Open deakinhead opened 3 years ago

deakinhead commented 3 years ago

Hi. I'm using csv writer to integrate with a warehouse and they require that all values, including null values, in the csv be double quoted. I set the alwaysQuote option to true, but it looks like null values still get output as

,,,,,

rather than

,"","","","",

Would it be possible to add a new option to double quote null values or to update the existing option so that it works that way?

ryu1kn commented 3 years ago

Hi @deakinhead , thanks for the suggestion. I want to avoid making a breaking change at this stage; so probably need to introduce a new flag. Naming would be a struggle. Wish alwaysQuote gave quotes even for empty fields...

ryu1kn commented 3 years ago

ref https://github.com/ryu1kn/csv-writer/issues/38

ryu1kn commented 3 years ago

quoteEmptyFields ?

deakinhead commented 3 years ago

@ryu1kn Thanks for the quick response. quoteEmptyFields sounds good to me.

How long do you think it would take to add?

blowfishlol commented 1 year ago

Hi @ryu1kn , i have opened a PR to add this param into the writers :)

https://github.com/ryu1kn/csv-writer/pull/97

This makes the writer accept quoteEmptyFields param, that makes nullish (null/undefined) values to be written with empty double-quote "" on the CSV generation.