d3 / d3-dsv

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

Initialization of columns Property for xxxParse(...) methods #31

Closed tomwanzek closed 7 years ago

tomwanzek commented 7 years ago

In the edge case where the to-be-parsed string passed into xxxParse(...) methods is empty, the column property of the returned parsed array is undefined.

Although this is an edge case, it seems preferable to return an empty array of column names for consistency.

(Thanks @azoson for pointing this behaviour out in DefinitelyTyped/DefinitelyTyped#21092 and DefinitelyTyped/DefinitelyTyped#21162 . cc @gustavderdrache)

mbostock commented 7 years ago

Yep, a bug. I’d probably change the assignment to:

rows.columns = columns || [];
tomwanzek commented 7 years ago

I just pushed a PR to save you the trouble :smile: I thought the initialization could happen right when columns is declared.

Both approaches should work, if you want me to change the PR to your fallback assignment, I could quickly change it. your call.

tomwanzek commented 7 years ago

@mbostock I changed the PR to use the fallback approach: rows.columns = columns || [];