1.0.0 • Published 2 years ago
typesafe-units v1.0.0
typesafe-units
unit converter with focus on type-safety, simplicity and performance.
Key Features
Converting
const converted = units.from(3, "cm").to("in");
console.log(converted);
// Output: 1.1811
Comparing
const c1 = units.Convertible(100, "kilometer");
const c2 = units.Convertible(1000, "meter");
if (c1.lt(c2)) {
console.log(`${c1} is less than ${c2}!`);
} else if (c1.eq(c2)) {
console.log(`${c1} and ${c2} are equal!`);
} else {
console.log(`${c1} is greater than ${c2}!`);
}
// Output: 100km is greater than 1000m!
Formatting
const convertible = units.Convertible(12.2323123, "kt");
console.log(convertible.format("%.2f %s", { length: "long" }));
// Output: 12.23 knots
Documentation
Read useful guides here. Read the full documentation here.
Supported Units
Area
Current
Digital
Energy
Force
Length
Mass
Parts-Per
Power
Pressure
Speed
Temperature
Time
Voltage
Volume
1.0.0
2 years ago