borgar / numfmt

Full ECMA-376 number and date formatting in JavaScript
40 stars 9 forks source link

Consider indicating whether "black" color is explicitly specified or assigned as a default #40

Closed madrev closed 5 months ago

madrev commented 1 year ago

In our application, we'd like to use the color defined in the format string if it is explicitly specified, falling back to some other default if not.

Unfortunately it seems numfmt returns black in both of these cases and there's no way to discern whether black has been explicitly specified for the given value or not. Formatter.info almost does this, but only for negative values.

Might you consider either providing more detail in formatter.info for the non-negative cases, or providing some metadata at format time to indicate whether black was specified? More drastically, maybe it could not return black in the unspecified case? (I suppose this would be a breaking change).

Happy to try to cut a PR if we can agree on a direction.

borgar commented 1 year ago

I think both having better details in info and not returning a value if none was specified are better than the current behavior is. 🙂 There is the possibility of having this as an option as well. I've done that for a few backwards incompatible things recently.

I am currently looking more critically at the library. There are a number of things that can be simplified quote a lot and so I may just do a breaking major version update and fix the color function.