simple-units
v1.1.5
Published
unit converter with focus on the golden mean between simplicity, customizability and performance
Downloads
729
Maintainers
Readme
simple-units
unit converter with focus on the golden mean between simplicity, customizability 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
Customizing
const myCustomUnit = new Unit(...);
units.group("length").Editor.add(myCustomUnit);
Documentation
Read useful guides here. Read the full documentation here.
Why simple-units?
simple-units is one of the fastest unit converters (see performance tests) while being the most flexible and easiest one. It's designed to feel natural. Added to that as adding custom units to simple-units is very simple, you are not dependend on the package developer (!). Last but not least it supports a huge amount of units and powerful functionality like comparing quantities of different units or formatting them nicely.