百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

convert

> 编程语言
开源

TypeScript 和 JavaScript 中最小、最快的库,可实现非常简单、完全类型安全的单位转换。

197 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptconversionconversionsconvertconvert-units

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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