The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript.
The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript.
The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript.
npm install convertMore installation examples below.
convert(5, "miles").to("km");
convertMany("4d 16h").to("minutes");Generated API documentation for the latest version is available online.
import convert from "convert";
// 360 seconds into minutes
convert(360, "seconds").to("minutes");
// -> 6
// BigInt support
convert(20n, "hours").to("minutes");
// -> 1200n
// Format to the best unit automatically
convert(5500, "meters").to("best");
// -> { quantity: 5.5, unit: 'km', toString: () => '5.5 km' }
// You can also do length, data, volume, mass, temperature, and more
convert(5, "kilometers").to("nautical miles");
convert(12, "pounds").to("ounces");
convert(8192, "bytes").to("KiB");
convert(10, "atmospheres").to("kPa");
convert(451, "fahrenheit").to("celsius");import { convertMany } from "convert";
// Convert 1 day and 8 hours into ms
convertMany("1d8h").to("ms");…ms shorthandimport { ms } from "convert";
// Convert a duration into milliseconds
ms("1d 2h 30min");
// -> 95400000
// Convert milliseconds to a string
ms(86400000);
// -> '1d'Convert is published as convert on npm.
npm install convertAnd then import it in your code like this:
import convert from "convert";Convert is better than other unit conversion libraries because it's faster and smaller than them, while having the same features. Benchmarks of popular unit conversion libraries, including Convert are available here.
Convert is the fastest, taking less than a microsecond for all functions.
That's a little over 3 million convert() calls per second.
No open issues yet, or sync has not completed.