@thi.ng/units 0.4.45 → 0.4.46

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +10 -10
  3. package/unit.js +10 -20
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-23T07:02:19Z
3
+ - **Last updated**: 2024-05-08T18:24:32Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/units",
3
- "version": "0.4.45",
3
+ "version": "0.4.46",
4
4
  "description": "Extensible SI unit creation, conversions, quantities & calculations (incl. ~170 predefined units & constants)",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -36,16 +36,16 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.1",
40
- "@thi.ng/checks": "^3.6.3",
41
- "@thi.ng/equiv": "^2.1.57",
42
- "@thi.ng/errors": "^2.5.6"
39
+ "@thi.ng/api": "^8.11.2",
40
+ "@thi.ng/checks": "^3.6.4",
41
+ "@thi.ng/equiv": "^2.1.58",
42
+ "@thi.ng/errors": "^2.5.7"
43
43
  },
44
44
  "devDependencies": {
45
- "@microsoft/api-extractor": "^7.43.0",
46
- "esbuild": "^0.20.2",
47
- "typedoc": "^0.25.12",
48
- "typescript": "^5.4.3"
45
+ "@microsoft/api-extractor": "^7.43.2",
46
+ "esbuild": "^0.21.1",
47
+ "typedoc": "^0.25.13",
48
+ "typescript": "^5.4.5"
49
49
  },
50
50
  "keywords": [
51
51
  "acceleration",
@@ -179,5 +179,5 @@
179
179
  "status": "beta",
180
180
  "year": 2021
181
181
  },
182
- "gitHead": "5dd66c18a3862a3af69a5b2f49563f7cbdd960c2\n"
182
+ "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
183
183
  }
package/unit.js CHANGED
@@ -18,8 +18,7 @@ const unit = (dim, scale, offset = 0, coherent2 = false) => ({
18
18
  const coherent = (dim) => unit(dim, 1, 0, true);
19
19
  const dimensionless = (scale, offset = 0, coherent2 = false) => unit(NONE.dim, scale, offset, coherent2);
20
20
  const defUnit = (sym, name, unit2, force = false) => {
21
- if (UNITS[sym] && !force)
22
- illegalArgs(`attempt to override unit: ${sym}`);
21
+ if (UNITS[sym] && !force) illegalArgs(`attempt to override unit: ${sym}`);
23
22
  return UNITS[sym] = { ...unit2, sym, name };
24
23
  };
25
24
  const asUnit = (id) => {
@@ -31,8 +30,7 @@ const asUnit = (id) => {
31
30
  }
32
31
  }
33
32
  for (let u in UNITS) {
34
- if (UNITS[u].name === id)
35
- return UNITS[u];
33
+ if (UNITS[u].name === id) return UNITS[u];
36
34
  }
37
35
  illegalArgs(`unknown unit: ${id}`);
38
36
  };
@@ -52,11 +50,9 @@ const quantity = (value, unit2) => new Quantity(
52
50
  isNumber(value) ? mul(unit2, value) : value.map((x) => mul(unit2, x))
53
51
  );
54
52
  function mul(a, b, coherent2 = false) {
55
- if (a instanceof Quantity)
56
- return __combineQ(mul, a, b);
53
+ if (a instanceof Quantity) return __combineQ(mul, a, b);
57
54
  const $a = __ensureUnit(a);
58
- if (isNumber(b))
59
- return unit($a.dim, $a.scale * b, $a.offset, coherent2);
55
+ if (isNumber(b)) return unit($a.dim, $a.scale * b, $a.offset, coherent2);
60
56
  const $b = __ensureUnit(b);
61
57
  return unit(
62
58
  $a.dim.map((x, i) => x + $b.dim[i]),
@@ -66,8 +62,7 @@ function mul(a, b, coherent2 = false) {
66
62
  );
67
63
  }
68
64
  function div(a, b, coherent2 = false) {
69
- if (a instanceof Quantity)
70
- return __combineQ(div, a, b);
65
+ if (a instanceof Quantity) return __combineQ(div, a, b);
71
66
  const $a = __ensureUnit(a);
72
67
  if (isNumber(b)) {
73
68
  return unit($a.dim, $a.scale / b, $a.offset, coherent2);
@@ -107,8 +102,7 @@ function convert(x, a, b) {
107
102
  return (xnorm - $dest.offset) / $dest.scale;
108
103
  }
109
104
  const isConvertible = (src, dest) => {
110
- if (src instanceof Quantity)
111
- return isConvertible(__qunit(src), dest);
105
+ if (src instanceof Quantity) return isConvertible(__qunit(src), dest);
112
106
  const $src = __ensureUnit(src);
113
107
  const $dest = __ensureUnit(dest);
114
108
  return isReciprocal($src, $dest) || equivArrayLike($src.dim, $dest.dim);
@@ -121,24 +115,20 @@ const isReciprocal = (a, b) => {
121
115
  for (let i = 0; i < 7; i++) {
122
116
  const xa = $a[i];
123
117
  const xb = $b[i];
124
- if (xa === 0 && xb === 0)
125
- continue;
126
- if (xa !== -xb)
127
- return false;
118
+ if (xa === 0 && xb === 0) continue;
119
+ if (xa !== -xb) return false;
128
120
  ok = true;
129
121
  }
130
122
  return ok;
131
123
  };
132
124
  const formatSI = (u) => {
133
- if (u instanceof Quantity)
134
- return formatSI(__qunit(u));
125
+ if (u instanceof Quantity) return formatSI(__qunit(u));
135
126
  const { dim } = __ensureUnit(u);
136
127
  const SI = ["kg", "m", "s", "A", "K", "mol", "cd"];
137
128
  const acc = [];
138
129
  for (let i = 0; i < 7; i++) {
139
130
  const x = dim[i];
140
- if (x !== 0)
141
- acc.push(SI[i] + (x !== 1 ? x : ""));
131
+ if (x !== 0) acc.push(SI[i] + (x !== 1 ? x : ""));
142
132
  }
143
133
  return acc.length ? acc.join("\xB7") : "<dimensionless>";
144
134
  };