ericman314 / UnitMath

JavaScript library for unit conversion and arithmetic
Apache License 2.0
31 stars 7 forks source link

Simplify the API of the formatter #47

Closed josdejong closed 1 year ago

josdejong commented 2 years ago

Looking at the docs of the custom formatter, https://github.com/ericman314/UnitMath#custom-formatter , I have the feeling that the formatter option can be simpler, by removing the possibility to pass additional arguments to it via toString. I think you can achieve that already by changing:

unit('3.14159 rad').toString({ formatter: funnyFormatter }, '$', '_'

to

unit('3.14159 rad').toString({ formatter: value => funnyFormatter(value, '$', '_') }

// or 

const funnyFormatter$ = value => funnyFormatter(value, '$', '_')
unit('3.14159 rad').toString({ formatter: funnyFormatter$ }
ericman314 commented 2 years ago

I'm not sure. I definitely agree that the documentation on formatter is too complicated though. I don't remember if there was a reason we had to support passing user args into the formatter. Maybe when I wrote it I had just learned about JavaScript's spread operator and was looking for a nail to hit with that hammer. I may just leave it undocumented.

josdejong commented 2 years ago

👍 not a big deal, I just felt like the API could be a bit simpler without sacrificing anything.

ericman314 commented 1 year ago

I ended up taking your advice in 1.0.0-rc2 and removed the additional arguments to the custom formatter, under the principle of "you aren't gonna need it."

josdejong commented 1 year ago

👍