# convert

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

Latest version **8.0.2** (published 2026-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install convert
pnpm add convert
yarn add convert
bun add convert
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 8.0.2 |
| Published | 2026-09-10 |
| First published | 2020-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 1000.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 201 |
| Author | Jonah Snider |
| Maintainers | jonahsnider |
| Keywords | convert, convert-units, unit-conversion, uom, metric, imperial, units, unit, measurement, measure, temperature, mass, weight, length, data |

## Links

- npm: https://www.npmjs.com/package/convert
- Repository: https://github.com/jonahsnider/convert
- Homepage: https://convert.js.org/
- npm.io page: https://npm.io/package/convert

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 8.0.2 (latest) — 2026-09-10
- 0.2.0-canary (canary) — 2020-06-11
- 8.0.1 — 2026-09-04
- 7.0.2 — 2026-07-22
- 7.0.0 — 2026-02-24
- 6.0.0 — 2026-01-17
- 5.14.1 — 2025-12-15
- 5.13.1 — 2025-10-29
- 5.12.1 — 2025-10-11
- 5.12.0 — 2025-05-09
- 5.11.0 — 2025-04-24
- 5.10.0 — 2025-04-11
- 5.9.0 — 2025-03-27
- 5.8.0 — 2025-02-19
- 5.7.0 — 2024-12-07
- … 86 more at https://npm.io/package/convert/versions

## README

# Convert

The [smallest](https://bundlephobia.com/package/convert) & [fastest](https://github.com/jonahsnider/js-unit-conversion-benchmarks) library for really easy, totally type-safe unit conversions in TypeScript & JavaScript.

[![bundle size](https://img.shields.io/bundlephobia/minzip/convert)](https://bundlephobia.com/package/convert)
[![npm monthly downloads](https://img.shields.io/npm/dm/convert)](https://www.npmjs.com/package/convert)

```sh
npm install convert
```

[**More installation examples below**](#Installation).

```js
convert(5, "miles").to("km");
convertMany("4d 16h").to("minutes");
```

## Features

- Full build time and runtime validation of conversions
- Web frameworks like Next.js and Vite know that Convert is side-effect free, so [conversions will be precalculated at build-time](https://github.com/jonahsnider/convert/blob/main/docs/build-time-optimizations.tsx), absolutely zero conversion code is sent to clients
- Runs anywhere (browsers, Node, Bun, etc.)
- Tiny bundle size and 0 dependencies
- Supports bigints

## Usage

Generated API documentation for the latest version is available online.

[**View docs**](https://convert.js.org).

```ts
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");
```

### Converting many units

```ts
import { convertMany } from "convert";

// Convert 1 day and 8 hours into ms
convertMany("1d8h").to("ms");
```

### Converting to best unit

```ts
import convert from "convert";

// Convert into the best unit
const duration = convert(36, "h").to("best");
// -> { quantity: 1.5, unit: 'd', toString: () => '1.5 d' }

// The toString() method means you can automatically cast the object to a string without any issues
"duration is " + duration;
// -> duration is 1.5d

// You can also specify to use a specific kind of units (metric or imperial, metric is default)
convert(3.5, "km").to("best"); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5 km' }
convert(3.5, "km").to("best", "metric"); // -> { quantity: 3.5, unit: 'km', toString: () => '3.5 km' }
convert(3.5, "km").to("best", "imperial"); // -> { quantity: 2.17, unit: 'mi', toString: () => '3.5 mi' }
```

### `ms` shorthand

```ts
import { ms } from "convert";

// Convert a duration into milliseconds
ms("1d 2h 30min");
// -> 95400000

// Convert milliseconds to a string
ms(86400000);
// -> '1d'
```

## Installation

Convert is published as `convert` on npm.

```sh
npm install convert
```

And then import it in your code like this:

```js
import convert from "convert";
```

## 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](https://github.com/jonahsnider/js-unit-conversion-benchmarks).

Convert is the fastest, taking less than a microsecond for all functions.
That's a little over 3 million `convert()` calls per second.

### Bundle size comparison

[![npm bundle size of convert](https://img.shields.io/bundlephobia/minzip/convert?label=convert)](https://bundlephobia.com/result?p=convert)

[![npm bundle size of safe-units](https://img.shields.io/bundlephobia/minzip/safe-units?label=safe-units)](https://bundlephobia.com/result?p=safe-units)

[![npm bundle size of convert-units](https://img.shields.io/bundlephobia/minzip/convert-units?label=convert-units)](https://bundlephobia.com/result?p=convert-units)

[![npm bundle size of js-quantities](https://img.shields.io/bundlephobia/minzip/js-quantities?label=js-quantities)](https://bundlephobia.com/result?p=js-quantities)

[![npm bundle size of uom](https://img.shields.io/bundlephobia/minzip/uom?label=uom)](https://bundlephobia.com/result?p=uom)
![+](https://img.shields.io/badge/%2B-gray)
[![npm bundle size of uom-units](https://img.shields.io/bundlephobia/minzip/uom-units?label=uom-units)](https://bundlephobia.com/result?p=uom-units)

---
_Source: https://npm.io/package/convert · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
