d3 / d3-dsv

A parser and formatter for delimiter-separated values, such as CSV and TSV.

Home Page:https://d3js.org/d3-dsv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

d3.autotype: keep leading 0

ericemc3 opened this issue · comments

Is there a reason, besides performance, for d3.autotype skipping leading 0?
d3.autoType({id: "06075"})
=> 6075

d3.autotype is quite convenient.
Could a test on leading 0 be added to avoid string to number conversion here?

We designed the behavior of d3.autoType based on JavaScript. If it’s not what you want, you should implement your own row conversion function. Changing this behavior now would not be backwards-compatible, and also we wanted a strong precedent for the behavior so that it’s easier for folks to remember how d3.autoType behaves.

If you want to skip a specific field when using d3.autoType, consider using destructuring spread:

d3.csvParse(string, ({id, ...rest}) => ({id, ...d3.autoType(rest)}))