Skip to content

Why does autoType mutate the input? #107

@akre54

Description

@akre54

Hi there - mostly curious but what's the reason for autoType mutating the object in-place?

This caused a bug in my app since the function is not idempotent - passing the same object twice succeeds on the first time with a numeric value, and fails on the second due to the object[key].trim() line. The value is a string the first time around, and a number after it is parsed.

The fix is to always clone the result first (i.e. arr.map(r => d3.autoType({ ...r }))) but given how most d3 utility functions are pure I'm surprised to see this. It's clearly intentional given the explicit test for the behavior but am I missing a use case? Or is it just in the interest of speed / it's expected that the happy path is d3.csv(url, d3.autoType)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions