UNPKG

@qudtlib/core

Version:

Data model for QUDTLib

273 lines (272 loc) 13.1 kB
import { Unit } from "./unit.js"; import { QuantityKind } from "./quantityKind.js"; import { Prefix } from "./prefix.js"; import { DerivedUnitSearchMode } from "./derivedUnitSearchMode.js"; import { FactorUnit } from "./factorUnit.js"; import { FactorUnits } from "./factorUnits.js"; import { QuantityValue } from "./quantityValue.js"; import { Decimal } from "decimal.js"; import { SystemOfUnits } from "./systemOfUnits.js"; import { DimensionVector } from "./dimensionVector.js"; export declare class QudtlibConfig { readonly units: Map<string, Unit>; readonly quantityKinds: Map<string, QuantityKind>; readonly prefixes: Map<string, Prefix>; readonly systemsOfUnits: Map<string, SystemOfUnits>; readonly unitsByDimensionVector: Map<string, Array<Unit>>; constructor(); indexUnitsByDimensionVector(): void; } export declare const config: QudtlibConfig; export declare class Qudt { static NAMESPACES: Readonly<{ qudt: import("./namespace.js").Namespace; quantityKind: import("./namespace.js").Namespace; unit: import("./namespace.js").Namespace; currency: import("./namespace.js").Namespace; prefix: import("./namespace.js").Namespace; systemOfUnits: import("./namespace.js").Namespace; dimensionVector: import("./namespace.js").Namespace; }>; /** * Returns the {@link Unit} identified the specified IRI. For example, <code> * unit("http://qudt.org/vocab/unit/N-PER-M2")</code> yields `Units.N__PER__M2`, * if that unit has been loaded; * * @param iri the requested unit IRI * @return the unit or `undefined` if no unit is found */ static unit(unitIri: string): Unit | undefined; /** * Same as {@link #unit(string)} but throws an exception if no unit is found. * @param unitIri the unit IRI * @return the unit */ static unitRequired(unitIri: string): Unit; /** * Returns the first unit found whose label matches the specified label after replacing any * underscore with space and ignoring case (US locale). If more intricate matching is needed, * clients can use `{@link #allUnits()}.filter(...)`. * * @param label the matched label * @return the first unit found */ static unitFromLabel(label: string): Unit | undefined; static unitFromLabelRequired(label: string): Unit; static unitFromLocalname(localname: string): Unit | undefined; static unitFromLocalnameRequired(localname: string): Unit; static unitIriFromLocalname(localname: string): string; static currencyFromLocalname(localname: string): Unit | undefined; static currencyFromLocalnameRequired(localname: string): Unit; static currencyIriFromLocalname(localname: string): string; static quantityKind(quantityKindIri: string): QuantityKind | undefined; static quantityKindRequired(quantityKindIri: string): QuantityKind; static quantityKindFromLocalname(localname: string): QuantityKind | undefined; static quantityKindFromLocalnameRequired(localname: string): QuantityKind; static quantityKindIriFromLocalname(localname: string): string; static quantityKinds(unit: Unit): QuantityKind[]; static quantityKindsBroad(unit: Unit): QuantityKind[]; static isBroaderQuantityKind(suspectedBroader: QuantityKind, quantityKind: QuantityKind): boolean; static prefixFromLabelRequired(label: string): Prefix; static prefixFromLabel(label: string): Prefix | undefined; static prefixFromLocalname(localname: string): Prefix | undefined; static prefixFromLocalnameRequired(localname: string): Prefix; static prefixIriFromLocalname(localname: string): string; static prefix(prefixIri: string): Prefix | undefined; static prefixRequired(prefixIri: string): Prefix; static systemOfUnitsFromLabelRequired(label: string): SystemOfUnits; static systemOfUnitsFromLabel(label: string): SystemOfUnits | undefined; static systemOfUnitsFromLocalname(localname: string): SystemOfUnits | undefined; static systemOfUnitsFromLocalnameRequired(localname: string): SystemOfUnits; static systemOfUnitsIriFromLocalname(localname: string): string; static systemOfUnits(systemOfUnitsIri: string): SystemOfUnits | undefined; static systemOfUnitsRequired(systemOfUnitsIri: string): SystemOfUnits; /** * Obtains units based on factor units, using the specified {@link DerivedUnitSearchMode}. * * For example, * * ``` * const spec = new Map<Unit, number>(); * spec.set(Units.M, 1); * spec.set(Units.KiloGM, 1); * spec.set(Units.SEC, -2); * Qudt.derivedUnitsFrom Map( * DerivedUnitSearchMode.BEST_MATCH, spec); * ``` * * will yield an array containing the Newton Unit ({@code Qudt.Units.N}) * * @param searchMode the {@link DerivedUnitSearchMode} to use * @param factorUnits a map containing unit to exponent entries. * @return the derived units that match the given factor units */ static derivedUnitsFromMap(searchMode: DerivedUnitSearchMode, factorUnits: Map<Unit, number>): Unit[]; /** * Obtains units based on factor units. * * @param searchMode the {@link DerivedUnitSearchMode} to use * @param factorUnits the factor units * @return the derived unit that match the given factor units * @see #derivedUnitsFromMap(DerivedUnitSearchMode, Map) */ static derivedUnitsFromFactorUnits(searchMode: DerivedUnitSearchMode, ...factorUnits: FactorUnit[]): Unit[]; /** * Vararg method, must be an even number of arguments, always alternating types of Unit|String * and Integer. * * @param factorUnitSpec alternating Unit (representing a unit IRI) and Decimal|number (the * exponent) * @return the units that match */ static derivedUnitsFromExponentUnitPairs(searchMode: DerivedUnitSearchMode, ...factorUnitSpecs: (Unit | string | number)[]): Unit[]; /** * @param searchMode the {@link DerivedUnitSearchMode} to use * @param selection the factor unit selection * @return the units that match * @see #derivedUnitsFromMap(DerivedUnitSearchMode, Map) */ static derivedUnitsFromFactorUnitSelection(searchMode: DerivedUnitSearchMode, selection: FactorUnits): Unit[]; private static bestMatchForFactorUnitsComparator; private static findMatchingUnits; static getUnitsByDimensionVector(dimVector: DimensionVector | string): Array<Unit>; static getUnitsWithSameDimensionVector(unit: Unit): Unit[]; /** * Returns the unit resulting from scaling the specified `unit` with the specified `prefix`. * NOTE: if you have unit/prefix labels (not IRIs) - such as "KILO", "NEWTON", use {@link #scaleUnitFromLabels(string, string):Unit}. * * @param prefix the prefix to use for scaling or its IRI. * @param baseUnit the unit to scale or its IRI * @return the resulting unit * @throws exception if no such unit is found */ static scale(prefix: Prefix | string, baseUnit: Unit | string): Unit; /** * Returns the unit resulting from scaling the specified `baseUnitLabel` label * (such as "METER") with the specified `prefixLabel` (such as "KILO"). * * @param prefixLabel the label of the prefix, case-insensitive , such as "KILO", or "kilo" * @param baseUnitLabel the label of the base unit, case-insensitive, such as "Meter" */ static scaleUnitFromLabels(prefixLabel: string, baseUnitLabel: string): Unit; /** * Returns the list of {@link FactorUnit}s of the specified `unit`. * * @param unit the unit to get factors for * @return the factors of the unit or an empty list if the unit is not a derived unit */ static factorUnits(unit: Unit): FactorUnit[]; /** * Perform mathematical simplification on factor units. Only simplifies units with exponents of the same sign. * * For example, * ``` * N / M * M -> N per M^2 * ``` * * @param factorUnits the factor units to simplify * @return the simplified factor units. * @deprecated `use contractExponents(FactorUnit[]): FactorUnit[]` instead */ static simplifyFactorUnits(factorUnits: FactorUnit[]): FactorUnit[]; static contractFactorUnits(factorUnits: FactorUnit[]): FactorUnit[]; static reduceFactorUnits(factorUnits: FactorUnit[]): FactorUnit[]; static unscale(unit: Unit, treatKiloGmAsUnscaled?: boolean, treatPrefixlessAsUnscaled?: boolean): Unit; /** * Return a list of {@link FactorUnit}s with the same exponents as the specified `factorUnits` but their base units as units. * * @param factorUnits the factor units to unscale * @return the unscaled factor units */ static unscaleFactorUnits(factorUnits: FactorUnit[], treatKiloGMAsUnscaled?: boolean, treatPrefixlessAsUnscaled?: boolean): FactorUnit[]; /** * Instantiates a QuantityValue. * @param value a Decimal * @param unit a Unit or unit IRI. * @return a QuantityValue with the specified data */ static quantityValue(value: Decimal, unit: Unit | string): QuantityValue; /** * Converts the specified value from the unit it is in (`fromUnit`) to the specified target unit (`toUnit`). * @param value: a Decimal, the value to convert. * @param fromUnit: a Unit or string. A string is interpreted as a Unit IRI. * @param toUnit: a Unit or string. A string is interpreted as a Unit IRI. * @return the resulting value */ static convert(value: Decimal, fromUnit: Unit | string, toUnit: Unit | string, quantityKind?: QuantityKind | string): Decimal; /** * Converts the specified QuantityValue from to the specified target unit (`toUnit`). * @param value: a Decimal, the value to convert. * @param fromUnit: a Unit or string. A string is interpreted as a Unit IRI. * @param toUnit: a Unit or string. A string is interpreted as a Unit IRI. * @return a QuantityValue holding the result */ static convertQuantityValue(from: QuantityValue, toUnit: Unit | string, quantityKind?: QuantityKind | string): QuantityValue; /** * Returns `true` if the two units can be converted into each other. * @param fromUnit a Unit or unit IRI * @param toUnit a Unit or unit IRI * @return a boolean indicating whether the units are convertible. */ static isConvertible(fromUnit: Unit | string, toUnit: Unit | string): boolean; /** * Returns a [Unit, Decimal] tuple containing the base unit of the specified `unit` * along with the scale factor needed to convert values from the base unit to * the specified unit. * * @param unit the unit to scale to its base * @return a [Unit, Decimal] tuple with the base unit and the required scale factor */ static scaleToBaseUnit(unit: Unit): { unit: Unit; factor: Decimal; }; static allUnits(): Unit[]; static allQuantityKinds(): QuantityKind[]; static allPrefixes(): Prefix[]; static allSystemsOfUnits(): SystemOfUnits[]; static allUnitsOfSystem(system: SystemOfUnits): Unit[]; /** * Returns the first unit obtained using {@link #correspondingUnitsInSystem(Unit, * SystemOfUnits)}. * * @return the unit corresponding to the specified unit in the specified systemOfUnits. */ static correspondingUnitInSystem(unit: Unit, systemOfUnits: SystemOfUnits): Unit | undefined; /** * Gets units that correspond to the specified unit are allowed in the specified systemOfUnits. * The resulting units have to * * <ol> * <li>have the same dimension vector as the unit * <li>share at least one quantityKind with unit * </ol> * * and they are ascending sorted by dissimilarity in magnitude to the magnitude of the specified * unit, i.e. the first unit returned is the closest in magnitude. * * <p>If two resulting units have the same magnitude difference from the specified one, the * following comparisons are made consecutively until a difference is found: * * <ol> * <li>the base unit of the specified system is ranked first * <li>conversion offset closer to the one of the specified unit is ranked first * <li>the unscaled unit is ranked first * <li>the unit that has a symbol is ranked first * <li>the unit with more quantityKinds is ranked first * <li>the units are ranked by their IRIs lexicographically * </ol> * * that is a base unit of the system is ranked first. If none or both are base units, the one * with a conversion offset closer to the specified unit's conversion offset is ranked first. * * @param unit * @param systemOfUnits * @return */ static correspondingUnitsInSystem(unit: Unit, systemOfUnits: SystemOfUnits): Unit[]; private static scaleDifference; private static offsetDifference; private static logOrZeroRequireNonNegative; } //# sourceMappingURL=qudt.d.ts.map