@thi.ng/units 0.4.18 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +33 -37
- package/constants/densities.js +44 -26
- package/constants/earth.js +15 -32
- package/constants/paper-sizes.js +106 -59
- package/constants/velocities.js +8 -12
- package/package.json +10 -7
- package/unit.js +155 -284
- package/units/accel.js +14 -4
- package/units/angle.js +16 -7
- package/units/area.js +20 -9
- package/units/data.js +50 -25
- package/units/density.js +6 -2
- package/units/electric.js +48 -24
- package/units/energy.js +14 -6
- package/units/force.js +4 -1
- package/units/frequency.js +18 -8
- package/units/length.js +40 -19
- package/units/luminous.js +8 -3
- package/units/mass.js +22 -10
- package/units/parts.js +16 -7
- package/units/power.js +18 -8
- package/units/pressure.js +18 -8
- package/units/substance.js +4 -1
- package/units/temperature.js +12 -3
- package/units/time.js +22 -10
- package/units/velocity.js +12 -5
- package/units/volume.js +34 -14
package/unit.js
CHANGED
|
@@ -4,305 +4,176 @@ import { isString } from "@thi.ng/checks/is-string";
|
|
|
4
4
|
import { equivArrayLike } from "@thi.ng/equiv";
|
|
5
5
|
import { assert } from "@thi.ng/errors/assert";
|
|
6
6
|
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
* @param dim
|
|
19
|
-
* @param scale
|
|
20
|
-
* @param offset
|
|
21
|
-
* @param coherent
|
|
22
|
-
*/
|
|
23
|
-
export const unit = (dim, scale, offset = 0, coherent = false) => ({
|
|
24
|
-
dim: isNumber(dim) ? __oneHot(dim) : dim,
|
|
25
|
-
scale,
|
|
26
|
-
offset,
|
|
27
|
-
coherent,
|
|
7
|
+
import {
|
|
8
|
+
NONE,
|
|
9
|
+
PREFIXES
|
|
10
|
+
} from "./api.js";
|
|
11
|
+
const UNITS = {};
|
|
12
|
+
const unit = (dim, scale, offset = 0, coherent2 = false) => ({
|
|
13
|
+
dim: isNumber(dim) ? __oneHot(dim) : dim,
|
|
14
|
+
scale,
|
|
15
|
+
offset,
|
|
16
|
+
coherent: coherent2
|
|
28
17
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Returns a new dimensionless unit (i.e. all SI dimensions are zero) with given
|
|
37
|
-
* `scale` factor.
|
|
38
|
-
*
|
|
39
|
-
* @param scale
|
|
40
|
-
* @param offset
|
|
41
|
-
* @param coherent
|
|
42
|
-
*/
|
|
43
|
-
export const dimensionless = (scale, offset = 0, coherent = false) => unit(NONE.dim, scale, offset, coherent);
|
|
44
|
-
/**
|
|
45
|
-
* Takes a unit symbol, full unit name and pre-defined {@link Unit} impl and
|
|
46
|
-
* registers it in the {@link UNITS} cache for further lookups by symbol name.
|
|
47
|
-
*
|
|
48
|
-
* @remarks
|
|
49
|
-
* By default throws an error if attempting to register a unit with an existing
|
|
50
|
-
* symbol. If `force` is true, the existing unit will be overwritten.
|
|
51
|
-
*
|
|
52
|
-
* @param sym
|
|
53
|
-
* @param name
|
|
54
|
-
* @param unit
|
|
55
|
-
* @param force
|
|
56
|
-
*/
|
|
57
|
-
export const defUnit = (sym, name, unit, force = false) => {
|
|
58
|
-
if (UNITS[sym] && !force)
|
|
59
|
-
illegalArgs(`attempt to override unit: ${sym}`);
|
|
60
|
-
return (UNITS[sym] = { ...unit, sym, name });
|
|
18
|
+
const coherent = (dim) => unit(dim, 1, 0, true);
|
|
19
|
+
const dimensionless = (scale, offset = 0, coherent2 = false) => unit(NONE.dim, scale, offset, coherent2);
|
|
20
|
+
const defUnit = (sym, name, unit2, force = false) => {
|
|
21
|
+
if (UNITS[sym] && !force)
|
|
22
|
+
illegalArgs(`attempt to override unit: ${sym}`);
|
|
23
|
+
return UNITS[sym] = { ...unit2, sym, name };
|
|
61
24
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
export const asUnit = (id) => {
|
|
69
|
-
for (let i = 0; i < id.length; i++) {
|
|
70
|
-
const pre = id.substring(0, i);
|
|
71
|
-
const unit = UNITS[id.substring(i)];
|
|
72
|
-
if (unit) {
|
|
73
|
-
return PREFIXES[pre] !== undefined
|
|
74
|
-
? prefix(pre, unit)
|
|
75
|
-
: !pre
|
|
76
|
-
? unit
|
|
77
|
-
: illegalArgs(`unknown unit: ${id}`);
|
|
78
|
-
}
|
|
25
|
+
const asUnit = (id) => {
|
|
26
|
+
for (let i = 0; i < id.length; i++) {
|
|
27
|
+
const pre = id.substring(0, i);
|
|
28
|
+
const unit2 = UNITS[id.substring(i)];
|
|
29
|
+
if (unit2) {
|
|
30
|
+
return PREFIXES[pre] !== void 0 ? prefix(pre, unit2) : !pre ? unit2 : illegalArgs(`unknown unit: ${id}`);
|
|
79
31
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
32
|
+
}
|
|
33
|
+
for (let u in UNITS) {
|
|
34
|
+
if (UNITS[u].name === id)
|
|
35
|
+
return UNITS[u];
|
|
36
|
+
}
|
|
37
|
+
illegalArgs(`unknown unit: ${id}`);
|
|
85
38
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
* (see {@link PREFIXES}). If `coherent` is true (default: false), the new unit
|
|
90
|
-
* itself is considered coherent and can be prefixed later.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* // create kilometer unit from (builtin) meter
|
|
95
|
-
* const KM = prefix("k", M);
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* @param id
|
|
99
|
-
* @param unit
|
|
100
|
-
* @param coherent
|
|
101
|
-
*/
|
|
102
|
-
export const prefix = (id, unit, coherent = false) => {
|
|
103
|
-
const $u = __ensureUnit(unit);
|
|
104
|
-
return $u.coherent
|
|
105
|
-
? mul($u, PREFIXES[id], coherent)
|
|
106
|
-
: illegalArgs("unit isn't coherent");
|
|
39
|
+
const prefix = (id, unit2, coherent2 = false) => {
|
|
40
|
+
const $u = __ensureUnit(unit2);
|
|
41
|
+
return $u.coherent ? mul($u, PREFIXES[id], coherent2) : illegalArgs("unit isn't coherent");
|
|
107
42
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
deref() {
|
|
117
|
-
return ((isArray(this.value)
|
|
118
|
-
? this.value.map((x) => x.scale)
|
|
119
|
-
: this.value.scale));
|
|
120
|
-
}
|
|
43
|
+
class Quantity {
|
|
44
|
+
constructor(value) {
|
|
45
|
+
this.value = value;
|
|
46
|
+
}
|
|
47
|
+
deref() {
|
|
48
|
+
return isArray(this.value) ? this.value.map((x) => x.scale) : this.value.scale;
|
|
49
|
+
}
|
|
121
50
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
*
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
*
|
|
139
|
-
* // compute wavelength of a WiFi signal in millimeters
|
|
140
|
-
* convert(div(speedOfLight, quantity(2.4,"GHz")), "mm");
|
|
141
|
-
* // 124.9135
|
|
142
|
-
*
|
|
143
|
-
* // DIN A4 paper size
|
|
144
|
-
* const A4 = quantity([210, 297], "mm");
|
|
145
|
-
*
|
|
146
|
-
* // convert paper size to inches
|
|
147
|
-
* convert(A4, "in");
|
|
148
|
-
* // [ 8.2677, 11.6929 ]
|
|
149
|
-
*
|
|
150
|
-
* // or calculate pixel dimensions @ 300 dpi
|
|
151
|
-
* // the result of the product is dimensionless so we use NONE as target unit
|
|
152
|
-
* convert(mul(A4, quantity(300, "dpi")), NONE)
|
|
153
|
-
* // [ 2480.314960629921, 3507.8740157480315 ]
|
|
154
|
-
*
|
|
155
|
-
* // alternatively dimensionless units can be deref'd directly
|
|
156
|
-
* mul(A4, quantity(300, "dpi")).deref()
|
|
157
|
-
* // [ 2480.314960629921, 3507.8740157480315 ]
|
|
158
|
-
* ```
|
|
159
|
-
*
|
|
160
|
-
* @param value
|
|
161
|
-
* @param unit
|
|
162
|
-
*/
|
|
163
|
-
export const quantity = (value, unit) => new Quantity(((isNumber(value)
|
|
164
|
-
? mul(unit, value)
|
|
165
|
-
: value.map((x) => mul(unit, x)))));
|
|
166
|
-
export function mul(a, b, coherent = false) {
|
|
167
|
-
if (a instanceof Quantity)
|
|
168
|
-
return __combineQ(mul, a, b);
|
|
169
|
-
const $a = __ensureUnit(a);
|
|
170
|
-
if (isNumber(b))
|
|
171
|
-
return unit($a.dim, $a.scale * b, $a.offset, coherent);
|
|
172
|
-
const $b = __ensureUnit(b);
|
|
173
|
-
return unit($a.dim.map((x, i) => x + $b.dim[i]), $a.scale * $b.scale, 0, coherent);
|
|
51
|
+
const quantity = (value, unit2) => new Quantity(
|
|
52
|
+
isNumber(value) ? mul(unit2, value) : value.map((x) => mul(unit2, x))
|
|
53
|
+
);
|
|
54
|
+
function mul(a, b, coherent2 = false) {
|
|
55
|
+
if (a instanceof Quantity)
|
|
56
|
+
return __combineQ(mul, a, b);
|
|
57
|
+
const $a = __ensureUnit(a);
|
|
58
|
+
if (isNumber(b))
|
|
59
|
+
return unit($a.dim, $a.scale * b, $a.offset, coherent2);
|
|
60
|
+
const $b = __ensureUnit(b);
|
|
61
|
+
return unit(
|
|
62
|
+
$a.dim.map((x, i) => x + $b.dim[i]),
|
|
63
|
+
$a.scale * $b.scale,
|
|
64
|
+
0,
|
|
65
|
+
coherent2
|
|
66
|
+
);
|
|
174
67
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
68
|
+
function div(a, b, coherent2 = false) {
|
|
69
|
+
if (a instanceof Quantity)
|
|
70
|
+
return __combineQ(div, a, b);
|
|
71
|
+
const $a = __ensureUnit(a);
|
|
72
|
+
if (isNumber(b)) {
|
|
73
|
+
return unit($a.dim, $a.scale / b, $a.offset, coherent2);
|
|
74
|
+
}
|
|
75
|
+
const $b = __ensureUnit(b);
|
|
76
|
+
return unit(
|
|
77
|
+
$a.dim.map((x, i) => x - $b.dim[i]),
|
|
78
|
+
$a.scale / $b.scale,
|
|
79
|
+
0,
|
|
80
|
+
coherent2
|
|
81
|
+
);
|
|
184
82
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
: div(NONE, u.value))
|
|
190
|
-
: div(NONE, u, coherent);
|
|
83
|
+
function reciprocal(u, coherent2 = false) {
|
|
84
|
+
return u instanceof Quantity ? new Quantity(
|
|
85
|
+
isArray(u.value) ? u.value.map((x) => div(NONE, x)) : div(NONE, u.value)
|
|
86
|
+
) : div(NONE, u, coherent2);
|
|
191
87
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
*
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
* // acceleration aka m/s^2
|
|
201
|
-
* const M_S2 = div(M, pow(S, 2));
|
|
202
|
-
* ```
|
|
203
|
-
*
|
|
204
|
-
* @param u
|
|
205
|
-
* @param k
|
|
206
|
-
* @param coherent
|
|
207
|
-
*/
|
|
208
|
-
export const pow = (u, k, coherent = false) => {
|
|
209
|
-
const $u = __ensureUnit(u);
|
|
210
|
-
return unit($u.dim.map((x) => x * k), $u.scale ** k, 0, coherent);
|
|
88
|
+
const pow = (u, k, coherent2 = false) => {
|
|
89
|
+
const $u = __ensureUnit(u);
|
|
90
|
+
return unit(
|
|
91
|
+
$u.dim.map((x) => x * k),
|
|
92
|
+
$u.scale ** k,
|
|
93
|
+
0,
|
|
94
|
+
coherent2
|
|
95
|
+
);
|
|
211
96
|
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
assert(equivArrayLike($src.dim, $dest.dim), "incompatible dimensions");
|
|
224
|
-
return (xnorm - $dest.offset) / $dest.scale;
|
|
97
|
+
function convert(x, a, b) {
|
|
98
|
+
const $src = __ensureUnit(a);
|
|
99
|
+
if (x instanceof Quantity) {
|
|
100
|
+
return isArray(x.value) ? x.value.map((y) => convert(1, y, $src)) : convert(1, x.value, $src);
|
|
101
|
+
}
|
|
102
|
+
const $dest = __ensureUnit(b);
|
|
103
|
+
const xnorm = x * $src.scale + $src.offset;
|
|
104
|
+
if (isReciprocal($src, $dest))
|
|
105
|
+
return (1 / xnorm - $dest.offset) / $dest.scale;
|
|
106
|
+
assert(equivArrayLike($src.dim, $dest.dim), "incompatible dimensions");
|
|
107
|
+
return (xnorm - $dest.offset) / $dest.scale;
|
|
225
108
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
export const isConvertible = (src, dest) => {
|
|
233
|
-
if (src instanceof Quantity)
|
|
234
|
-
return isConvertible(__qunit(src), dest);
|
|
235
|
-
const $src = __ensureUnit(src);
|
|
236
|
-
const $dest = __ensureUnit(dest);
|
|
237
|
-
return isReciprocal($src, $dest) || equivArrayLike($src.dim, $dest.dim);
|
|
109
|
+
const isConvertible = (src, dest) => {
|
|
110
|
+
if (src instanceof Quantity)
|
|
111
|
+
return isConvertible(__qunit(src), dest);
|
|
112
|
+
const $src = __ensureUnit(src);
|
|
113
|
+
const $dest = __ensureUnit(dest);
|
|
114
|
+
return isReciprocal($src, $dest) || equivArrayLike($src.dim, $dest.dim);
|
|
238
115
|
};
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
export const isReciprocal = (a, b) => {
|
|
255
|
-
const { dim: $a } = __ensureUnit(a);
|
|
256
|
-
const { dim: $b } = __ensureUnit(b);
|
|
257
|
-
let ok = false;
|
|
258
|
-
for (let i = 0; i < 7; i++) {
|
|
259
|
-
const xa = $a[i];
|
|
260
|
-
const xb = $b[i];
|
|
261
|
-
if (xa === 0 && xb === 0)
|
|
262
|
-
continue;
|
|
263
|
-
if (xa !== -xb)
|
|
264
|
-
return false;
|
|
265
|
-
ok = true;
|
|
266
|
-
}
|
|
267
|
-
return ok;
|
|
116
|
+
const isDimensionless = (u) => u instanceof Quantity ? isDimensionless(__qunit(u)) : __ensureUnit(u).dim.every((x) => x === 0);
|
|
117
|
+
const isReciprocal = (a, b) => {
|
|
118
|
+
const { dim: $a } = __ensureUnit(a);
|
|
119
|
+
const { dim: $b } = __ensureUnit(b);
|
|
120
|
+
let ok = false;
|
|
121
|
+
for (let i = 0; i < 7; i++) {
|
|
122
|
+
const xa = $a[i];
|
|
123
|
+
const xb = $b[i];
|
|
124
|
+
if (xa === 0 && xb === 0)
|
|
125
|
+
continue;
|
|
126
|
+
if (xa !== -xb)
|
|
127
|
+
return false;
|
|
128
|
+
ok = true;
|
|
129
|
+
}
|
|
130
|
+
return ok;
|
|
268
131
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
for (let i = 0; i < 7; i++) {
|
|
282
|
-
const x = dim[i];
|
|
283
|
-
if (x !== 0)
|
|
284
|
-
acc.push(SI[i] + (x !== 1 ? x : ""));
|
|
285
|
-
}
|
|
286
|
-
return acc.length ? acc.join("·") : "<dimensionless>";
|
|
132
|
+
const formatSI = (u) => {
|
|
133
|
+
if (u instanceof Quantity)
|
|
134
|
+
return formatSI(__qunit(u));
|
|
135
|
+
const { dim } = __ensureUnit(u);
|
|
136
|
+
const SI = ["kg", "m", "s", "A", "K", "mol", "cd"];
|
|
137
|
+
const acc = [];
|
|
138
|
+
for (let i = 0; i < 7; i++) {
|
|
139
|
+
const x = dim[i];
|
|
140
|
+
if (x !== 0)
|
|
141
|
+
acc.push(SI[i] + (x !== 1 ? x : ""));
|
|
142
|
+
}
|
|
143
|
+
return acc.length ? acc.join("\xB7") : "<dimensionless>";
|
|
287
144
|
};
|
|
288
|
-
|
|
289
|
-
const __ensureUnit = (x) => (isString(x) ? asUnit(x) : x);
|
|
290
|
-
/** @internal */
|
|
145
|
+
const __ensureUnit = (x) => isString(x) ? asUnit(x) : x;
|
|
291
146
|
const __oneHot = (x) => {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
147
|
+
const dims = new Array(7).fill(0);
|
|
148
|
+
dims[x] = 1;
|
|
149
|
+
return dims;
|
|
295
150
|
};
|
|
296
|
-
const __qunit = (q) =>
|
|
151
|
+
const __qunit = (q) => isArray(q.value) ? q.value[0] : q.value;
|
|
297
152
|
const __combineQ = (op, a, b) => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
153
|
+
const $b = b;
|
|
154
|
+
const vecA = isArray(a.value);
|
|
155
|
+
const vecB = isArray($b.value);
|
|
156
|
+
return new Quantity(
|
|
157
|
+
vecA ? vecB ? a.value.map((x, i) => op(x, $b.value[i])) : a.value.map((x) => op(x, $b.value)) : vecB ? $b.value.map((x) => op(a.value, x)) : op(a.value, $b.value)
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
export {
|
|
161
|
+
Quantity,
|
|
162
|
+
UNITS,
|
|
163
|
+
asUnit,
|
|
164
|
+
coherent,
|
|
165
|
+
convert,
|
|
166
|
+
defUnit,
|
|
167
|
+
dimensionless,
|
|
168
|
+
div,
|
|
169
|
+
formatSI,
|
|
170
|
+
isConvertible,
|
|
171
|
+
isDimensionless,
|
|
172
|
+
isReciprocal,
|
|
173
|
+
mul,
|
|
174
|
+
pow,
|
|
175
|
+
prefix,
|
|
176
|
+
quantity,
|
|
177
|
+
reciprocal,
|
|
178
|
+
unit
|
|
308
179
|
};
|
package/units/accel.js
CHANGED
|
@@ -3,7 +3,17 @@ import { ft, m } from "./length.js";
|
|
|
3
3
|
import { s } from "./time.js";
|
|
4
4
|
import { defUnit, div, mul, pow } from "../unit.js";
|
|
5
5
|
const s2 = pow(s, 2);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const m_s2 = defUnit("m/s2", "meter per second squared", div(m, s2));
|
|
7
|
+
const ft_s2 = defUnit("ft/s2", "foot per second squared", div(ft, s2));
|
|
8
|
+
const rad_s2 = defUnit(
|
|
9
|
+
"rad/s2",
|
|
10
|
+
"radian per second squared",
|
|
11
|
+
div(rad, s2)
|
|
12
|
+
);
|
|
13
|
+
const g0 = defUnit("g0", "standard gravity", mul(m_s2, 9.80665));
|
|
14
|
+
export {
|
|
15
|
+
ft_s2,
|
|
16
|
+
g0,
|
|
17
|
+
m_s2,
|
|
18
|
+
rad_s2
|
|
19
|
+
};
|
package/units/angle.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { defUnit, dimensionless, mul } from "../unit.js";
|
|
2
2
|
const PI = Math.PI;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
const rad = defUnit("rad", "radian", dimensionless(1, 0, true));
|
|
4
|
+
const deg = defUnit("deg", "degree", mul(rad, PI / 180));
|
|
5
|
+
const gon = defUnit("gon", "gradian", mul(rad, PI / 200));
|
|
6
|
+
const turn = defUnit("turn", "turn", mul(rad, 2 * PI));
|
|
7
|
+
const arcmin = defUnit("arcmin", "arc minute", mul(rad, PI / 10800));
|
|
8
|
+
const arcsec = defUnit("arcsec", "arc second", mul(rad, PI / 648e3));
|
|
9
|
+
const sr = defUnit("sr", "steradian", dimensionless(1, 0, true));
|
|
10
|
+
export {
|
|
11
|
+
arcmin,
|
|
12
|
+
arcsec,
|
|
13
|
+
deg,
|
|
14
|
+
gon,
|
|
15
|
+
rad,
|
|
16
|
+
sr,
|
|
17
|
+
turn
|
|
18
|
+
};
|
package/units/area.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { cm, ft, inch, km, m, mi, mm } from "./length.js";
|
|
2
2
|
import { defUnit, mul, pow } from "../unit.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const m2 = defUnit("m2", "square meter", pow(m, 2));
|
|
4
|
+
const mm2 = defUnit("mm2", "square millimeter", pow(mm, 2));
|
|
5
|
+
const cm2 = defUnit("cm2", "square centimeter", pow(cm, 2));
|
|
6
|
+
const km2 = defUnit("km2", "square kilometer", pow(km, 2));
|
|
7
|
+
const ha = defUnit("ha", "hectar", mul(m2, 1e4));
|
|
8
|
+
const ac = defUnit("ac", "acre", mul(m2, 4046.86));
|
|
9
|
+
const sqin = defUnit("sqin", "square inch", pow(inch, 2));
|
|
10
|
+
const sqft = defUnit("sqft", "square foot", pow(ft, 2));
|
|
11
|
+
const sqmi = defUnit("sqmi", "square mile", pow(mi, 2));
|
|
12
|
+
export {
|
|
13
|
+
ac,
|
|
14
|
+
cm2,
|
|
15
|
+
ha,
|
|
16
|
+
km2,
|
|
17
|
+
m2,
|
|
18
|
+
mm2,
|
|
19
|
+
sqft,
|
|
20
|
+
sqin,
|
|
21
|
+
sqmi
|
|
22
|
+
};
|
package/units/data.js
CHANGED
|
@@ -1,26 +1,51 @@
|
|
|
1
1
|
import { defUnit, dimensionless, mul, prefix } from "../unit.js";
|
|
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
|
-
export
|
|
2
|
+
const bit = defUnit("bit", "bit", dimensionless(1, 0, true));
|
|
3
|
+
const kbit = defUnit("kbit", "kilobit", prefix("k", bit));
|
|
4
|
+
const Mbit = defUnit("Mbit", "megabit", prefix("M", bit));
|
|
5
|
+
const Gbit = defUnit("Gbit", "gigabit", prefix("G", bit));
|
|
6
|
+
const Tbit = defUnit("Tbit", "terabit", prefix("T", bit));
|
|
7
|
+
const B = defUnit("B", "byte", mul(bit, 8, true));
|
|
8
|
+
const kB = defUnit("kB", "kilobyte", prefix("k", B));
|
|
9
|
+
const MB = defUnit("MB", "megabyte", prefix("M", B));
|
|
10
|
+
const GB = defUnit("GB", "gigabyte", prefix("G", B));
|
|
11
|
+
const TB = defUnit("TB", "terabyte", prefix("T", B));
|
|
12
|
+
const PB = defUnit("PB", "petabyte", prefix("P", B));
|
|
13
|
+
const EB = defUnit("EB", "exabyte", prefix("E", B));
|
|
14
|
+
const Kibit = defUnit("Kibit", "kibibit", mul(bit, 1024));
|
|
15
|
+
const Mibit = defUnit("Mibit", "mebibit", mul(Kibit, 1024));
|
|
16
|
+
const Gibit = defUnit("Gibit", "gibibit", mul(Mibit, 1024));
|
|
17
|
+
const Tibit = defUnit("Tibit", "tebibit", mul(Gibit, 1024));
|
|
18
|
+
const Pibit = defUnit("Pibit", "pebibit", mul(Tibit, 1024));
|
|
19
|
+
const Eibit = defUnit("Eibit", "exbibit", mul(Pibit, 1024));
|
|
20
|
+
const KiB = defUnit("KiB", "kibibyte", mul(B, 1024));
|
|
21
|
+
const MiB = defUnit("MiB", "mebibyte", mul(KiB, 1024));
|
|
22
|
+
const GiB = defUnit("GiB", "gibibyte", mul(MiB, 1024));
|
|
23
|
+
const TiB = defUnit("TiB", "tebibyte", mul(GiB, 1024));
|
|
24
|
+
const PiB = defUnit("PiB", "pebibyte", mul(TiB, 1024));
|
|
25
|
+
const EiB = defUnit("EiB", "exbibyte", mul(PiB, 1024));
|
|
26
|
+
export {
|
|
27
|
+
B,
|
|
28
|
+
EB,
|
|
29
|
+
EiB,
|
|
30
|
+
Eibit,
|
|
31
|
+
GB,
|
|
32
|
+
Gbit,
|
|
33
|
+
GiB,
|
|
34
|
+
Gibit,
|
|
35
|
+
KiB,
|
|
36
|
+
Kibit,
|
|
37
|
+
MB,
|
|
38
|
+
Mbit,
|
|
39
|
+
MiB,
|
|
40
|
+
Mibit,
|
|
41
|
+
PB,
|
|
42
|
+
PiB,
|
|
43
|
+
Pibit,
|
|
44
|
+
TB,
|
|
45
|
+
Tbit,
|
|
46
|
+
TiB,
|
|
47
|
+
Tibit,
|
|
48
|
+
bit,
|
|
49
|
+
kB,
|
|
50
|
+
kbit
|
|
51
|
+
};
|
package/units/density.js
CHANGED
|
@@ -2,5 +2,9 @@ import { inch } from "./length.js";
|
|
|
2
2
|
import { kg } from "./mass.js";
|
|
3
3
|
import { defUnit, div, reciprocal } from "../unit.js";
|
|
4
4
|
import { m3 } from "./volume.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const kg_m3 = defUnit("kg/m3", "kilogram per cubic meter", div(kg, m3));
|
|
6
|
+
const dpi = defUnit("dpi", "dots per inch", reciprocal(inch));
|
|
7
|
+
export {
|
|
8
|
+
dpi,
|
|
9
|
+
kg_m3
|
|
10
|
+
};
|