/** * @module Unit */ export interface Unit { readonly name: string; readonly quantity: TQuantityName; readonly unitInfo: UnitInfo; } /** * This record represents a determinate quantity (as of length, time, heat, or value) * adopted as a standard of measurement. * * It is helpful to think of instances of this record as recording the history by which * they are created. Thus, for example, the string "g/kg" (which is a dimensionless unit) * would result from invoking the method toString() on a unit that was created by * dividing a gram unit by a kilogram unit. Yet, "kg" divided by "kg" returns ONE and * not "kg/kg" due to automatic unit factorization. * * This record supports the multiplication of offsets units. The result is usually a unit * not convertible to its standard unit. Such units may appear in derivative quantities. * For example °C/m is an unit of gradient, which is common in atmospheric and oceanographic research. * * Units raised at rational powers are also supported. For example the cubic root of liter * is a unit compatible with meter. */ export declare type UnitInfo = AlternateUnit | BaseUnit | ProductUnit | TransformedUnit; /** * This record represents the building blocks on top of which all others * units are created. * This record represents the "standard base units" which includes SI base * units and possibly others user-defined base units. It does not represent * the base units of any specific System Of Units (they would have * be base units accross all possible systems otherwise). */ export interface BaseUnit { readonly type: "base"; readonly quantity: T; /** Holds the unique symbol for this base unit. */ readonly symbol: string; } /** * This record represents the units used in expressions to distinguish * between quantities of a different nature but of the same dimensions. */ export interface AlternateUnit { readonly type: "alternate"; readonly quantity: T; readonly symbol: string; /** Holds the parent unit (a system unit). */ readonly parent: Unit; } /** * This record represents the units derived from other units using * UnitConverter converters. * * Examples of transformed units: * CELSIUS = KELVIN.add(273.15); * FOOT = METER.multiply(0.3048); * MILLISECOND = MILLI(SECOND); * * Transformed units have no label. But like any other units, * they may have labels attached to them: * UnitFormat.getStandardInstance().label(FOOT, "ft"); * * or aliases: * UnitFormat.getStandardInstance().alias(CENTI(METER)), "centimeter"); * UnitFormat.getStandardInstance().alias(CENTI(METER)), "centimetre"); */ export interface TransformedUnit { readonly type: "transformed"; readonly quantity: T; /** Holds the parent unit (not a transformed unit). */ readonly parentUnit: Unit; /** Holds the converter to the parent unit. */ readonly toParentUnitConverter: UnitConverter; } /** * This record represents units formed by the product of rational powers of * existing units. * This record maintains the canonical form of this product (simplest * form after factorization). For example: * METER.pow(2).divide(METER) returns METER. */ export interface ProductUnit { readonly type: "product"; readonly quantity: T; readonly elements: ReadonlyArray; } /** Represents a rational power of a single unit. */ export interface Element { /** Holds the single unit. */ readonly unit: Unit; /** Holds the power exponent. */ readonly pow: number; } /** * This type represents a converter of numeric values. * Sub-types must ensure unicity of the identity * converter. In other words, if the result of an operation is equivalent * to the identity converter, then the unique IDENTITY instance * should be returned. */ export declare type UnitConverter = OffsetConverter | CompoundConverter | FactorConverter | IdentityConverter; /** This record represents a compound converter. */ export interface CompoundConverter { readonly type: "compound"; /** Holds the first converter. */ readonly first: UnitConverter; /** Holds the second converter. */ readonly second: UnitConverter; } export interface FactorConverter { readonly type: "factor"; readonly factor: number; } /** This record represents the identity converter (singleton). */ export interface IdentityConverter { readonly type: "identity"; } export interface OffsetConverter { readonly type: "offset"; readonly offset: number; } export declare type Dimensionless = "Dimensionless"; /** * Holds the dimensionless unit ONE * @type {Unit} */ export declare const One: Unit; /** * Creates a base unit having the specified symbol. * @param quantity The quantity of the resulting unit. * @param symbol The symbol of this base unit. */ export declare function createBase(name: string, quantity: T, symbol: string): Unit; /** * Creates an alternate unit for the specified unit identified by the * specified symbol. * @param symbol The symbol for this alternate unit. * @param parent Parent the system unit from which this alternate unit is derived. */ export declare function createAlternate(name: string, symbol: string, parent: Unit): Unit; /** * Returns the product of the specified units. * @param quantity The quantity of the resulting unit. * @param left The left unit operand. * @param right The right unit operand. * @returns left * right */ export declare function times(name: string, quantity: T, left: Unit, right: Unit): Unit; /** * Returns the quotient of the specified units. * @param quantity The quantity of the resulting unit. * @param left The dividend unit operand. * @param right The divisor unit operand. * @returns left / right */ export declare function divide(name: string, quantity: T, left: Unit, right: Unit): Unit; export declare function squareRoot(name: string, quantity: T, unit: Unit): Unit; export declare function timesNumber(name: string, factor: number, unit: Unit): Unit; export declare function divideNumber(name: string, factor: number, unit: Unit): Unit; export declare function plus(name: string, offset: number, unit: Unit): Unit; export declare function minus(name: string, offset: number, unit: Unit): Unit; /** * Converts numeric values from a unit to another unit. * @param value The numeric value to convert. * @param fromUnit The unit from which to convert the numeric value. * @param toUnit The unit to which to convert the numeric value. * @returns The converted numeric value. */ export declare function convert(value: number, fromUnit: Unit, toUnit: Unit): number; export declare function equals(left: Unit, right: Unit): boolean; export declare type GetSymbolFn = (unit: Unit) => string; export declare function buildDerivedSymbol(unit: Unit, getSymbol?: GetSymbolFn): string; export declare function exhaustiveCheck(x: never, throwError?: boolean, match?: string): never;