@thi.ng/units 0.4.17 → 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/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 { NONE, PREFIXES, } from "./api.js";
8
- /**
9
- * Cache/registry for all units defined via {@link defUnit}.
10
- */
11
- export const UNITS = {};
12
- /**
13
- * Defines a "raw" (anonymous) unit using given dimension(s), scale factor, zero
14
- * offset and `coherent` flag indicating if the unit is the coherent one for
15
- * given dimensions and can later be used for deriving prefixed versions (see
16
- * {@link coherent}).
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
- * Syntax sugar for defining coherent SI base units. See {@link unit}.
31
- *
32
- * @param dim
33
- */
34
- export const coherent = (dim) => unit(dim, 1, 0, true);
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
- * Attempts to find a unit by given symbol ID/name. Throws error if unit is
64
- * unknown.
65
- *
66
- * @param id
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
- for (let u in UNITS) {
81
- if (UNITS[u].name === id)
82
- return UNITS[u];
83
- }
84
- illegalArgs(`unknown unit: ${id}`);
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
- * Creates a new re-scaled version of given unit (only coherent ones are
88
- * allowed), using the scale factor associated with given standard metric prefix
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
- * Wrapper for scalar or vector quantities. See {@link quantity}.
110
- */
111
- export class Quantity {
112
- value;
113
- constructor(value) {
114
- this.value = value;
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
- * Creates a new {@link Quantity}, i.e. a certain finite amount of a given unit.
124
- * `value` can be a number or vector.
125
- *
126
- * @remarks
127
- * The quantities can then be used for calculations & conversions using the
128
- * polymorphic functions: {@link div}, {@link mul}, {@link reciprocal} and
129
- * {@link convert}.
130
- *
131
- * The {@link Quantity} class also implements the standard [`IDeref`]()
132
- * interface to obtain unwrapped amount (though only should be used for
133
- * dimensionless quantities). Use {@link convert} otherwise!
134
- *
135
- * @example
136
- * ```ts
137
- * const speedOfLight = quantity(299792458, "m/s");
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
- export function div(a, b, coherent = false) {
176
- if (a instanceof Quantity)
177
- return __combineQ(div, a, b);
178
- const $a = __ensureUnit(a);
179
- if (isNumber(b)) {
180
- return unit($a.dim, $a.scale / b, $a.offset, coherent);
181
- }
182
- const $b = __ensureUnit(b);
183
- return unit($a.dim.map((x, i) => x - $b.dim[i]), $a.scale / $b.scale, 0, coherent);
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
- export function reciprocal(u, coherent = false) {
186
- return u instanceof Quantity
187
- ? new Quantity(isArray(u.value)
188
- ? u.value.map((x) => div(NONE, x))
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
- * Raises given unit to power `k`. If `coherent` is true (default: false), the
194
- * new unit itself is considered coherent and can be prefixed later.
195
- *
196
- * ```ts
197
- * // create kilometer unit from (builtin) meter
198
- * const SQ_METER = pow(M, 2);
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
- export function convert(x, a, b) {
213
- const $src = __ensureUnit(a);
214
- if (x instanceof Quantity) {
215
- return isArray(x.value)
216
- ? x.value.map((y) => convert(1, y, $src))
217
- : convert(1, x.value, $src);
218
- }
219
- const $dest = __ensureUnit(b);
220
- const xnorm = x * $src.scale + $src.offset;
221
- if (isReciprocal($src, $dest))
222
- return (1 / xnorm - $dest.offset) / $dest.scale;
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
- * Returns true if `src` quantity or unit is convertible to `dest` unit.
228
- *
229
- * @param src
230
- * @param dest
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
- * Returns true, if `u` is a dimensionless quantity or unit.
241
- *
242
- * @param u
243
- */
244
- export const isDimensionless = (u) => u instanceof Quantity
245
- ? isDimensionless(__qunit(u))
246
- : __ensureUnit(u).dim.every((x) => x === 0);
247
- /**
248
- * Returns true if the two given units are reciprocal to each other (and
249
- * therefore can be used for conversion).
250
- *
251
- * @param a
252
- * @param b
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
- * Polymorphic function. Returns formatted version of given quantity's or unit's
271
- * SI dimension vector.
272
- *
273
- * @param u
274
- */
275
- export const formatSI = (u) => {
276
- if (u instanceof Quantity)
277
- return formatSI(__qunit(u));
278
- const { dim } = __ensureUnit(u);
279
- const SI = ["kg", "m", "s", "A", "K", "mol", "cd"];
280
- const acc = [];
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
- /** @internal */
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
- const dims = new Array(7).fill(0);
293
- dims[x] = 1;
294
- return dims;
147
+ const dims = new Array(7).fill(0);
148
+ dims[x] = 1;
149
+ return dims;
295
150
  };
296
- const __qunit = (q) => (isArray(q.value) ? q.value[0] : q.value);
151
+ const __qunit = (q) => isArray(q.value) ? q.value[0] : q.value;
297
152
  const __combineQ = (op, a, b) => {
298
- const $b = b;
299
- const vecA = isArray(a.value);
300
- const vecB = isArray($b.value);
301
- return new Quantity(vecA
302
- ? vecB
303
- ? a.value.map((x, i) => op(x, $b.value[i]))
304
- : a.value.map((x) => op(x, $b.value))
305
- : vecB
306
- ? $b.value.map((x) => op(a.value, x))
307
- : op(a.value, $b.value));
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
- export const m_s2 = defUnit("m/s2", "meter per second squared", div(m, s2));
7
- export const ft_s2 = defUnit("ft/s2", "foot per second squared", div(ft, s2));
8
- export const rad_s2 = defUnit("rad/s2", "radian per second squared", div(rad, s2));
9
- export const g0 = defUnit("g0", "standard gravity", mul(m_s2, 9.80665));
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
- export const rad = defUnit("rad", "radian", dimensionless(1, 0, true));
4
- export const deg = defUnit("deg", "degree", mul(rad, PI / 180));
5
- export const gon = defUnit("gon", "gradian", mul(rad, PI / 200));
6
- export const turn = defUnit("turn", "turn", mul(rad, 2 * PI));
7
- export const arcmin = defUnit("arcmin", "arc minute", mul(rad, PI / 10800));
8
- export const arcsec = defUnit("arcsec", "arc second", mul(rad, PI / 648000));
9
- export const sr = defUnit("sr", "steradian", dimensionless(1, 0, true));
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
- export const m2 = defUnit("m2", "square meter", pow(m, 2));
4
- export const mm2 = defUnit("mm2", "square millimeter", pow(mm, 2));
5
- export const cm2 = defUnit("cm2", "square centimeter", pow(cm, 2));
6
- export const km2 = defUnit("km2", "square kilometer", pow(km, 2));
7
- export const ha = defUnit("ha", "hectar", mul(m2, 1e4));
8
- export const ac = defUnit("ac", "acre", mul(m2, 4046.86));
9
- export const sqin = defUnit("sqin", "square inch", pow(inch, 2));
10
- export const sqft = defUnit("sqft", "square foot", pow(ft, 2));
11
- export const sqmi = defUnit("sqmi", "square mile", pow(mi, 2));
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
- export const bit = defUnit("bit", "bit", dimensionless(1, 0, true));
3
- export const kbit = defUnit("kbit", "kilobit", prefix("k", bit));
4
- export const Mbit = defUnit("Mbit", "megabit", prefix("M", bit));
5
- export const Gbit = defUnit("Gbit", "gigabit", prefix("G", bit));
6
- export const Tbit = defUnit("Tbit", "terabit", prefix("T", bit));
7
- export const B = defUnit("B", "byte", mul(bit, 8, true));
8
- export const kB = defUnit("kB", "kilobyte", prefix("k", B));
9
- export const MB = defUnit("MB", "megabyte", prefix("M", B));
10
- export const GB = defUnit("GB", "gigabyte", prefix("G", B));
11
- export const TB = defUnit("TB", "terabyte", prefix("T", B));
12
- export const PB = defUnit("PB", "petabyte", prefix("P", B));
13
- export const EB = defUnit("EB", "exabyte", prefix("E", B));
14
- // https://en.wikipedia.org/wiki/Byte#Multiple-byte_units
15
- export const Kibit = defUnit("Kibit", "kibibit", mul(bit, 1024));
16
- export const Mibit = defUnit("Mibit", "mebibit", mul(Kibit, 1024));
17
- export const Gibit = defUnit("Gibit", "gibibit", mul(Mibit, 1024));
18
- export const Tibit = defUnit("Tibit", "tebibit", mul(Gibit, 1024));
19
- export const Pibit = defUnit("Pibit", "pebibit", mul(Tibit, 1024));
20
- export const Eibit = defUnit("Eibit", "exbibit", mul(Pibit, 1024));
21
- export const KiB = defUnit("KiB", "kibibyte", mul(B, 1024));
22
- export const MiB = defUnit("MiB", "mebibyte", mul(KiB, 1024));
23
- export const GiB = defUnit("GiB", "gibibyte", mul(MiB, 1024));
24
- export const TiB = defUnit("TiB", "tebibyte", mul(GiB, 1024));
25
- export const PiB = defUnit("PiB", "pebibyte", mul(TiB, 1024));
26
- export const EiB = defUnit("EiB", "exbibyte", mul(PiB, 1024));
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
- export const kg_m3 = defUnit("kg/m3", "kilogram per cubic meter", div(kg, m3));
6
- export const dpi = defUnit("dpi", "dots per inch", reciprocal(inch));
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
+ };