jscheiny/safe-units

Measure.of(<value>, bytes) yields value in bits

tymokvo opened this issue · 3 comments

Hello!

From the readme, I expected:

console.log(Measure.of(72, bytes).toString());

to print 72 B

but, the result is 576 b as the underlying value created by Measure.of is in bits.

This is a bit confusing as other higher order units behave as I would expect them to, e.g.:

console.log(Measure.of(72, kilograms).toString());

yields 72 kg rather than 72000 g.

Using v1.1.0 with Typescript v4.3.5.

your kilogram example works because kilograms is the base unit of mass, but if you were to use pounds instead

console.log(Measure.of(72, pounds).toString());
// prints: 32.658650640000005 kg

you should use .in instead to print in a particular unit:

console.log(Measure.of(72, bytes).in(bytes));

Makes sense! But still confusing. Maybe a reference to the SI base units in the documentation would help? For those of us (like me 😬 ) who haven't taken physics for a while?

NIST has a good reference here, though it is US-centric. The ISO standard is paywalled, unfortunately.