d3 / d3-dsv

A parser and formatter for delimiter-separated values, such as CSV and TSV.
https://d3js.org/d3-dsv
ISC License
436 stars 76 forks source link

Option to quote empty strings? #84

Open nrabinowitz opened 3 years ago

nrabinowitz commented 3 years ago

Right now there's no way to distinguish between empty strings and missing data in formatted output.

csvFormatRows([['value', 'null', 'undefined', 'string'], [0,null,undefined,'']]);

I'd like this to return:

value
0,,,""

But instead I get:

value
0,,,
mbostock commented 3 years ago

This would need a symmetric option with parsing such that an unquoted empty string is mapped to null (or undefined?) whereas a quoted empty string is mapped to the empty string. Specifically in these two places:

https://github.com/d3/d3-dsv/blob/344677983ac44e7bbf0e2527ad7f0223d66a2f38/src/dsv.js#L105

https://github.com/d3/d3-dsv/blob/344677983ac44e7bbf0e2527ad7f0223d66a2f38/src/dsv.js#L109