You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd probably implement this by having some kind of API to create an instance of a Converter class which lets you register custom units at runtime somehow. With the current way Convert is written this would be a bit of a hassle to add since all the current code uses the one big lookup table for conversion ratios.
I'm pretty busy these days so unfortunately I can't make any guarantees on when I'll have time to add this feature.
I ended up saving custom units in DB as I had such requirement. type CustomUnit = { name: string; conversionFactor: number; baseUnit: string; measurementType: string }
So if a bag is 50kg
My custom unit looks like:
{ name: 'bag', conversionFactor: 50, baseUnit: 'kg', measurementType: 'mass' }
to convert to grams, I can do: convert(customUnit.conversionFactor * value, customUnit.baseUnit).to(targetUnit)
Feature request: Ability to define custom units
If this is already possible, some documentation on how to do so would be super.
The text was updated successfully, but these errors were encountered: