Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export FormatSpecifier constructor? #65

Closed
johnmeegan opened this issue Oct 24, 2018 · 1 comment
Closed

Export FormatSpecifier constructor? #65

johnmeegan opened this issue Oct 24, 2018 · 1 comment

Comments

@johnmeegan
Copy link

Is there any chance of having the ability to format with an object rather than string, e.g.:
format({ precision: 2, type: 'f' })(1.234);

Rather than:
format(".2f")(1.234);

I think it would be nice to allow being that explicit.

I also have a use case for it where I want to convert from other types of format strings into d3-format style. It's easier to convert from "other" to the specifier object, rather than the extra step of making that object a string as well.

I can see it being possible directly in the format function, or if the FormatSpecifier class was exported and had a constructor that accepts either an object or string:
const specifier = new FormatSpecifier({ precision: 2, type: 'f'}).toString();
format(specifier)(1.2345);

@mbostock
Copy link
Member

Yeah, I’m in favor of exposing the FormatSpecifier class. 👍

@mbostock mbostock changed the title Support passing in a format specifier object instead of string Export FormatSpecifier constructor? Jul 25, 2019
mbostock added a commit that referenced this issue Sep 5, 2019
Fil pushed a commit that referenced this issue Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants