Convert
The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript.

npm install convert
yarn add convert
More installation steps below.
convert(5, 'miles').to('km');
convertMany('4d 16h').to('minutes');
Features
- Full build time and runtime validation of conversions
- Using a web framework like Next.js or Nuxt.js? You get 0-cost build-time conversions. Convert is totally side-effect free, so conversions will be precalculated at build-time, so absolutely zero conversion code is sent to clients!
- Works in browsers and Node.js (UMD and ESM builds will work anywhere)
- Out of the box ES3 backwards-compatibility (CI tests on Node.js v0.9.1)
- Absolutely tiny bundle size and 0 dependencies
- Supports bigints without breaking on old engines
Usage
Generated API documentation for the latest version is available online.
View docs.
import convert from 'convert';
const {convert} = require('convert');
convert(360, 'seconds').to('minutes');
convert(20n, 'hours').to('minutes');
convert(5500, 'meters').to('best');
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');
Converting many units
import {convertMany} from 'convert';
const {convertMany} = require('convert');
convertMany('1d8h').to('ms');
Converting to best unit
import convert from 'convert';
const {convert} = require('convert');
const duration = convert(36, 'h').to('best');
'duration is ' + duration;
convert(3.5, 'km').to('best');
convert(3.5, 'km').to('best', 'metric');
convert(3.5, 'km').to('best', 'imperial');
ms
shorthand
import {ms} from 'convert';
const {ms} = require('convert');
ms('1d 2h 30min');
Installation
Package manager
Convert is published as convert
on npm.
npm install convert
yarn add convert
CommonJS
const {convert} = require('convert');
const {convert} = require('convert/dev');
const {convert} = require('convert/prod');
ES Modules
import convert from 'convert';
import convert from 'convert/dev';
import convert from 'convert/prod';
Browsers
Pick your favorite CDN:
Modules
<script type="module">
import convert from 'https://cdn.skypack.dev/convert@4';
import convert from 'https://esm.run/convert@4';
import convert from 'https://cdn.jsdelivr.net/npm/convert@4';
import convert from 'https://unpkg.com/convert@4';
</script>
UMD (global)
<script src="https://cdn.jsdelivr.net/npm/convert@4/dist/convert.prod.js"></script>
<script src="https://unpkg.com/convert@4/dist/convert.prod.js"></script>
Alternatives
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.




