Toolbox-XToolbox-X

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)
ParameterTypeDescription
valuenumberNumeric value to convert.
unitUnitKey (optional)Unit type (e.g., 'kg', 'm', 'kb').

Example

playground.ts

Sub-pages

Explore the conversion methods by category:

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)

On this page