-
Notifications
You must be signed in to change notification settings - Fork 3
Description
I believe this is rightfully out of scope for the initial proposal here but I wanted to, at the very least, capture the idea while it is fresh in my head following the discussions this week. I absolutely appreciate and agree with the approach of the proposal relying on the CLDR unit specification for the definition of unit
for amounts. However, I can also see valid use cases for allowing users to define units themselves. For this, a Unit
type could be useful. This could be as simple as allowing a unit to be expressed as a Symbol
:
const amount = Amount.from(12, { unit: Symbol('my-custom-unit') });
Obviously this would have Intl formatting challenges, however. An alternative approach could be to use a typed approach where a Unit
may implement it's own toLocaleString(...)
for Intl
const MyUnit = Unit.from({ toLocaleString(decimal, locale) { });
const amount = Amount.from(12, { unit: new MyUnit() });
There are, I'll admit, a number of flaws with both of these examples but again, the idea here is just to document the possibility.