Hi! I recently tried to format the size of a file using the NumberFormat and the byte unit. It works great, but obviously, "400.000 Bytes" is not very user-friendly. So I would like to propose something like automatic unit conversion.
Maybe it could look something like this: (problematic with imperial units, see comments below)
{
style: 'unit',
unit: ['byte', 'kilobyte', 'megabyte'],
unitConversionTreshold: 1000,
}
This would cause NumberFormat to convert whenever the treshold is reached, like this:
- 50 → "50 Bytes"
- 1.000 → "1 Kilobyte"
- 1.050 → "1.05 Kilobyte"
- 1.000.000 → "1 Megabyte"
Another, less flexible way to configure this might be with "measurements":
{
style: 'measurement',
measurement: 'length',
measurementBaseUnit: 'meter'
}
This would automatically convert through a series of units, e.g. 'millimeter' → 'centimeter' → 'meter' → 'kilometer', starting with a configurable base unit.
I think it would make great sense to include such a feature in this API, but I couldn't find any proposal for it. What do you think about this? Do I need to elaborate more on the details? I'm looking forward to your feedback!
Cheers,
Till