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

d3.autotype: keep leading 0 #79

Closed ericemc3 closed 3 years ago

ericemc3 commented 3 years ago

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?

mbostock commented 3 years ago

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)}))