@rwk/physics-math
Version:
Math for physics homework problems
188 lines • 5.38 kB
TypeScript
/**
* @packageDocumentation
* @module Units
*/
import { ViewOf } from "./utils";
import { StyleContext } from "./latex";
/**
* String literal parser for LaTeX literals (avoids the need for quoting backslash).
*/
export declare const TeX: (template: TemplateStringsArray, ...substitutions: any[]) => string;
/**
* Our enumerated primitive units.
*/
export declare enum Primitive {
time = "time",
mass = "mass",
length = "length",
cycles = "cycles",
angle = "angle",
solidAngle = "solidAngle",
current = "current",
temperature = "temperature",
amount = "amount",
candela = "candela",
money = "money"
}
export declare const primitiveKeys: Primitive[];
/**
* Comparison predicate for primitive units to allow sorting them into a
* canonical total order.
*
* @param a
* @param b
*/
export declare const orderUnits: (a: Primitive, b: Primitive) => 0 | 1 | -1;
/**
* Our supported exponents. A finite list of exponents allows TypeScript to
* automatically type exponents as numeric literal types.
*/
export declare type Exponent = -9 | -8 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
/**
* An object of primitive UNIT: Exponent pairs that uniquely describes each type.
*/
export declare type PUnitTerms = {
[u in keyof typeof Primitive]?: Exponent;
};
export interface PrimitiveUnitAttributes {
name: string;
symbol: string;
varName: string;
absolute?: boolean;
si_base?: boolean;
names?: string[];
[k: string]: any;
}
/**
* Marker interface indicating primitive standard non-prefixed SI-compatible units.
*/
export interface PrimitiveSI {
name?: string;
}
export interface UnitAttributes extends Partial<PrimitiveUnitAttributes> {
tex?: string;
scale?: number;
offset?: number;
}
/**
* The public interface to all units and aliases.
*/
export interface IUnitBase<T extends PUnitTerms = PUnitTerms> {
/**
* Unique lookup key for this type.
*/
readonly key: T;
readonly id: string;
readonly name: string;
readonly names: string[];
readonly symbol?: string;
readonly varName?: string;
readonly attributes: UnitAttributes;
readonly tex: string;
toTex(ctx?: StyleContext): string;
readonly html: Element & ViewOf<IUnitBase<T>>;
toHtml(block?: boolean, ctx?: StyleContext): Element & ViewOf<IUnitBase>;
}
/**
* Turn the structured UnitTerms key into a string to do the lookup for unique types.
* @param key
*/
export declare const makeLookupKey: (key: PUnitTerms) => string;
/**
* Marker interface indicating standard non-prefixed SI-compatible units.
*/
export interface SI {
}
/**
* Base class for all units (and aliases).
*/
export declare abstract class UnitBase<T extends PUnitTerms> implements IUnitBase<T> {
readonly key: T;
readonly symbol?: string;
readonly attributes: UnitAttributes;
private id_?;
private tex_?;
readonly names: string[];
protected constructor(key: T, attributes: UnitAttributes);
toTex(ctx?: StyleContext): string;
get tex(): string;
get id(): string;
abstract readonly name: string;
get html(): Element & ViewOf<this>;
toHtml(block?: boolean, ctx?: StyleContext): Element & ViewOf<this>;
toString(): string;
}
/**
* Our primitive (non-decomposable) units.
*/
declare class PrimitiveUnit<U extends Primitive> extends UnitBase<{
[K in U]: 1;
}> implements SI, PrimitiveSI {
readonly symbol: string;
readonly name: string;
readonly varName?: string;
readonly unit: Primitive;
constructor(u: U, name: string, symbol: string, varName?: string, attributes?: UnitAttributes);
}
/**
* Type of our [[PRIMITIVE_MAP]] map. This provides one key/value entry for each primitive,
* indexed by the UNIT enum.
*/
export declare type PrimitiveMap = {
[k in keyof typeof Primitive]: PrimitiveUnit<(typeof Primitive)[k]>;
};
/**
* A map from primitive name to its Unit instance.
*/
export declare const PRIMITIVE_MAP: Readonly<PrimitiveMap>;
/**
* Namespace for primitives only; merged into the U namespace.
* @internal
*/
export declare namespace P {
const mass: IUnitBase<{
mass: 1;
}>;
type mass = typeof mass;
const time: IUnitBase<{
time: 1;
}>;
type time = typeof time;
const length: IUnitBase<{
length: 1;
}>;
type length = typeof length;
const angle: IUnitBase<{
angle: 1;
}>;
type angle = typeof angle;
const solidAngle: IUnitBase<{
solidAngle: 1;
}>;
type solidAngle = typeof solidAngle;
const amount: IUnitBase<{
amount: 1;
}>;
type amount = typeof amount;
const cycles: IUnitBase<{
cycles: 1;
}>;
type cycles = typeof cycles;
const current: IUnitBase<{
current: 1;
}>;
type current = typeof current;
const temperature: IUnitBase<{
temperature: 1;
}>;
type temperature = typeof temperature;
const candela: IUnitBase<{
candela: 1;
}>;
type candela = typeof candela;
const money: IUnitBase<{
money: 1;
}>;
}
export {};
//# sourceMappingURL=primitive-units.d.ts.map