Unit
A comprehensive unit conversion utility supporting conversions between various measurement systems including length, mass, temperature, volume, area, speed, time, digital storage, power, energy, pressure, and frequency.
The Unit class is a comprehensive unit conversion utility that supports conversions between various measurement systems.
Constructor
constructor(value: number, unit?: UnitKey)| Parameter | Type | Description |
|---|---|---|
value | number | Numeric value to convert. |
unit | UnitKey (optional) | Unit type (e.g., 'kg', 'm', 'kb'). |
Example
playground.ts
Sub-pages
Explore the conversion methods by category:
- Instance Methods —
toString(),convertByPrefix(),convertFromTo(),convert() - Length Conversions — meters, feet, km, miles, cm, mm
- Mass & Weight Conversions — kg, lbs, grams, ounces
- Temperature Conversions — Celsius, Fahrenheit, Kelvin
- Volume Conversions — ml, liters, gallons
- Area Conversions — sq. meters, sq. feet, sq. km, sq. inches
- Speed Conversions — km/h, mph
- Time Conversions — seconds, minutes, hours, days
- Digital Storage Conversions — bytes, KB, MB, GB, TB
- Power Conversions — watts, kilowatts
- Energy Conversions — joules, calories, kilojoules
- Pressure Conversions — atm, pascal, bar
- Frequency Conversions — Hz, kHz, MHz
Type Definitions
UnitKey
type UnitKey = keyof typeof UNITS;Supported unit abbreviations (e.g., 'kg', 'm', 'F').
UnitLabel
type UnitLabel = (typeof UNITS)[UnitKey];Full names of units (e.g., 'Kilogram', 'Meter').
SIPrefix
type SIPrefix = keyof typeof PREFIX_MULTIPLIERS;Scientific prefixes (e.g., 'k', 'm', 'M').
UnitNumberMethods
type UnitNumberMethods = {
[K in keyof typeof Unit]: (typeof Unit)[K] extends (
(value: number) => number
) ? K : never;
}[keyof typeof Unit];Type-safe names of static conversion methods.
Last updated: Sun, Jun 14, 2026 08:22:19PM (UTC)
