Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

convert

> 编程语言
Open source

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

197 stars0 likes1 views
WebsiteGitHub

About

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

Convert

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

bash
npm install convert

More installation examples below.

javascript
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, 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.

typescript
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

typescript
import { convertMany } from "convert";

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

Converting to best unit

…

ms shorthand

typescript
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.

bash
npm install convert

And then import it in your code like this:

javascript
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.

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

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptconversionconversionsconvertconvert-units

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言