@thi.ng/units 0.4.33 → 0.4.35
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 +21 -12
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
<!-- This file is generated - DO NOT EDIT! -->
|
|
2
2
|
<!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
|
|
3
|
-
> [!IMPORTANT]
|
|
4
|
-
> ‼️ Announcing the thi.ng user survey 2024 📋
|
|
5
|
-
>
|
|
6
|
-
> [Please participate in the survey here!](https://forms.gle/XacbSDEmQMPZg8197)\
|
|
7
|
-
> (open until end of February)
|
|
8
|
-
>
|
|
9
|
-
> **To achieve a better sample size, I'd highly appreciate if you could
|
|
10
|
-
> circulate the link to this survey in your own networks.**
|
|
11
|
-
>
|
|
12
|
-
> [Discussion](https://github.com/thi-ng/umbrella/discussions/447)
|
|
13
|
-
|
|
14
3
|
# 
|
|
15
4
|
|
|
16
5
|
[](https://www.npmjs.com/package/@thi.ng/units)
|
|
@@ -22,7 +11,7 @@
|
|
|
22
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
23
12
|
> and anti-framework.
|
|
24
13
|
>
|
|
25
|
-
> 🚀
|
|
14
|
+
> 🚀 Please help me to work full-time on these projects by [sponsoring me on
|
|
26
15
|
> GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
|
|
27
16
|
|
|
28
17
|
- [About](#about)
|
|
@@ -104,6 +93,8 @@ most dimensions' base units usually using a factor of 1 and no offset.
|
|
|
104
93
|
For example, here's how we can define kilograms and meters:
|
|
105
94
|
|
|
106
95
|
```ts
|
|
96
|
+
import { coherent, unit } from "@thi.ng/units";
|
|
97
|
+
|
|
107
98
|
// kilogram, SI dimension 0
|
|
108
99
|
const KG = coherent(0);
|
|
109
100
|
// { dim: [ 1, 0, 0, 0, 0, 0, 0 ], scale: 1, offset: 0, coherent: true }
|
|
@@ -125,6 +116,8 @@ More complex units like electrical resistance (e.g. ohm) are based on more than
|
|
|
125
116
|
a single dimension:
|
|
126
117
|
|
|
127
118
|
```ts
|
|
119
|
+
import { div, A, V } from "@thi.ng/units";
|
|
120
|
+
|
|
128
121
|
// ohm = volt / ampere
|
|
129
122
|
div(V, A)
|
|
130
123
|
// { dim: [ 1, 2, -3, -2, 0, 0, 0 ], scale: 1, offset: 0, coherent: true }
|
|
@@ -140,6 +133,8 @@ Btw. The
|
|
|
140
133
|
function can be used to format a unit's dimension vector:
|
|
141
134
|
|
|
142
135
|
```ts
|
|
136
|
+
import { div, formatSI, A, V } from "@thi.ng/units";
|
|
137
|
+
|
|
143
138
|
formatSI(div(V, A));
|
|
144
139
|
// "kg·m2·s-3·A-2"
|
|
145
140
|
```
|
|
@@ -422,6 +417,8 @@ Existing coherent units can be
|
|
|
422
417
|
produce derived versions:
|
|
423
418
|
|
|
424
419
|
```ts
|
|
420
|
+
import { prefix, Hz } from "@thi.ng/units";
|
|
421
|
+
|
|
425
422
|
// define micrometer (also available as preset)
|
|
426
423
|
prefix("µ", "m")
|
|
427
424
|
// { dim: [ 0, 1, 0, 0, 0, 0, 0 ], scale: 0.000001, offset: 0, coherent: false }
|
|
@@ -446,6 +443,8 @@ The following combinators can be used to derive scaled and/or more complex units
|
|
|
446
443
|
Creates reciprocal of given unit (e.g. Hz ⇒ 1/second)
|
|
447
444
|
|
|
448
445
|
```ts
|
|
446
|
+
import { div, mul, pow, prefix, reciprocal, bit, m, s } from "@thi.ng/units";
|
|
447
|
+
|
|
449
448
|
// acceleration (meter per second squared)
|
|
450
449
|
const m_s2 = div(m, pow(s, 2));
|
|
451
450
|
// { dim: [ 0, 1, -2, 0, 0, 0, 0 ], scale: 1, offset: 0, coherent: false }
|
|
@@ -475,6 +474,8 @@ nonsense).
|
|
|
475
474
|
Units can be specified in various ways:
|
|
476
475
|
|
|
477
476
|
```ts
|
|
477
|
+
import { convert, div, reciprocal, h, km_h, mph, yd } from "@thi.ng/units";
|
|
478
|
+
|
|
478
479
|
// convert from km/h to mph using unit names
|
|
479
480
|
convert(100, "km/h", "mph");
|
|
480
481
|
// 62.13711922373341
|
|
@@ -496,6 +497,8 @@ Another example using dimensionless units (here angles, arc second ⇒ radian) t
|
|
|
496
497
|
compute the distance of 10 arcsec on the earth surface (in meters):
|
|
497
498
|
|
|
498
499
|
```ts
|
|
500
|
+
import { convert, R } from "@thi.ng/units";
|
|
501
|
+
|
|
499
502
|
// earth radius in meters
|
|
500
503
|
// (also available as quantity EARTH_RADIUS, see section below)
|
|
501
504
|
const R = 6371000;
|
|
@@ -520,6 +523,8 @@ Quantities are created via
|
|
|
520
523
|
quantities). Use [`convert()`](#unit-conversions) otherwise!
|
|
521
524
|
|
|
522
525
|
```ts
|
|
526
|
+
import { convert, div, quantity } from "@thi.ng/units";
|
|
527
|
+
|
|
523
528
|
// (also available as preset)
|
|
524
529
|
const speedOfLight = quantity(299792458, "m/s");
|
|
525
530
|
|
|
@@ -531,6 +536,8 @@ convert(div(speedOfLight, quantity(2.4,"GHz")), "mm");
|
|
|
531
536
|
Some examples using vector quantities:
|
|
532
537
|
|
|
533
538
|
```ts
|
|
539
|
+
import { convert, mul, quantity, NONE } from "@thi.ng/units";
|
|
540
|
+
|
|
534
541
|
// DIN A4 paper size (also available as preset)
|
|
535
542
|
const A4 = quantity([210, 297], "mm");
|
|
536
543
|
|
|
@@ -552,6 +559,8 @@ mul(A4, quantity(300, "dpi")).deref()
|
|
|
552
559
|
When combining different quantities, their units do not need to be the same:
|
|
553
560
|
|
|
554
561
|
```ts
|
|
562
|
+
import { convert, mul, quantity } from "@thi.ng/units";
|
|
563
|
+
|
|
555
564
|
// compute 10 mm x 2 inch and convert to square centimeter
|
|
556
565
|
convert(mul(quantity(10, "mm"), quantity(2, "in")), "cm2")
|
|
557
566
|
// 5.08
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/units",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.35",
|
|
4
4
|
"description": "Extensible SI unit creation, conversions, quantities & calculations (incl. ~170 predefined units & constants)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"test": "bun test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.9.
|
|
39
|
-
"@thi.ng/checks": "^3.5.
|
|
40
|
-
"@thi.ng/equiv": "^2.1.
|
|
41
|
-
"@thi.ng/errors": "^2.4.
|
|
38
|
+
"@thi.ng/api": "^8.9.27",
|
|
39
|
+
"@thi.ng/checks": "^3.5.1",
|
|
40
|
+
"@thi.ng/equiv": "^2.1.50",
|
|
41
|
+
"@thi.ng/errors": "^2.4.19"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@microsoft/api-extractor": "^7.40.1",
|
|
@@ -179,5 +179,5 @@
|
|
|
179
179
|
"status": "beta",
|
|
180
180
|
"year": 2021
|
|
181
181
|
},
|
|
182
|
-
"gitHead": "
|
|
182
|
+
"gitHead": "df9e312af741d87e6b450afcfea6a6e381662b1e\n"
|
|
183
183
|
}
|