forked from thi-ng/umbrella
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.ts
111 lines (105 loc) · 1.64 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
export interface Unit {
/**
* SI base dimension vector ({@link Dimensions})
*/
dim: Dimensions;
/**
* Scaling factor relative to the coherent unit
*/
scale: number;
/**
* Zero offset value
*/
offset: number;
/**
* True, if this unit is coherent.
*
* @remarks
* Reference:
* - https://en.wikipedia.org/wiki/Coherence_(units_of_measurement)
*/
coherent: boolean;
}
export interface NamedUnit extends Unit {
/**
* Symbol under which this unit can be looked up with via {@link asUnit} and
* others.
*/
sym: string;
/**
* This unit's human readable description/name.
*/
name: string;
}
export type MaybeUnit = Unit | string;
/**
* Vector of the 7 basic SI unit dimensions.
*
* @remarks
* In order:
*
* - 0 = mass
* - 1 = length
* - 2 = time
* - 3 = current
* - 4 = temperature
* - 5 = amount of substance
* - 6 = luminous intensity
*
* Note: For dimensionless units, all dimensions are zero.
*
* Reference:
* - https://en.wikipedia.org/wiki/SI_base_unit
*/
export type Dimensions = [
number,
number,
number,
number,
number,
number,
number
];
/**
* A known metric prefix.
*/
export type Prefix = keyof typeof PREFIXES;
/**
* @remarks
* Reference:
* - https://en.wikipedia.org/wiki/Metric_prefix
*/
export const PREFIXES = {
Q: 1e30,
R: 1e27,
Y: 1e24,
Z: 1e21,
E: 1e18,
P: 1e15,
T: 1e12,
G: 1e9,
M: 1e6,
k: 1e3,
h: 1e2,
d: 1e-1,
c: 1e-2,
m: 1e-3,
µ: 1e-6,
n: 1e-9,
p: 1e-12,
f: 1e-15,
a: 1e-18,
z: 1e-21,
y: 1e-24,
r: 1e-27,
q: 1e-30,
};
/**
* Dimensionless unit preset.
*/
export const NONE: Unit = {
dim: [0, 0, 0, 0, 0, 0, 0],
scale: 1,
offset: 0,
coherent: false,
};