Lightweight, zero-dependency unit conversion utility designed for modern JavaScript and TypeScript workflows.
Get started in seconds using your preferred package manager.
npm install universal-unitimport { convertUnit } from 'universal-unit'
const result = convertUnit({
value: 5,
from: 'km',
to: 'm',
category: 'length',
})
console.log(result) // 5000Available units
nm, um, mm, cm, dm, m, km, in, ft, yd, mile, nmi
Available units
mcg, mg, g, kg, ton, oz, lb, st
Available units
sq_m, sq_km, sq_cm, sq_mm, hectare, acre, sq_mi, sq_yd, sq_ft, sq_in
Available units
m3, liter, ml, cm3, in3, ft3, gallon, quart, pint, cup, floz
Available units
byte, kb, mb, gb, tb, pb
Available units
m/s, km/h, mph, knot, ft/s
Available units
second, minute, hour, day, week, year
Available units
pa, kpa, bar, psi, atm, torr
Available units
USD, EUR, GBP, INR, JPY, CNY, AUD, CAD, CHF, NZD, SGD, HKD, KRW
Specifications for core conversion parameters
Primary synchronous conversion executor.
convertUnit({ value, from, to, category })| Parameter | Type | Description |
|---|---|---|
| value | number | Numeric value to convert |
| from | string | Source unit alias or identifier |
| to | string | Target unit alias or identifier |
| category | string | Target conversion category namespace |
convertUnit({ value: 5, from: 'km', to: 'm', category: 'length' })convertUnit({ value: 5, from: 'kg', to: 'g', category: 'weight' })convertUnit({ value: 100, from: 'sq_m', to: 'sq_ft', category: 'area' })convertUnit({ value: 1, from: 'gb', to: 'mb', category: 'data' })convertUnit({ value: 2, from: 'hour', to: 'second', category: 'time' })convertUnit({ value: 10, from: 'm/s', to: 'km/h', category: 'speed' })convertUnit({ value: 1, from: 'bar', to: 'psi', category: 'pressure' })convertUnit({ value: 1, from: 'gallon', to: 'liter', category: 'volume' })Query and calculate real-time live currency exchange rates.
import { convertCurrency } from 'universal-unit'
const result = await convertCurrency(100, 'USD', 'INR')
console.log(result)Core architectural highlights
Zero Dependencies
Lightweight & Fast
TypeScript Ready
Input Validation
Multiple Aliases
One Unified API
Live Currency Rates
Auto Caching
Deterministic exception management for invalid arguments
convertUnit({
value: 10,
from: 'km',
to: 'm',
category: 'invalid'
})convertUnit({
value: 10,
from: 'invalid',
to: 'm',
category: 'length'
})