npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

all-units

v1.0.3

Published

Universal unit converter — 13 categories, 100+ units. Zero dependencies. TypeScript-first.

Downloads

188

Readme

all-units

Universal unit converter — 13 categories, 100+ units. Zero dependencies. TypeScript-first.

npm license build

Features

  • 13 categories: length, mass, temperature, area, volume, time, speed, pressure, energy, power, digital storage, angle, frequency
  • 100+ units with precise conversion factors
  • Fluent API: convert(100).from('cm').to('m') — readable and chainable
  • Direct API: convert(100, 'cm', 'm') — compact one-liner
  • Full TypeScript types with IDE autocomplete for all unit names
  • Throws a clear error when units are incompatible (different categories)
  • Zero runtime dependencies
  • Works in Node.js, Deno, Bun, and modern browsers
  • ESM + CommonJS dual build

Install

npm install all-units
# or
pnpm add all-units
# or
yarn add all-units

Usage

import { convert } from 'all-units'

// Fluent API (recommended)
convert(100).from('cm').to('m')          // 1
convert(1).from('km').to('mi')           // 0.621371
convert(0).from('C').to('F')             // 32
convert(100).from('C').to('F')           // 212
convert(1).from('kg').to('lb')           // 2.204623
convert(1).from('kWh').to('J')           // 3600000
convert(1).from('GB').to('MB')           // 1000   (SI)
convert(1).from('GiB').to('MiB')         // 1024   (IEC)
convert(180).from('deg').to('rad')       // 3.14159 (π)
convert(1).from('atm').to('bar')         // 1.01325

// Direct API
convert(1000, 'm', 'km')                 // 1
convert(32, 'F', 'C')                    // 0

CommonJS (require) is also supported:

const { convert } = require('all-units')

convert(1, 'mi', 'km')  // 1.609344

API

convert(value, from, to)

Direct style — pass value, source unit and target unit in one call.

convert(value: number, from: Unit, to: Unit): number

convert(value).from(unit).to(unit)

Fluent style — build the conversion step by step.

convert(value: number): FromStep
// .from(unit).to(unit) → number

Both styles throw Error if:

  • A unit string is unknown
  • The two units belong to different categories (e.g. 'cm''kg')

canConvert(from, to)

Returns true if the two units are in the same category.

canConvert('cm', 'm')    // true
canConvert('cm', 'kg')   // false
canConvert('xyz', 'm')   // false

getCategory(unit)

Returns the category name of a unit, or undefined if unknown.

getCategory('km')    // 'length'
getCategory('C')     // 'temperature'
getCategory('GiB')   // 'digital'

possibilities(unit)

Returns all units that are compatible with the given unit (same category). Useful for populating UI dropdowns.

possibilities('km')  // ['um', 'mm', 'cm', 'm', 'km', 'in', 'ft', 'yd', 'mi', 'nmi']
possibilities('C')   // ['C', 'F', 'K', 'R']
possibilities('GB')  // ['bit', 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']

listUnits()

Returns all units grouped by category, or just the list for one category.

listUnits()            // { length: ['mm', 'cm', 'm', ...], temperature: [...], ... }
listUnits('length')    // ['um', 'mm', 'cm', 'm', 'km', 'in', 'ft', 'yd', 'mi', 'nmi']

Supported units

Length

| Unit | Name | |---|---| | um | Micrometre | | mm | Millimetre | | cm | Centimetre | | m | Metre | | km | Kilometre | | in | Inch | | ft | Foot | | yd | Yard | | mi | Mile | | nmi | Nautical mile |

Mass

| Unit | Name | |---|---| | mg | Milligram | | g | Gram | | kg | Kilogram | | t | Metric ton | | oz | Ounce | | lb | Pound | | st | Stone |

Temperature

| Unit | Name | |---|---| | C | Celsius | | F | Fahrenheit | | K | Kelvin | | R | Rankine |

Area

mm2 cm2 m2 km2 in2 ft2 yd2 mi2 ha (hectare) ac (acre)

Volume

ml cl dl l m3 tsp tbsp fl_oz cup pt qt gal (US) uk_gal (UK)

Time

ms s min h d wk mo yr

Speed

m/s km/h mph knot ft/s

Pressure

Pa kPa MPa bar atm psi mmHg inHg

Energy

J kJ cal kcal Wh kWh BTU eV

Power

W kW MW GW hp

Digital storage

| Unit | Standard | Size | |---|---|---| | bit | — | 1 bit | | B | — | 1 byte | | KB MB GB TB PB | SI (powers of 10) | 10³ … 10¹⁵ bytes | | KiB MiB GiB TiB PiB | IEC (powers of 2) | 2¹⁰ … 2⁵⁰ bytes |

Angle

deg (degree) rad (radian) grad (gradian)

Frequency

Hz kHz MHz GHz

Development

git clone https://github.com/MaxGrushevsky/unit-convert.git
cd unit-convert
npm install

npm run build         # compile to dist/
npm test              # run tests once
npm run test:watch    # run tests in watch mode
npm run typecheck     # TypeScript type-check only

License

MIT