Skip to content

Typings — Number

Package: @litert/utils-numberSource: packages/partials/number/src/Classes/UnitConverter.ts


Import

ts
import type { Units } from '@litert/utils-number';

IUnit<T>

Describes a single unit with a name and a conversion factor relative to the base unit of a UnitConverter.

ts
interface IUnit<T extends string | number> {
    name: T;
    factor: number;
}
PropertyTypeDescription
nameTThe name or symbol of the unit (e.g., 'km', 'gb')
factornumberConversion factor relative to the base unit — how many base units equal 1 of this unit

IUnitConverterOptions<T>

Constructor options for UnitConverter<T>.

ts
interface IUnitConverterOptions<T extends string | number> {
    baseUnit: T;
    units: Array<IUnit<T>>;
}
PropertyTypeDescription
baseUnitTThe reference unit; all other unit factors are relative to this
unitsArray<IUnit<T>>Derived units, each with an absolute factor relative to baseUnit. Use UnitConverter.makeUnitsByFactor to generate geometric series