A Flowtype-safe API for handling numbers with associated units
import { UnitizedNumber, Length, Angle } from 'unitized'
new UnitizedNumber(2, Length.feet)
.add(new UnitizedNumber(3, Length.meters))
.toString()
// '11.842519685039369 ft'
// More convenient construction:
Length.feet
.of(2)
.add(Length.meters.of(3))
.toString()
// '11.842519685039369 ft'
Length.feet
.of(1)
.in(Length.meters)
.toString()
// '0.3048 m'
Length.feet.of(1).get(Length.meters)
// 0.3048
import { UnitizedNumber } from 'unitized'
Represents a number and a unit. The type parameters guard against operations on unrelated units (e.g. 1 meter + 5 degrees) by causing Flow errors.
Example: const twoMeters: UnitizedNumber<Length> = new UnitizedNumber(2, Length.meters)
Returns a new UnitizedNumber equal to this plus addend, in this number's units.
Returns a new UnitizedNumber equal to this minus addend, in this number's units.
Returns a new UnitizedNumber equal to this times multiplicand, in this number's units.
For example, 1 meter * 6 = 6 meters.
Returns the remainder after dividing this number by modulus, in this number's units.
For example, 345 centimeters % 2 meters = 145 centimeters.
Returns a new UnitizedNumber equal to this divided by denominator, in this number's units.
For example, 1 meter / 5 = 0.2 meters.
Returns a this divided by denominator, a unitless quantity.
For example, 1 meter / 50 centimeters = 2.
Returns true iff the value (regardless of units) is not NaN or infinite.
Returns true iff the value is positive.
Returns true iff the value is negative.
Returns true iff the value is zero.
Returns true iff the value is not zero.
Returns a UnitizedNumber
that has the negative value in
the same units.
Returns a non-negative UnitizedNumber
that has the same
magnitude in the same units.
Returns > 0 if this > other, < 0 if this < other, and 0 otherwise.
The type for units of length.
The type for units of area.
E.g. Area.squares.get(Length.meters) === Area.squareMeters
Multiplies two lengths together and returns the result as an area.
Squares a length and returns the result as an area.
Takes the square root of an area and returns the result as a length.
Divides an area by a length, return the result as a length.
The type for units of angle.
1/360 of a unit circle
Arclength on a unit circle
1/400 of a unit circle
NATO mils (1/6400 of a unit circle)
The ratio of the rise over the run expressed as a percent. 100% = 45 degrees.