Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Units

Representation and manipulation of physical units.

These are based on SI, and in particular the (Guide for the Use of the International System of Units (SI))https://physics.nist.gov/cuu/pdf/sp811.pdf(https://physics.nist.gov/cuu/pdf/sp811.pdf]) However, this does not try to be complete, and extends the set of base units somewhat to aid clarity (for example, 'cycles/revolutions') while preserving semantics and standardized presentation. Having units that map to SI '1' is not very helpful sometimes.

See the Units.Units namespace for definitions of individual units.

preferred

Index

Type aliases

Complete

Complete<U>: U extends IUnitBase<infer T> ? Unit<CompleteTerms<T>> : never

Takes an IUnitBase with partially-supplied UnitTerms and fill in the missing exponents with 0.

internal
module

Physical Units

Type parameters

CompleteTerms

CompleteTerms<A>: {[ K in keyof typeof Primitive]: OrZero<A[K]> }

Take a partial set of UnitTerms, and fills in the missing exponents with 0.

module

Physical Units

Type parameters

Divide

Divide<A, B>: A extends Unit<infer TA> ? B extends Unit<infer TB> ? Unit<DivideTerms<TA, TB>> : never : never

Divide two Unit types, A/B (by subtracting the exponents).

module

Physical Units

Type parameters

DivideTerms

DivideTerms<A, B>: {[ K in keyof typeof Primitive]: Sub<OrZero<A[K]>, OrZero<B[K]>> }

Divide two UnitTerms, A/B

module

Physical Units

Type parameters

InvertTerms

InvertTerms<A>: {[ K in keyof typeof Primitive]: Negate<OrZero<A[K]>> }

Invert a UnitTerms (by negating the exponents).

module

Physical Units

Type parameters

Multiply

Multiply<A, B>: A extends IUnitBase<infer TA> ? B extends IUnitBase<infer TB> ? Unit<MultiplyTerms<TA, TB>> : never : never

Multiply two Unit types (by adding the exponents).

module

Physical Units

Type parameters

MultiplyTerms

MultiplyTerms<A, B>: {[ K in keyof typeof Primitive]: Add<OrZero<A[K]>, OrZero<B[K]>> }

Multiply two UnitTerms (by adding the exponents.)

module

Physical Units

Type parameters

PrefixExponent

PrefixExponent: 24 | 21 | 18 | 15 | 12 | 9 | 6 | 3 | 2 | 1 | -1 | -2 | -3 | -6 | -9 | -12 | -15 | -18 | -21 | -24

PrefixName

PrefixName: "yotta" | "zetta" | "exa" | "peta" | "tera" | "giga" | "mega" | "kilo" | "hecto" | "deka" | "deci" | "centi" | "milli" | "micro" | "nano" | "pico" | "fempto" | "atto" | "zepto" | "yocto"

PrefixSymbol

PrefixSymbol: "Y" | "Z" | "E" | "P" | "T" | "G" | "M" | "k" | "h" | "da" | "d" | "c" | "m" | "μ" | "u" | "n" | "p" | "f" | "a" | "z" | "y"

TermsOfUnit

TermsOfUnit<U>: U extends Unit<infer T> ? CompleteTerms<T> : never

Type parameters

TermsOfUnitBase

TermsOfUnitBase<U>: U extends IUnitBase<infer T> ? T : never

Type parameters

UnitTerms

UnitTerms: {[ u in keyof typeof Primitive]: Exponent }

An object with keys being the name of Primitive types and the values being exponents. All values are required; supply zero for values not supplied.

See PUnitTerms for a partial set where types can be left undefined.

module

Units

Functions

Const completeKey

Const defineAlias

  • defineAlias<T>(name: string, symbol: undefined | string, attributes: AliasAttributes, si: Unit<T>, scale: number, offset?: number, ...names: string[]): Unit<T> & Alias
  • Define a unit alias, which can convert to/from a corresponding standard unprefixed SI unit.

    module

    Physical Units

    Type parameters

    Parameters

    • name: string
    • symbol: undefined | string
    • attributes: AliasAttributes
    • si: Unit<T>
    • scale: number
    • offset: number = 0
    • Rest ...names: string[]

    Returns Unit<T> & Alias

Const defineUnit

  • Define a derived type.

    The numbers in the keys are exponents for primitive types. They are taken as type literals,

    This ensures, for example, that the types of U.velocity and U.acceleration are distinct.

    const U.velocity     = defineUnit({distance: 1, time: -1});
    const U.acceleration = defineUnit({distance: 1, time: -2});
    

    Results in types of:

    type U.velocity     = Unit<{distance: 1, time: -1}>
    type U.acceleration = Unit<{distance: 1, time: -2}>
    
    module

    Physical Units

    module

    Physical Units

    Type parameters

    Parameters

    • key: T

      The key defining the type composition

    • attributes: UnitAttributes = ...

      Additional attributes describing the type.

    • Rest ...names: string[]

      Additional names to use for this type, e.g. newton.

    Returns Unit<CompleteTerms<T>>

Const getUnit

  • Get a unit by name.

    To process a # + unit into standard unprefixed SI, do:

    const [siVal, siUnit] = getUnit(unitName).toSI(val);
    

    To just get the standard SI unit, do:

    const siUnit = getUnit(unitName).si;
    

    Parameters

    • name: string
    • siOnly: boolean = false

      if true, only unscaled SI units are returned.

    Returns Unit<UnitTerms>

Const isUnit

Generated using TypeDoc