Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Unit

Unit

Usage

Creation

const myUnit = new Unit("meter", {
 baseName: "length",
 aliases: ["m", "meters"],
 prefixes: 'decimal'
})

Specifiers

You can specify the prefix using the specifier(...) function.

const nanoUnit = myUnit.specifier(UnitPrefix.NANO);

Hierarchy

Index

Constructors

constructor

Properties

Protected Readonly Static UNITS

UNITS: Map<string, Unit> = ...

Protected Readonly Static UNIT_BASES

UNIT_BASES: Map<string, string> = ...

Accessors

aliases

  • get aliases(): string[]

baseName

  • get baseName(): string

definitions

name

  • get name(): string
  • set name(name: string): void

prefixType

Protected prefixes

Methods

convert

  • convert<T>(value: T, target: string | Unit): T
  • Convert a value in the current unit to a target unit

    Type parameters

    Parameters

    • value: T

      Value to convert

    • target: string | Unit

      Target unit

    Returns T

    Converted unit

createBaseDefinition

createDefinition

Protected findByName

  • findByName(name: string): Unit

specifier

Static convert

  • Convert a value from a specific unit to a target unit

    Parameters

    • value: number | Vector3

      Value to convert

    • from: string | Unit

      Source unit

    • to: string | Unit

      Target unit

    Returns number | Vector3

    Converted unit

Static findByName

  • findByName(name: string, baseName?: string): Unit
  • Find a unit by its name

    Parameters

    • name: string

      Unit name

    • Optional baseName: string

      Optional base name to specific result

    Returns Unit

    Unit if found

Static registerUnit

  • registerUnit(unit: Unit, override?: boolean): Unit
  • Register a new unit

    Parameters

    • unit: Unit

      Unit to register

    • override: boolean = false

      Override an existing unit with the same name

    Returns Unit

    Registered unit