Options
All
  • Public
  • Public/Protected
  • All
Menu

iamsquare/convert-units

NPM Coverage GitHub issues npm bundle size (scoped) GitHub

A handy utility for converting between quantities in different units.

Installation

npm i @iamsquare/convert-units

Usage

@iamsquare/convert-units is a functional port of convert-units with extended type support.

You start by instancing a Converter:

import { Converter } from '@iamsquare/convert-units';

const converter = new Converter({ measuresData: { ... }});

If you want to use all measure types, just instance Converter like so:

import { allMeasures } from '@iamsquare/convert-units';

const converter = new Converter({ measuresData: allMeasures }); // TMeasures => AllMeasures, TSystems => AllSystems, TUnitTypes => AllUnitType

If you want to use a subset of all measure type you must declare TMeasures, TSystems and TUnitTypes explicitly (typescript can't infer types on its own if they get too complex. e.g.: two measure types with different systems):

import {
  Converter,
  area,
  AreaSystems,
  AreaUnits,
  distance,
  DistanceSystems,
  DistanceUnits,
} from '@iamsquare/convert-units';

type Measures = 'area' | 'distance';
type Systems = AreaSystems | DistanceSystems;
type Units = AreaUnits | DistanceUnits;

const converter = new Converter<Measures, Systems, Units>({
  area,
  distance
});

Here's how you convert metric units for volume:

import { convert } from '@iamsquare/convert-units';

convert(converter, 'l', 'ml', 1);
// 1000

Jump from imperial to metric units the same way:

convert(converter, 'lb', 'kg', 1);
// 0.4536... (tested to 4 significant figures)

Just be careful not to ask for an impossible conversion!

convert(converter, 'oz', 'fl-oz', 1);
// throws exception -- you can't go from mass to volume!

You can ask to select the best unit for you. Optionally you can explicitly exclude orders of magnitude or specify a cutoff number for selecting the best representation.

convertToBest(converter, {}, 'mm', 12000);
// { value: 12, unitType: 'm' } (the smallest unit with a value above 1)

convertToBest(converter, { exclude: ['m'] }, 'mm', 12000);
// { value: 1200, unitType: 'cm' } (the smallest unit excluding meters)

convertToBest(converter, { cutOffNumber: 10 }, 'mm', 900);
// { value: 900, unitType: 'cm' } (the smallest unit with a value equal to or above 10)

convertToBest(converter, { cutOffNumber: 10 }, 'mm', 1000);
// { value: 10, unitType: 'm' } (the smallest unit with a value equal to or above 10)

You can get a list of the measurement types supported with measures

measures(converter);
// [ 'distance', 'mass', 'volume', ... ]

If you ever want to know the possible conversions for a unit, just use possibilities

import { possibilities } = from '@iamsquare/convert-units';

possibilities(converter, 'l');
// [ 'ml', 'l', 'tsp', 'Tbs', 'fl-oz', 'cup', 'pnt', 'qt', 'gal' ]

possibilities(converter, 'kg');
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb' ]

You can also get the possible conversions for a measure:

possibilities(converter, 'mass');
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb', 'mt', 't' ]

You can also get the all the available units:

possibilities(converter);
// [ 'mm', 'cm', 'm', 'in', 'ft-us', 'ft', 'mi', ... ];

To get a detailed description of a unit, use describe

describe(converter, 'kg');
{
  unitType: 'kg',
  measure: 'mass',
  system: 'metric',
  name: {
    singular: 'SINGULAR_KILOGRAM',
    plural: 'PLURAL_KILOGRAM'
  }
}

To get detailed descriptions of all units, use list.

list(converter);
[
  {
    unitType: 'kg',
    measure: 'mass',
    system: 'metric',
    name: {
      singular: 'SINGULAR_KILOGRAM',
      plural: 'PLURAL_KILOGRAM'
    }
  },
  ...
]

You can also get detailed description of all units for a measure:

list(converter, 'mass');
[
  {
    unitType: 'kg',
    measure: 'mass',
    system: 'metric',
    name: {
      singular: 'SINGULAR_KILOGRAM',
      plural: 'PLURAL_KILOGRAM'
    }
  },
  ...
]

NOTE: By default the i18n module is not active so until a translation dictionary is provided list and describe will return the raw dictionary key instead.

Documentation

For a more in-depth documentation take a look here

Supported Units

Measure Metric Imperial Other
Area mm2, cm2, m2, ha, km2 in2, ft2, ac, mi2 -
Acceleration g-force, m/s2 - -
Angle - - deg, rad, grad, arcmin, arcsec
Apparent Power - - VA, mVA, kVA, MVA, GVA
Charge - - c, mC, μC, nC, pC
Current - - A, mA, kA
Digital - - b, Kb, Mb, Gb, Tb, B, KB, MB, GB, TB
Energy - - Wh, mWh, kWh, MWh, GWh, J, kJ
Force N, kN lbf -
Frequency - - Hz, mHz, kHz, MHz, GHz, THz, rpm, deg/s, rad/s
Illuminance lx ft-cd -
Length nm, μm, mm, cm, m, km in, yd, ft-us, ft, fathom, mi, nMi -
Mass mcg, mg, g, kg, mt oz, lb, t -
Pace s/m, min/km s/ft, min/mi -
Parts-Per - - ppm, ppb, ppt, ppq
Pieces - - pcs, bk-doz, cp, doz-doz, doz, gr-gr, gros, half-dozen, long-hundred, ream, scores, sm-gr, trio
Power W, mW, kW, MW, GW, PS Btu/s, ft-lb/s, hp -
Pressure Pa, hPa, kPa, MPa, bar, torr psi, ksi -
Reactive Energy - - VARh, mVARh, kVARh, MVARh, GVARh
Reactive Power - - VAR, mVAR, kVAR, MVAR, GVAR
Speed m/s, km/h mph, knot, ft/s -
Temperature C, K F, R -
Time - - ns, mu, ms, s, min, h, d, week, month, year
Voltage - - V, mV, kV
Volume mm3, cm3, ml, l, kl, m3, km3 tsp, Tbs, in3, fl-oz, cup, pnt, qt, gal, ft3, yd3 -
Volume Flow Rate mm3/s, cm3/s, ml/s, cl/s, dl/s, l/s, l/min, l/h, kl/s, kl/min, kl/h, m3/s, m3/min, m3/h, km3/s tsp/s, Tbs/s, in3/s, in3/min, in3/h, fl-oz/s, fl-oz/min, fl-oz/h, cup/s, pnt/s, pnt/min, pnt/h, qt/s, gal/s, gal/min, gal/h, ft3/s, ft3/min, ft3/h, yd3/s, yd3/min, yd3/h -

NOTE: these units are exported as enums so that you don't have to remember which unit is which. Also, if you're using this library in a plain javascript environment these are useful to avoid annoying typos.

You can check the list of these enums in the documentation.

Want More?

Adding new measurement types is easy. Check one of these definitions or unit tests to see how they are implemented. When you're done you can import them just like any other measure provided by the library:

import {
  Converter,
  distance,
  DistanceSystems,
  DistanceUnits,
} from '@iamsquare/convert-units';

import {
  customMeasure,
  CustomMeasureSystems,
  CustomUnits
} from './customMeasure';

type Measures = 'customMeasure' | 'distance';
type Systems = CustomMeasureSystems | DistanceSystems;
type Units = CustomUnits | DistanceUnits;

const converter = new Converter<Measures, Systems, Units>({
  customMeasure,
  distance
});

Feel free to open a PR if you think that your custom definition should be added to the library!

i18n

Each Converter instance can be initialized with an additional translations property. For example if you want to use all the measure types and their respective translations, just instance Converter like so:

import { Converter, allMeasures, allTranslations } from '@iamsquare/convert-units';

const converter = new Converter({ measureData: allMeasures, translations: allTranslations });

Or if you only need a subset of measures:

import {
  Converter,
  area,
  areaTranslations,
  AreaSystems,
  AreaUnits,
  distance,
  distanceTranslations,
  DistanceSystems,
  DistanceUnits
} from '@iamsquare/convert-units';

type Measures = 'area' | 'distance';
type Systems = AreaSystems | DistanceSystems;
type Units = AreaUnits | DistanceUnits;

const converter = new Converter<Measures, Systems, Units>({ measureData: { area, distance }, translations: { ...areaTranslations, ...distanceTranslations }});

The translationModule inside the Converter class exposes three methods:

converter.translationModule.setTranslations({ ... })
converter.translationModule.mergeTranslations({ ... })

Both accept a JSON containing key-value pairs, where the key is a valid translationKey and the value is a string. The first one overwrites the current translations dictionary, the second merges the two dictionaries together.

converter.translationModule.resetTranslations();

Resets the translations dictionary to its original state (when the class has been instanced).

converter.translationModule.getTranslationByKey(key);

Returns the translation for a given key (or the key itself in case it's undefined in the dictionary).

Dependencies

This library depends on ramda and ramda-extension.

These imports are not tree-shaken, so if you're bundling this library in a project please refer to your bundler's documentation. Note that Rollup and Webpack should handle tree-shaking without extra-effort.

Roadmap

Check the kanban board here

Development

If you want to help remember to run the command npm run setup:dev. It will install all dependencies and husky so that code will get tested and linted before every commit.

License

Copyright (c) 2021 Marco Cesi, https://iamsquare.it

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Enumerations

Classes

Interfaces

Type aliases

Properties

Variables

Functions

Type aliases

AccelerationPluralTranslationKey

AccelerationPluralTranslationKey: "PLURAL_G0" | "PLURAL_G_SUN" | "PLURAL_G_MERCURY" | "PLURAL_G_VENUS" | "PLURAL_G_MARS" | "PLURAL_G_SATURN" | "PLURAL_G_JUPITER" | "PLURAL_G_NEPTUNE" | "PLURAL_G_PLUTO" | "PLURAL_G_MOON" | "PLURAL_METRE_PER_SECOND_SQUARED"

AccelerationSingularTranslationKey

AccelerationSingularTranslationKey: "SINGULAR_G0" | "SINGULAR_G_SUN" | "SINGULAR_G_MERCURY" | "SINGULAR_G_VENUS" | "SINGULAR_G_MARS" | "SINGULAR_G_SATURN" | "SINGULAR_G_JUPITER" | "SINGULAR_G_NEPTUNE" | "SINGULAR_G_PLUTO" | "SINGULAR_G_MOON" | "SINGULAR_METRE_PER_SECOND_SQUARED"

AccelerationSystems

AccelerationSystems: "metric"

AccelerationUnit

AccelerationUnit: "g0" | "m/s2" | "g-sun" | "g-mercury" | "g-venus" | "g-mars" | "g-saturn" | "g-jupiter" | "g-neptune" | "g-pluto" | "g-moon"

AllMeasure

AllMeasure: "acceleration" | "angle" | "apparentPower" | "area" | "charge" | "current" | "frequency" | "digital" | "distance" | "force" | "each" | "energy" | "illuminance" | "mass" | "pace" | "partsPer" | "pieces" | "power" | "pressure" | "reactiveEnergy" | "reactivePower" | "speed" | "temperature" | "time" | "voltage" | "volume" | "volumeFlowRate"

AllSystem

AllSystem: "metric" | "imperial" | "swedish" | "bits" | "bytes" | "other"

AllTranslations

AllTranslations: Record<TranslationKey, string>

AllUnitType

Anchor

Anchor<S, U>: GenericAnchor<S, U>

Type parameters

AnchorPartialRecord

AnchorPartialRecord<S, U>: {[ P in S]: GenericAnchor<Exclude<S, P>, U> }

Type parameters

AnglePluralTranslationKey

AnglePluralTranslationKey: "PLURAL_RADIANS" | "PLURAL_DEGREES" | "PLURAL_GRADIANS" | "PLURAL_ARCMINUTES" | "PLURAL_ARCSECONDS"

AngleSingularTranslationKey

AngleSingularTranslationKey: "SINGULAR_RADIANS" | "SINGULAR_DEGREES" | "SINGULAR_GRADIANS" | "SINGULAR_ARCMINUTES" | "SINGULAR_ARCSECONDS"

AngleSystems

AngleSystems: "metric"

AngleUnit

AngleUnit: "deg" | "rad" | "grad" | "arcmin" | "arcsec"

ApparentPowerPluralTranslationKey

ApparentPowerPluralTranslationKey: "PLURAL_VOLT_AMPERE" | "PLURAL_MILLIVOLT_AMPERE" | "PLURAL_KILOVOLT_AMPERE" | "PLURAL_MEGAVOLT_AMPERE" | "PLURAL_GIGAVOLT_AMPERE"

ApparentPowerSingularTranslationKey

ApparentPowerSingularTranslationKey: "SINGULAR_VOLT_AMPERE" | "SINGULAR_MILLIVOLT_AMPERE" | "SINGULAR_KILOVOLT_AMPERE" | "SINGULAR_MEGAVOLT_AMPERE" | "SINGULAR_GIGAVOLT_AMPERE"

ApparentPowerSystems

ApparentPowerSystems: "metric"

ApparentPowerUnit

ApparentPowerUnit: "VA" | "mVA" | "kVA" | "MVA" | "GVA"

AreaPluralTranslationKey

AreaPluralTranslationKey: "PLURAL_SQUARE_MILLIMETER" | "PLURAL_SQUARE_CENTIMETER" | "PLURAL_SQUARE_METER" | "PLURAL_SQUARE_KILOMETER" | "PLURAL_HECTARE" | "PLURAL_SQUARE_INCH" | "PLURAL_SQUARE_YARD" | "PLURAL_SQUARE_FOOT" | "PLURAL_SQUARE_MILE" | "PLURAL_ACRE"

AreaSingularTranslationKey

AreaSingularTranslationKey: "SINGULAR_SQUARE_MILLIMETER" | "SINGULAR_SQUARE_CENTIMETER" | "SINGULAR_SQUARE_METER" | "SINGULAR_SQUARE_KILOMETER" | "SINGULAR_HECTARE" | "SINGULAR_SQUARE_INCH" | "SINGULAR_SQUARE_YARD" | "SINGULAR_SQUARE_FOOT" | "SINGULAR_SQUARE_MILE" | "SINGULAR_ACRE"

AreaSystems

AreaSystems: "metric" | "imperial"

AreaUnit

BestConversion

BestConversion<TUnitType>: { unitType: TUnitType; value: number }

Type parameters

  • TUnitType: string

Type declaration

  • unitType: TUnitType
  • value: number

BitDigitalUnit

BitDigitalUnit: "b" | "kb" | "Mb" | "Gb" | "Tb" | "Pb" | "kib" | "Mib" | "Gib" | "Tib" | "Pib"

ByteDigitalUnit

ByteDigitalUnit: "B" | "kB" | "MB" | "GB" | "TB" | "PB" | "kiB" | "MiB" | "GiB" | "TiB" | "PiB"

CamelToPascalCase

CamelToPascalCase<S>: S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? "_" : ""}${Uppercase<T>}${CamelToPascalCase<U>}` : S

Type parameters

  • S: string

ChargePluralTranslationKey

ChargePluralTranslationKey: "PLURAL_COULOMB" | "PLURAL_MILLICOULOMB" | "PLURAL_MICROCOULOMB" | "PLURAL_NANOCOULOMB" | "PLURAL_PICOCOULOMB"

ChargeSingularTranslationKey

ChargeSingularTranslationKey: "SINGULAR_COULOMB" | "SINGULAR_MILLICOULOMB" | "SINGULAR_MICROCOULOMB" | "SINGULAR_NANOCOULOMB" | "SINGULAR_PICOCOULOMB"

ChargeSystems

ChargeSystems: "metric"

ChargeUnit

ChargeUnit: "c" | "mC" | "μC" | "nC" | "pC"

Conversion

Conversion<TMeasures, TSystems, TUnitType>: { measure: TMeasures; system: TSystems; unit: Unit; unitType: TUnitType }

Type parameters

  • TMeasures: string

  • TSystems: string

  • TUnitType: string

Type declaration

  • measure: TMeasures
  • system: TSystems
  • unit: Unit
  • unitType: TUnitType

ConvertToBestDto

ConvertToBestDto<TUnitType>: { cutoff: number; exclude: TUnitType[] }

Type parameters

  • TUnitType: string

Type declaration

  • cutoff: number
  • exclude: TUnitType[]

ConverterOptions

ConverterOptions<TMeasures, TSystems, TUnitType, TTranslationKeys>: { measuresData: MeasureDictionary<TMeasures, TSystems, TUnitType>; translations?: Translations<TTranslationKeys> }

Type parameters

  • TMeasures: string

  • TSystems: string

  • TUnitType: string

  • TTranslationKeys: string

Type declaration

CurrentPluralTranslationKey

CurrentPluralTranslationKey: "PLURAL_AMPERE" | "PLURAL_MILLIAMPERE" | "PLURAL_KILOAMPERE"

CurrentSingularTranslationKey

CurrentSingularTranslationKey: "SINGULAR_AMPERE" | "SINGULAR_MILLIAMPERE" | "SINGULAR_KILOAMPERE"

CurrentSystems

CurrentSystems: "metric"

CurrentUnit

CurrentUnit: "A" | "mA" | "kA"

DigitalPluralTranslationKey

DigitalPluralTranslationKey: "PLURAL_BIT" | "PLURAL_KILOBIT" | "PLURAL_MEGABIT" | "PLURAL_GIGABIT" | "PLURAL_TERABIT" | "PLURAL_PETABIT" | "PLURAL_KIBIBIT" | "PLURAL_MEBIBIT" | "PLURAL_GIBIBIT" | "PLURAL_TEBIBIT" | "PLURAL_PEBIBIT" | "PLURAL_BYTE" | "PLURAL_KILOBYTE" | "PLURAL_MEGABYTE" | "PLURAL_GIGABYTE" | "PLURAL_TERABYTE" | "PLURAL_PETABYTE" | "PLURAL_KIBIBYTE" | "PLURAL_MEBIBYTE" | "PLURAL_GIBIBYTE" | "PLURAL_TEBIBYTE" | "PLURAL_PEBIBYTE"

DigitalSingularTranslationKey

DigitalSingularTranslationKey: "SINGULAR_BIT" | "SINGULAR_KILOBIT" | "SINGULAR_MEGABIT" | "SINGULAR_GIGABIT" | "SINGULAR_TERABIT" | "SINGULAR_PETABIT" | "SINGULAR_KIBIBIT" | "SINGULAR_MEBIBIT" | "SINGULAR_GIBIBIT" | "SINGULAR_TEBIBIT" | "SINGULAR_PEBIBIT" | "SINGULAR_BYTE" | "SINGULAR_KILOBYTE" | "SINGULAR_MEGABYTE" | "SINGULAR_GIGABYTE" | "SINGULAR_TERABYTE" | "SINGULAR_PETABYTE" | "SINGULAR_KIBIBYTE" | "SINGULAR_MEBIBYTE" | "SINGULAR_GIBIBYTE" | "SINGULAR_TEBIBYTE" | "SINGULAR_PEBIBYTE"

DigitalSystems

DigitalSystems: "bits" | "bytes"

DigitalUnit

DistancePluralTranslationKey

DistancePluralTranslationKey: "PLURAL_NANOMETER" | "PLURAL_MICROMETER" | "PLURAL_MILLIMETER" | "PLURAL_CENTIMETER" | "PLURAL_METER" | "PLURAL_KILOMETER" | "PLURAL_INCH" | "PLURAL_YARD" | "PLURAL_US_SURVEY_FOOT" | "PLURAL_FOOT" | "PLURAL_FATHOM" | "PLURAL_MILE" | "PLURAL_NAUTICAL_MILE"

DistanceSingularTranslationKey

DistanceSingularTranslationKey: "SINGULAR_NANOMETER" | "SINGULAR_MICROMETER" | "SINGULAR_MILLIMETER" | "SINGULAR_CENTIMETER" | "SINGULAR_METER" | "SINGULAR_KILOMETER" | "SINGULAR_INCH" | "SINGULAR_YARD" | "SINGULAR_US_SURVEY_FOOT" | "SINGULAR_FOOT" | "SINGULAR_FATHOM" | "SINGULAR_MILE" | "SINGULAR_NAUTICAL_MILE"

DistanceSystems

DistanceSystems: "metric" | "imperial"

DistanceUnit

EachPluralTranslationKey

EachPluralTranslationKey: "PLURAL_EACH" | "PLURAL_DOZEN"

EachSingularTranslationKey

EachSingularTranslationKey: "SINGULAR_EACH" | "SINGULAR_DOZEN"

EachSystems

EachSystems: "other"

EachUnit

EachUnit: "ea" | "dz"

EnergyPluralTranslationKey

EnergyPluralTranslationKey: "PLURAL_WATT_HOUR" | "PLURAL_MILLIWATT_HOUR" | "PLURAL_KILOWATT_HOUR" | "PLURAL_MEGAWATT_HOUR" | "PLURAL_GIGAWATT_HOUR" | "PLURAL_JOULE" | "PLURAL_KILOJOULE"

EnergySingularTranslationKey

EnergySingularTranslationKey: "SINGULAR_WATT_HOUR" | "SINGULAR_MILLIWATT_HOUR" | "SINGULAR_KILOWATT_HOUR" | "SINGULAR_MEGAWATT_HOUR" | "SINGULAR_GIGAWATT_HOUR" | "SINGULAR_JOULE" | "SINGULAR_KILOJOULE"

EnergySystems

EnergySystems: "metric"

EnergyUnit

EnergyUnit: "Wh" | "mWh" | "kWh" | "MWh" | "GWh" | "J" | "kJ"

ExtractedSystem

ExtractedSystem<E>: Extract<AllSystem, E>

Type parameters

ForcePluralTranslationKey

ForcePluralTranslationKey: "PLURAL_NEWTON" | "PLURAL_KILONEWTON" | "PLURAL_POUND_FORCE"

ForceSingularTranslationKey

ForceSingularTranslationKey: "SINGULAR_NEWTON" | "SINGULAR_KILONEWTON" | "SINGULAR_POUND_FORCE"

ForceSystems

ForceSystems: "metric" | "imperial"

ForceUnit

FrequencyPluralTranslationKey

FrequencyPluralTranslationKey: "PLURAL_HERTZ" | "PLURAL_MILLIHERTZ" | "PLURAL_KILOHERTZ" | "PLURAL_MEGAHERTZ" | "PLURAL_GIGAHERTZ" | "PLURAL_TERAHERTZ" | "PLURAL_RPM" | "PLURAL_DEGREE_PER_SECOND" | "PLURAL_RADIAN_PER_SECOND"

FrequencySingularTranslationKey

FrequencySingularTranslationKey: "SINGULAR_HERTZ" | "SINGULAR_MILLIHERTZ" | "SINGULAR_KILOHERTZ" | "SINGULAR_MEGAHERTZ" | "SINGULAR_GIGAHERTZ" | "SINGULAR_TERAHERTZ" | "SINGULAR_RPM" | "SINGULAR_DEGREE_PER_SECOND" | "SINGULAR_RADIAN_PER_SECOND"

FrequencySystems

FrequencySystems: "metric"

FrequencyUnit

FrequencyUnit: "Hz" | "mHz" | "kHz" | "MHz" | "GHz" | "THz" | "rpm" | "deg/s" | "rad/s"

IlluminancePluralTranslationKey

IlluminancePluralTranslationKey: "PLURAL_LUX" | "PLURAL_FOOT_CANDLE"

IlluminanceSingularTranslationKey

IlluminanceSingularTranslationKey: "SINGULAR_LUX" | "SINGULAR_FOOT_CANDLE"

IlluminanceSystems

IlluminanceSystems: "metric" | "imperial"

IlluminanceUnit

ImperialAreaUnit

ImperialAreaUnit: "in2" | "yd2" | "ft2" | "ac" | "mi2"

ImperialDistanceUnit

ImperialDistanceUnit: "in" | "yd" | "ft-us" | "ft" | "mi" | "nMi" | "fathom"

ImperialForceUnit

ImperialForceUnit: "lbf"

ImperialIlluminanceUnit

ImperialIlluminanceUnit: "ft-cd"

ImperialMassUnit

ImperialMassUnit: "oz" | "lb" | "t"

ImperialPaceUnit

ImperialPaceUnit: "s/ft" | "min/mi"

ImperialPowerUnit

ImperialPowerUnit: "Btu/s" | "ft-lb/s" | "hp"

ImperialPressureUnit

ImperialPressureUnit: "psi" | "ksi" | "inHg"

ImperialSpeedUnit

ImperialSpeedUnit: "knot" | "ft/s" | "mph"

ImperialTemperatureUnit

ImperialTemperatureUnit: "F" | "R"

ImperialVolumeFlowRateUnit

ImperialVolumeFlowRateUnit: "tsp/s" | "Tbs/s" | "in3/s" | "in3/min" | "in3/h" | "fl-oz/s" | "fl-oz/min" | "fl-oz/h" | "cup/s" | "pnt/s" | "pnt/min" | "pnt/h" | "qt/s" | "gal/s" | "gal/min" | "gal/h" | "ft3/s" | "ft3/min" | "ft3/h" | "yd3/s" | "yd3/min" | "yd3/h"

ImperialVolumeUnit

ImperialVolumeUnit: "tsp" | "Tbs" | "in3" | "fl-oz" | "cup" | "pnt" | "qt" | "gal" | "ft3" | "yd3"

MassPluralTranslationKey

MassPluralTranslationKey: "PLURAL_GRAM" | "PLURAL_MICROGRAM" | "PLURAL_MILLIGRAM" | "PLURAL_KILOGRAM" | "PLURAL_METRIC_TONNE" | "PLURAL_OUNCE" | "PLURAL_POUND" | "PLURAL_TON"

MassSingularTranslationKey

MassSingularTranslationKey: "SINGULAR_GRAM" | "SINGULAR_MICROGRAM" | "SINGULAR_MILLIGRAM" | "SINGULAR_KILOGRAM" | "SINGULAR_METRIC_TONNE" | "SINGULAR_OUNCE" | "SINGULAR_POUND" | "SINGULAR_TON"

MassSystems

MassSystems: "metric" | "imperial"

MassUnit

Maybe

Maybe<T>: T | undefined

Type parameters

  • T

MeasureDefinition

MeasureDefinition<S, U>: { anchors?: Maybe<AnchorPartialRecord<ExtractedSystem<S>, U>>; systems: Record<ExtractedSystem<S>, PartialRecord<U, Unit>> }

Type parameters

Type declaration

MeasureDictionary

MeasureDictionary<TMeasures, TSystems, TUnitType>: PartialRecord<TMeasures, MeasureDictionaryValue<TSystems, TUnitType>>

Type parameters

  • TMeasures: string

  • TSystems: string

  • TUnitType: string

MeasureDictionaryValue

MeasureDictionaryValue<TSystems, TUnitType>: { anchors?: Maybe<PartialRecord<TSystems, GenericAnchor<TSystems, TUnitType>>>; systems: PartialRecord<TSystems, PartialRecord<TUnitType, Unit>> }

Type parameters

  • TSystems: string

  • TUnitType: string

Type declaration

MetricAreaUnit

MetricAreaUnit: "mm2" | "cm2" | "m2" | "ha" | "km2"

MetricDistanceUnit

MetricDistanceUnit: "nm" | "μm" | "mm" | "cm" | "m" | "km"

MetricForceUnit

MetricForceUnit: "N" | "kN"

MetricIlluminanceUnit

MetricIlluminanceUnit: "lx"

MetricMassUnit

MetricMassUnit: "mcg" | "mg" | "g" | "kg" | "mt"

MetricPaceUnit

MetricPaceUnit: "s/m" | "min/km"

MetricPowerUnit

MetricPowerUnit: "W" | "mW" | "kW" | "MW" | "GW" | "PS"

MetricPressureUnit

MetricPressureUnit: "Pa" | "hPa" | "kPa" | "MPa" | "bar" | "torr" | "mmHg"

MetricSpeedUnit

MetricSpeedUnit: "m/s" | "km/h" | "m/h"

MetricTemperatureUnit

MetricTemperatureUnit: "C" | "K"

MetricVolumeFlowRateUnit

MetricVolumeFlowRateUnit: "mm3/s" | "cm3/s" | "ml/s" | "cl/s" | "dl/s" | "l/s" | "l/min" | "l/h" | "kl/s" | "kl/min" | "kl/h" | "m3/s" | "m3/min" | "m3/h" | "km3/s"

MetricVolumeUnit

MetricVolumeUnit: "mm3" | "cm3" | "ml" | "cl" | "dl" | "l" | "kl" | "m3" | "km3"

Name

Name: { plural: string; singular: string }

Type declaration

  • plural: string
  • singular: string

Nullable

Nullable<T>: T | null

Type parameters

  • T

PacePluralTranslationKey

PacePluralTranslationKey: "PLURAL_MINUTE_PER_KILOMETRE" | "PLURAL_SECOND_PER_METRE" | "PLURAL_MINUTE_PER_MILE" | "PLURAL_SECOND_PER_FOOT"

PaceSingularTranslationKey

PaceSingularTranslationKey: "SINGULAR_MINUTE_PER_KILOMETRE" | "SINGULAR_SECOND_PER_METRE" | "SINGULAR_MINUTE_PER_MILE" | "SINGULAR_SECOND_PER_FOOT"

PaceSystems

PaceSystems: "metric" | "imperial"

PaceUnit

PartialRecord

PartialRecord<T, U>: Partial<Record<T, U>>

Type parameters

  • T: keyof any

  • U

PartsPerPluralTranslationKey

PartsPerPluralTranslationKey: "PLURAL_PART_PER_MILLION" | "PLURAL_PART_PER_BILLION" | "PLURAL_PART_PER_TRILLION" | "PLURAL_PART_PER_QUADRILLION"

PartsPerSingularTranslationKey

PartsPerSingularTranslationKey: "SINGULAR_PART_PER_MILLION" | "SINGULAR_PART_PER_BILLION" | "SINGULAR_PART_PER_TRILLION" | "SINGULAR_PART_PER_QUADRILLION"

PartsPerSystems

PartsPerSystems: "other"

PartsPerUnit

PartsPerUnit: "ppm" | "ppb" | "ppt" | "ppq"

PiecesPluralTranslationKey

PiecesPluralTranslationKey: "PLURAL_PIECE" | "PLURAL_BAKERS_DOZEN" | "PLURAL_COUPLE" | "PLURAL_DOZEN_DOZEN" | "PLURAL_PIECE_DOZEN" | "PLURAL_GREAT_GROSS" | "PLURAL_GROSS" | "PLURAL_SMALL_GROSS" | "PLURAL_HALF_DOZEN" | "PLURAL_LONG_HUNDRED" | "PLURAL_REAM" | "PLURAL_SCORES" | "PLURAL_TRIO"

PiecesSingularTranslationKey

PiecesSingularTranslationKey: "SINGULAR_PIECE" | "SINGULAR_BAKERS_DOZEN" | "SINGULAR_COUPLE" | "SINGULAR_DOZEN_DOZEN" | "SINGULAR_PIECE_DOZEN" | "SINGULAR_GREAT_GROSS" | "SINGULAR_GROSS" | "SINGULAR_SMALL_GROSS" | "SINGULAR_HALF_DOZEN" | "SINGULAR_LONG_HUNDRED" | "SINGULAR_REAM" | "SINGULAR_SCORES" | "SINGULAR_TRIO"

PiecesSystems

PiecesSystems: "other"

PiecesUnit

PiecesUnit: "pcs" | "bk-doz" | "cp" | "doz-doz" | "doz" | "gr-gr" | "gros" | "half-dozen" | "long-hundred" | "ream" | "scores" | "sm-gr" | "trio"

PluralTranslationKey

PowerPluralTranslationKey

PowerPluralTranslationKey: "PLURAL_WATT" | "PLURAL_MILLIWATT" | "PLURAL_KILOWATT" | "PLURAL_MEGAWATT" | "PLURAL_GIGAWATT" | "PLURAL_HORSE_POWER" | "PLURAL_BTU_PER_SECOND" | "PLURAL_FOOT_POUND_PER_SECOND" | "PLURAL_IMPERIAL_HORSE_POWER"

PowerSingularTranslationKey

PowerSingularTranslationKey: "SINGULAR_WATT" | "SINGULAR_MILLIWATT" | "SINGULAR_KILOWATT" | "SINGULAR_MEGAWATT" | "SINGULAR_GIGAWATT" | "SINGULAR_HORSE_POWER" | "SINGULAR_BTU_PER_SECOND" | "SINGULAR_FOOT_POUND_PER_SECOND" | "SINGULAR_IMPERIAL_HORSE_POWER"

PowerSystems

PowerSystems: "metric" | "imperial"

PowerUnit

PressurePluralTranslationKey

PressurePluralTranslationKey: "PLURAL_PASCAL" | "PLURAL_KILOPASCAL" | "PLURAL_MEGAPASCAL" | "PLURAL_HECTOPASCAL" | "PLURAL_BAR" | "PLURAL_TORR" | "PLURAL_MILLIMETRE_OF_MERCURY" | "PLURAL_POUND_PER_SQUARE_INCH" | "PLURAL_KILOPOUND_PER_SQUARE_INCH" | "PLURAL_INCH_OF_MERCURY"

PressureSingularTranslationKey

PressureSingularTranslationKey: "SINGULAR_PASCAL" | "SINGULAR_KILOPASCAL" | "SINGULAR_MEGAPASCAL" | "SINGULAR_HECTOPASCAL" | "SINGULAR_BAR" | "SINGULAR_TORR" | "SINGULAR_MILLIMETRE_OF_MERCURY" | "SINGULAR_POUND_PER_SQUARE_INCH" | "SINGULAR_KILOPOUND_PER_SQUARE_INCH" | "SINGULAR_INCH_OF_MERCURY"

PressureSystems

PressureSystems: "metric" | "imperial"

PressureUnit

ReactiveEnergyPluralTranslationKey

ReactiveEnergyPluralTranslationKey: "PLURAL_VOLT_AMPERE_REACTIVE_HOUR" | "PLURAL_MILLIVOLT_AMPERE_REACTIVE_HOUR" | "PLURAL_KILOVOLT_AMPERE_REACTIVE_HOUR" | "PLURAL_MEGAVOLT_AMPERE_REACTIVE_HOUR" | "PLURAL_GIGAVOLT_AMPERE_REACTIVE_HOUR"

ReactiveEnergySingularTranslationKey

ReactiveEnergySingularTranslationKey: "SINGULAR_VOLT_AMPERE_REACTIVE_HOUR" | "SINGULAR_MILLIVOLT_AMPERE_REACTIVE_HOUR" | "SINGULAR_KILOVOLT_AMPERE_REACTIVE_HOUR" | "SINGULAR_MEGAVOLT_AMPERE_REACTIVE_HOUR" | "SINGULAR_GIGAVOLT_AMPERE_REACTIVE_HOUR"

ReactiveEnergySystems

ReactiveEnergySystems: "metric"

ReactiveEnergyUnit

ReactiveEnergyUnit: "VARh" | "mVARh" | "kVARh" | "MVARh" | "GVARh"

ReactivePowerPluralTranslationKey

ReactivePowerPluralTranslationKey: "PLURAL_VOLT_AMPERE_REACTIVE" | "PLURAL_MILLIVOLT_AMPERE_REACTIVE" | "PLURAL_KILOVOLT_AMPERE_REACTIVE" | "PLURAL_MEGAVOLT_AMPERE_REACTIVE" | "PLURAL_GIGAVOLT_AMPERE_REACTIVE"

ReactivePowerSingularTranslationKey

ReactivePowerSingularTranslationKey: "SINGULAR_VOLT_AMPERE_REACTIVE" | "SINGULAR_MILLIVOLT_AMPERE_REACTIVE" | "SINGULAR_KILOVOLT_AMPERE_REACTIVE" | "SINGULAR_MEGAVOLT_AMPERE_REACTIVE" | "SINGULAR_GIGAVOLT_AMPERE_REACTIVE"

ReactivePowerSystems

ReactivePowerSystems: "metric"

ReactivePowerUnit

ReactivePowerUnit: "VAR" | "mVAR" | "kVAR" | "MVAR" | "GVAR"

RequireAtLeastOne

RequireAtLeastOne<T, Keys>: Pick<T, Exclude<keyof T, Keys>> & {[ K in Keys]: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>> }[Keys]

Type parameters

  • T

  • Keys: keyof T = keyof T

SingularTranslationKey

SpeedPluralTranslationKey

SpeedPluralTranslationKey: "PLURAL_METRE_PER_SECOND" | "PLURAL_KILOMETRE_PER_HOUR" | "PLURAL_METRE_PER_HOUR" | "PLURAL_MILE_PER_HOUR" | "PLURAL_KNOT" | "PLURAL_FOOT_PER_SECOND"

SpeedSingularTranslationKey

SpeedSingularTranslationKey: "SINGULAR_METRE_PER_SECOND" | "SINGULAR_KILOMETRE_PER_HOUR" | "SINGULAR_METRE_PER_HOUR" | "SINGULAR_MILE_PER_HOUR" | "SINGULAR_KNOT" | "SINGULAR_FOOT_PER_SECOND"

SpeedSystems

SpeedSystems: "metric" | "imperial"

SpeedUnit

SwedishVolumeUnit

SwedishVolumeUnit: "krm" | "tsk" | "msk" | "kkp" | "glas" | "kanna"

TemperaturePluralTranslationKey

TemperaturePluralTranslationKey: "PLURAL_CELSIUS" | "PLURAL_KELVIN" | "PLURAL_FAHRENHEIT" | "PLURAL_RANKINE"

TemperatureSingularTranslationKey

TemperatureSingularTranslationKey: "SINGULAR_CELSIUS" | "SINGULAR_KELVIN" | "SINGULAR_FAHRENHEIT" | "SINGULAR_RANKINE"

TemperatureSystems

TemperatureSystems: "metric" | "imperial"

TemperatureUnit

TimePluralTranslationKey

TimePluralTranslationKey: "PLURAL_NANOSECOND" | "PLURAL_MICROSECOND" | "PLURAL_MILLISECOND" | "PLURAL_SECOND" | "PLURAL_MINUTE" | "PLURAL_HOUR" | "PLURAL_DAY" | "PLURAL_WEEK" | "PLURAL_MONTH" | "PLURAL_YEAR"

TimeSingularTranslationKey

TimeSingularTranslationKey: "SINGULAR_NANOSECOND" | "SINGULAR_MICROSECOND" | "SINGULAR_MILLISECOND" | "SINGULAR_SECOND" | "SINGULAR_MINUTE" | "SINGULAR_HOUR" | "SINGULAR_DAY" | "SINGULAR_WEEK" | "SINGULAR_MONTH" | "SINGULAR_YEAR"

TimeSystems

TimeSystems: "metric"

TimeUnit

TimeUnit: "ns" | "mu" | "ms" | "s" | "min" | "h" | "d" | "week" | "month" | "year"

TranslationKey

Translations

Translations<TTranslationKeys>: PartialRecord<TTranslationKeys, string>

Type parameters

  • TTranslationKeys: string

Unit

Unit: { anchor: number; anchorShift?: Maybe<number>; name: Name }

Type declaration

  • anchor: number
  • Optional anchorShift?: Maybe<number>
  • name: Name

UnitDescription

UnitDescription<TMeasures, TSystems, TUnitType>: { measure: TMeasures; name: Name; system: TSystems; unitType: TUnitType }

Type parameters

  • TMeasures: string

  • TSystems: string

  • TUnitType: string

Type declaration

  • measure: TMeasures
  • name: Name
  • system: TSystems
  • unitType: TUnitType

VoltagePluralTranslationKey

VoltagePluralTranslationKey: "PLURAL_VOLT" | "PLURAL_MILLIVOLT" | "PLURAL_KILOVOLT"

VoltageSingularTranslationKey

VoltageSingularTranslationKey: "SINGULAR_VOLT" | "SINGULAR_MILLIVOLT" | "SINGULAR_KILOVOLT"

VoltageSystems

VoltageSystems: "metric"

VoltageUnit

VoltageUnit: "V" | "mV" | "kV"

VolumeFlowRatePluralTranslationKey

VolumeFlowRatePluralTranslationKey: "PLURAL_CUBIC_MILLIMETER_PER_SECOND" | "PLURAL_CUBIC_CENTIMETER_PER_SECOND" | "PLURAL_MILLILITRE_PER_SECOND" | "PLURAL_CENTILITRE_PER_SECOND" | "PLURAL_DECILITRE_PER_SECOND" | "PLURAL_LITRE_PER_SECOND" | "PLURAL_LITRE_PER_MINUTE" | "PLURAL_LITRE_PER_HOUR" | "PLURAL_KILOLITRE_PER_SECOND" | "PLURAL_KILOLITRE_PER_MINUTE" | "PLURAL_KILOLITRE_PER_HOUR" | "PLURAL_CUBIC_METER_PER_SECOND" | "PLURAL_CUBIC_METER_PER_MINUTE" | "PLURAL_CUBIC_METER_PER_HOUR" | "PLURAL_CUBIC_KILOMETER_PER_SECOND" | "PLURAL_TEASPOON_PER_SECOND" | "PLURAL_TABLESPOON_PER_SECOND" | "PLURAL_CUBIC_INCH_PER_SECOND" | "PLURAL_CUBIC_INCH_PER_MINUTE" | "PLURAL_CUBIC_INCH_PER_HOUR" | "PLURAL_FLUID_OUNCE_PER_SECOND" | "PLURAL_FLUID_OUNCE_PER_MINUTE" | "PLURAL_FLUID_OUNCE_PER_HOUR" | "PLURAL_CUP_PER_SECOND" | "PLURAL_PINT_PER_SECOND" | "PLURAL_PINT_PER_MINUTE" | "PLURAL_PINT_PER_HOUR" | "PLURAL_QUART_PER_SECOND" | "PLURAL_GALLON_PER_SECOND" | "PLURAL_GALLON_PER_MINUTE" | "PLURAL_GALLON_PER_HOUR" | "PLURAL_CUBIC_FOOT_PER_SECOND" | "PLURAL_CUBIC_FOOT_PER_MINUTE" | "PLURAL_CUBIC_FOOT_PER_HOUR" | "PLURAL_CUBIC_YARD_PER_SECOND" | "PLURAL_CUBIC_YARD_PER_MINUTE" | "PLURAL_CUBIC_YARD_PER_HOUR"

VolumeFlowRateSingularTranslationKey

VolumeFlowRateSingularTranslationKey: "SINGULAR_CUBIC_MILLIMETER_PER_SECOND" | "SINGULAR_CUBIC_CENTIMETER_PER_SECOND" | "SINGULAR_MILLILITRE_PER_SECOND" | "SINGULAR_CENTILITRE_PER_SECOND" | "SINGULAR_DECILITRE_PER_SECOND" | "SINGULAR_LITRE_PER_SECOND" | "SINGULAR_LITRE_PER_MINUTE" | "SINGULAR_LITRE_PER_HOUR" | "SINGULAR_KILOLITRE_PER_SECOND" | "SINGULAR_KILOLITRE_PER_MINUTE" | "SINGULAR_KILOLITRE_PER_HOUR" | "SINGULAR_CUBIC_METER_PER_SECOND" | "SINGULAR_CUBIC_METER_PER_MINUTE" | "SINGULAR_CUBIC_METER_PER_HOUR" | "SINGULAR_CUBIC_KILOMETER_PER_SECOND" | "SINGULAR_TEASPOON_PER_SECOND" | "SINGULAR_TABLESPOON_PER_SECOND" | "SINGULAR_CUBIC_INCH_PER_SECOND" | "SINGULAR_CUBIC_INCH_PER_MINUTE" | "SINGULAR_CUBIC_INCH_PER_HOUR" | "SINGULAR_FLUID_OUNCE_PER_SECOND" | "SINGULAR_FLUID_OUNCE_PER_MINUTE" | "SINGULAR_FLUID_OUNCE_PER_HOUR" | "SINGULAR_CUP_PER_SECOND" | "SINGULAR_PINT_PER_SECOND" | "SINGULAR_PINT_PER_MINUTE" | "SINGULAR_PINT_PER_HOUR" | "SINGULAR_QUART_PER_SECOND" | "SINGULAR_GALLON_PER_SECOND" | "SINGULAR_GALLON_PER_MINUTE" | "SINGULAR_GALLON_PER_HOUR" | "SINGULAR_CUBIC_FOOT_PER_SECOND" | "SINGULAR_CUBIC_FOOT_PER_MINUTE" | "SINGULAR_CUBIC_FOOT_PER_HOUR" | "SINGULAR_CUBIC_YARD_PER_SECOND" | "SINGULAR_CUBIC_YARD_PER_MINUTE" | "SINGULAR_CUBIC_YARD_PER_HOUR"

VolumeFlowRateSystems

VolumeFlowRateSystems: "metric" | "imperial"

VolumeFlowRateUnit

VolumePluralTranslationKey

VolumePluralTranslationKey: "PLURAL_CUBIC_MILLIMETER" | "PLURAL_CUBIC_CENTIMETER" | "PLURAL_MILLILITRE" | "PLURAL_CENTILITRE" | "PLURAL_DECILITRE" | "PLURAL_LITRE" | "PLURAL_KILOLITRE" | "PLURAL_CUBIC_METER" | "PLURAL_CUBIC_KILOMETER" | "PLURAL_TEASPOON" | "PLURAL_TABLESPOON" | "PLURAL_CUBIC_INCH" | "PLURAL_FLUID_OUNCE" | "PLURAL_CUP" | "PLURAL_PINT" | "PLURAL_QUART" | "PLURAL_GALLON" | "PLURAL_CUBIC_FOOT" | "PLURAL_CUBIC_YARD" | "PLURAL_CUBIC_YARD" | "PLURAL_KRYDDMATTET" | "PLURAL_TESKED" | "PLURAL_MATSKED" | "PLURAL_KAFFEKOPP" | "PLURAL_GLAS" | "PLURAL_KANNA"

VolumeSingularTranslationKey

VolumeSingularTranslationKey: "SINGULAR_CUBIC_MILLIMETER" | "SINGULAR_CUBIC_CENTIMETER" | "SINGULAR_MILLILITRE" | "SINGULAR_CENTILITRE" | "SINGULAR_DECILITRE" | "SINGULAR_LITRE" | "SINGULAR_KILOLITRE" | "SINGULAR_CUBIC_METER" | "SINGULAR_CUBIC_KILOMETER" | "SINGULAR_TEASPOON" | "SINGULAR_TABLESPOON" | "SINGULAR_CUBIC_INCH" | "SINGULAR_FLUID_OUNCE" | "SINGULAR_CUP" | "SINGULAR_PINT" | "SINGULAR_QUART" | "SINGULAR_GALLON" | "SINGULAR_CUBIC_FOOT" | "SINGULAR_CUBIC_YARD" | "SINGULAR_KRYDDMATTET" | "SINGULAR_TESKED" | "SINGULAR_MATSKED" | "SINGULAR_KAFFEKOPP" | "SINGULAR_GLAS" | "SINGULAR_KANNA"

VolumeSystems

VolumeSystems: "metric" | "imperial" | "swedish"

VolumeUnit

Properties

allTranslations

allTranslations: Readonly<AllTranslations>

Variables

Const acceleration

Const accelerationTranslations

accelerationTranslations: Record<AccelerationSingularTranslationKey | AccelerationPluralTranslationKey, string> = ...

Const angle

Const angleTranslations

angleTranslations: Record<AngleSingularTranslationKey | AnglePluralTranslationKey, string> = ...

Const apparentPower

Const apparentPowerTranslations

apparentPowerTranslations: Record<ApparentPowerSingularTranslationKey | ApparentPowerPluralTranslationKey, string> = ...

Const area

Const areaTranslations

areaTranslations: Record<AreaSingularTranslationKey | AreaPluralTranslationKey, string> = ...

Const charge

Const chargeTranslations

chargeTranslations: Record<ChargeSingularTranslationKey | ChargePluralTranslationKey, string> = ...

Const current

Const currentTranslations

currentTranslations: Record<CurrentSingularTranslationKey | CurrentPluralTranslationKey, string> = ...

Const digital

Const digitalTranslations

digitalTranslations: Record<DigitalSingularTranslationKey | DigitalPluralTranslationKey, string> = ...

Const distance

Const distanceTranslations

distanceTranslations: Record<DistanceSingularTranslationKey | DistancePluralTranslationKey, string> = ...

Const each

Const eachTranslations

eachTranslations: Record<EachSingularTranslationKey | EachPluralTranslationKey, string> = ...

Const energy

Const energyTranslations

energyTranslations: Record<EnergySingularTranslationKey | EnergyPluralTranslationKey, string> = ...

Const force

Const forceTranslations

forceTranslations: Record<ForceSingularTranslationKey | ForcePluralTranslationKey, string> = ...

Const frequency

Const frequencyTranslations

frequencyTranslations: Record<FrequencySingularTranslationKey | FrequencyPluralTranslationKey, string> = ...

Const illuminance

Const illuminanceTranslations

illuminanceTranslations: Record<IlluminanceSingularTranslationKey | IlluminancePluralTranslationKey, string> = ...

Const mass

Const massTranslations

massTranslations: Record<MassSingularTranslationKey | MassPluralTranslationKey, string> = ...

Const pace

Const paceTranslations

paceTranslations: Record<PaceSingularTranslationKey | PacePluralTranslationKey, string> = ...

Const partsPer

Const partsPerTranslations

partsPerTranslations: Record<PartsPerSingularTranslationKey | PartsPerPluralTranslationKey, string> = ...

Const pieces

Const piecesTranslations

piecesTranslations: Record<PiecesSingularTranslationKey | PiecesPluralTranslationKey, string> = ...

Const power

Const powerTranslations

powerTranslations: Record<PowerSingularTranslationKey | PowerPluralTranslationKey, string> = ...

Const pressure

Const pressureTranslations

pressureTranslations: Record<PressureSingularTranslationKey | PressurePluralTranslationKey, string> = ...

Const reactiveEnergy

Const reactiveEnergyTranslations

reactiveEnergyTranslations: Record<ReactiveEnergySingularTranslationKey | ReactiveEnergyPluralTranslationKey, string> = ...

Const reactivePower

Const reactivePowerTranslations

reactivePowerTranslations: Record<ReactivePowerSingularTranslationKey | ReactivePowerPluralTranslationKey, string> = ...

Const speed

Const speedTranslations

speedTranslations: Record<SpeedSingularTranslationKey | SpeedPluralTranslationKey, string> = ...

Const temperature

Const temperatureTranslations

temperatureTranslations: Record<TemperatureSingularTranslationKey | TemperaturePluralTranslationKey, string> = ...

Const time

Const timeTranslations

timeTranslations: Record<TimeSingularTranslationKey | TimePluralTranslationKey, string> = ...

Const voltage

Const voltageTranslations

voltageTranslations: Record<VoltageSingularTranslationKey | VoltagePluralTranslationKey, string> = ...

Const volume

Const volumeFlowRate

Const volumeFlowRateTranslations

volumeFlowRateTranslations: Record<VolumeFlowRateSingularTranslationKey | VolumeFlowRatePluralTranslationKey, string> = ...

Const volumeTranslations

volumeTranslations: Record<VolumeSingularTranslationKey | VolumePluralTranslationKey, string> = ...

Functions

convert

  • convert<TMeasures, TSystems, TUnitType>(converter: IConverter<TMeasures, TSystems, TUnitType>, from: TUnitType, to: TUnitType, value: number): number | never
  • Converts a value from a compatible unit to another.

    throws

    An InstanceError if converter is not provided

    throws

    An IncompatibleUnitError if from or to are not valid unit types

    throws

    An Error if from and to have different measures

    throws

    An Error if a definition is malformed

    Type parameters

    • TMeasures: string

    • TSystems: string

    • TUnitType: string

    Parameters

    • converter: IConverter<TMeasures, TSystems, TUnitType>

      The converter instance to use with this function

    • from: TUnitType

      The type from which you want to convert

    • to: TUnitType

      The type to which you want to convert

    • value: number

      The value you want to convert

    Returns number | never

    The converted value

convertToBest

  • convertToBest<TMeasures, TSystems, TUnitType>(converter: IConverter<TMeasures, TSystems, TUnitType>, options: Partial<ConvertToBestDto<TUnitType>>, from: TUnitType, value: number): BestConversion<TUnitType>
  • Converts a value from a compatible unit to the best unit (or smallest) given some optional parameters.

    throws

    An InstanceError if converter is not provided

    throws

    An IncompatibleUnitError if from is not a valid unit type

    Type parameters

    • TMeasures: string

    • TSystems: string

    • TUnitType: string

    Parameters

    • converter: IConverter<TMeasures, TSystems, TUnitType>

      The converter instance to use with this function

    • options: Partial<ConvertToBestDto<TUnitType>>

      The conversion configuration

    • from: TUnitType

      The type from which you want to convert

    • value: number

      The value you want to convert

    Returns BestConversion<TUnitType>

    An object containing the best unit given the optional parameters and its converted value

describe

  • describe<TMeasures, TSystems, TUnitType, TTranslationKeys>(converter: IConverter<TMeasures, TSystems, TUnitType, TTranslationKeys>, type: TUnitType): UnitDescription<TMeasures, TSystems, TUnitType> | never
  • Describes an unit type

    throws

    An InstanceError if converter is not provided

    throws

    An IncompatibleUnitError if type is not a valid unit type

    Type parameters

    • TMeasures: string

    • TSystems: string

    • TUnitType: string

    • TTranslationKeys: string

    Parameters

    • converter: IConverter<TMeasures, TSystems, TUnitType, TTranslationKeys>

      The converter instance to use with this function

    • type: TUnitType

      The type you want get a description of

    Returns UnitDescription<TMeasures, TSystems, TUnitType> | never

    An in-depth description of type. Names are translated with the i18n module.

Const getUnit

  • getUnit<TMeasures, TSystems, TUnitType>(converter: IConverter<TMeasures, TSystems, TUnitType, null>, unitType: TUnitType): Conversion<TMeasures, TSystems, TUnitType>
  • Gives a Conversion object from an unit type

    This function is memoized

    throws

    An InstanceError if converter is not provided

    Type parameters

    • TMeasures: string

    • TSystems: string

    • TUnitType: string

    Parameters

    • converter: IConverter<TMeasures, TSystems, TUnitType, null>

      The converter instance to use with this function

    • unitType: TUnitType

      The type you want get the Conversion of

    Returns Conversion<TMeasures, TSystems, TUnitType>

    The raw valid conversion unit or null. Raw meaning that i18n values are not translated.

list

  • list<TMeasures, TSystems, TUnitType, TTranslationKeys>(converter: IConverter<TMeasures, TSystems, TUnitType, TTranslationKeys>, measure?: Maybe<TMeasures>): UnitDescription<TMeasures, TSystems, TUnitType>[] | never
  • Gives a list of descriptions of the units for a given measure, or all the units supported by the library.

    throws

    An InstanceError if converter is not provided

    throws

    An Error if measure is not a valid measure

    Type parameters

    • TMeasures: string

    • TSystems: string

    • TUnitType: string

    • TTranslationKeys: string

    Parameters

    • converter: IConverter<TMeasures, TSystems, TUnitType, TTranslationKeys>

      The converter instance to use with this function

    • Optional measure: Maybe<TMeasures>

      the measure of which you want the list of units

    Returns UnitDescription<TMeasures, TSystems, TUnitType>[] | never

    The list of descriptions of the units for a given measure, or all the units supported by the Converter instance passed as argument.

measures

  • measures<TMeasures, TSystems, TUnitType>(converter: IConverter<TMeasures, TSystems, TUnitType>): TMeasures[]
  • throws

    An InstanceError if converter is not provided

    Type parameters

    • TMeasures: string

    • TSystems: string

    • TUnitType: string

    Parameters

    • converter: IConverter<TMeasures, TSystems, TUnitType>

      The converter instance to use with this function

    Returns TMeasures[]

    All kind of measurements supported by the Converter instance passed as argument

possibilities

  • possibilities<TMeasures, TSystems, TUnitType>(converter: IConverter<TMeasures, TSystems, TUnitType>, arg?: Maybe<TMeasures | TUnitType>): TUnitType[]
  • Gives a list of compatible units from a given unit type or measure (it gives all the units supported by the library if no argument is provided)

    throws

    An Error if arg is not a valid unit type or measure

    Type parameters

    • TMeasures: string

    • TSystems: string

    • TUnitType: string

    Parameters

    • converter: IConverter<TMeasures, TSystems, TUnitType>

      The converter instance to use with this function

    • Optional arg: Maybe<TMeasures | TUnitType>

      A valid type or measure from which you want to get a list of compatible conversion units

    Returns TUnitType[]

    A list of compatible units with a given unit type or measure or all the units supported by the Converter instance passed as argument

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Private property

Generated using TypeDoc