@thi.ng/units 0.2.0 → 0.3.1
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 +7 -1
- package/README.md +63 -21
- package/constants/densities.d.ts +25 -0
- package/constants/densities.js +28 -0
- package/constants/din-sizes.js +1 -0
- package/constants/earth.d.ts +33 -0
- package/constants/earth.js +35 -0
- package/constants/velocities.d.ts +3 -0
- package/constants/velocities.js +3 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-03-
|
|
3
|
+
- **Last updated**: 2023-03-16T11:22:27Z
|
|
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.
|
|
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/units@0.3.0) (2023-03-16)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add more quantities/constants ([27cd71e](https://github.com/thi-ng/umbrella/commit/27cd71e))
|
|
17
|
+
|
|
12
18
|
## [0.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/units@0.2.0) (2023-03-15)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ This project is part of the
|
|
|
16
16
|
- [Angle](#angle)
|
|
17
17
|
- [Area](#area)
|
|
18
18
|
- [Data](#data)
|
|
19
|
+
- [Density](#density)
|
|
19
20
|
- [Electric current](#electric-current)
|
|
20
21
|
- [Energy](#energy)
|
|
21
22
|
- [Force](#force)
|
|
@@ -88,7 +89,7 @@ For example, here's how we can define kilograms and meters:
|
|
|
88
89
|
|
|
89
90
|
```ts
|
|
90
91
|
// kilogram, SI dimension 0
|
|
91
|
-
const KG = coherent(
|
|
92
|
+
const KG = coherent(0);
|
|
92
93
|
// { dim: [ 1, 0, 0, 0, 0, 0, 0 ], scale: 1, offset: 0, coherent: true }
|
|
93
94
|
|
|
94
95
|
// meters, SI dimension 1
|
|
@@ -193,6 +194,13 @@ The following units are provided as "builtins", here grouped by dimension:
|
|
|
193
194
|
| `PiB` | `PiB` | pebibyte (1024) |
|
|
194
195
|
| `EiB` | `EiB` | exbibyte (1024) |
|
|
195
196
|
|
|
197
|
+
#### Density
|
|
198
|
+
|
|
199
|
+
| Unit | Variable name | Description |
|
|
200
|
+
|----------|---------------|---------------|
|
|
201
|
+
| `kg/m3` | `kg_m3` | density |
|
|
202
|
+
| `1/inch` | `dpi` | dots per inch |
|
|
203
|
+
|
|
196
204
|
#### Electric current
|
|
197
205
|
|
|
198
206
|
| Unit | Variable name | Description |
|
|
@@ -296,15 +304,15 @@ The following units are provided as "builtins", here grouped by dimension:
|
|
|
296
304
|
|
|
297
305
|
https://en.wikipedia.org/wiki/Parts-per_notation
|
|
298
306
|
|
|
299
|
-
| Unit name | Variable name | Description
|
|
300
|
-
|
|
301
|
-
| `%` | `percent` | part per hundred
|
|
302
|
-
| `‰` | `permille` | part per thousand
|
|
303
|
-
| `‱` | `permyriad` | part per ten thousand
|
|
304
|
-
| `pcm` | `pcm` | part per
|
|
305
|
-
| `ppm` | `ppm` | part per million
|
|
306
|
-
| `ppb` | `ppb` | part per billion
|
|
307
|
-
| `ppt` | `ppt` | part per trillion
|
|
307
|
+
| Unit name | Variable name | Description |
|
|
308
|
+
|-----------|---------------|---------------------------|
|
|
309
|
+
| `%` | `percent` | part per hundred |
|
|
310
|
+
| `‰` | `permille` | part per thousand |
|
|
311
|
+
| `‱` | `permyriad` | part per ten thousand |
|
|
312
|
+
| `pcm` | `pcm` | part per hundred thousand |
|
|
313
|
+
| `ppm` | `ppm` | part per million |
|
|
314
|
+
| `ppb` | `ppb` | part per billion |
|
|
315
|
+
| `ppt` | `ppt` | part per trillion |
|
|
308
316
|
|
|
309
317
|
#### Power
|
|
310
318
|
|
|
@@ -472,7 +480,9 @@ Another example using dimensionless units (here angles, arc second ⇒ radian) t
|
|
|
472
480
|
compute the distance of 10 arcsec on the earth surface (in meters):
|
|
473
481
|
|
|
474
482
|
```ts
|
|
475
|
-
|
|
483
|
+
// earth radius in meters
|
|
484
|
+
// (also available as quantity EARTH_RADIUS, see section below)
|
|
485
|
+
const R = 6371000;
|
|
476
486
|
|
|
477
487
|
convert(10, "arcsec", "rad") * R;
|
|
478
488
|
// 308.87479623488537
|
|
@@ -487,7 +497,7 @@ calculations & conversions using the above mentioned polymorphic functions:
|
|
|
487
497
|
|
|
488
498
|
Quantities are created via
|
|
489
499
|
[`quantity()`](https://docs.thi.ng/umbrella/units/functions/quantity-1.html)
|
|
490
|
-
which acts
|
|
500
|
+
which acts as factory function for a thin `Quantity` class wrapper. The latter
|
|
491
501
|
also implements the standard
|
|
492
502
|
[`IDeref`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html) interface
|
|
493
503
|
to obtain the unwrapped amount (though it only should be used for dimensionless
|
|
@@ -502,6 +512,8 @@ convert(div(speedOfLight, quantity(2.4,"GHz")), "mm");
|
|
|
502
512
|
// 124.9135
|
|
503
513
|
```
|
|
504
514
|
|
|
515
|
+
Some examples using vector quantities:
|
|
516
|
+
|
|
505
517
|
```ts
|
|
506
518
|
// DIN A4 paper size (also available as preset)
|
|
507
519
|
const A4 = quantity([210, 297], "mm");
|
|
@@ -511,12 +523,12 @@ convert(A4, "in");
|
|
|
511
523
|
// [ 8.2677, 11.6929 ]
|
|
512
524
|
|
|
513
525
|
// or calculate pixel dimensions @ 300 dpi
|
|
514
|
-
// the result of
|
|
526
|
+
// the result of this product is dimensionless,
|
|
515
527
|
// so we use the NONE preset as target unit...
|
|
516
528
|
convert(mul(A4, quantity(300, "dpi")), NONE)
|
|
517
529
|
// [ 2480.314960629921, 3507.8740157480315 ]
|
|
518
530
|
|
|
519
|
-
// alternatively dimensionless units can be deref'd directly
|
|
531
|
+
// alternatively, dimensionless units can be deref'd directly
|
|
520
532
|
mul(A4, quantity(300, "dpi")).deref()
|
|
521
533
|
// [ 2480.314960629921, 3507.8740157480315 ]
|
|
522
534
|
```
|
|
@@ -533,12 +545,42 @@ convert(mul(quantity(10, "mm"), quantity(2, "in")), "cm2")
|
|
|
533
545
|
|
|
534
546
|
The following constants are provided (more to come):
|
|
535
547
|
|
|
536
|
-
| Var name | Unit
|
|
537
|
-
|
|
538
|
-
| `DIN_A0` ... `DIN_A8` | `
|
|
539
|
-
| `
|
|
540
|
-
| `
|
|
541
|
-
| `
|
|
548
|
+
| Var name | Unit | Comment |
|
|
549
|
+
|---------------------------|-------------------|------------------------|
|
|
550
|
+
| `DIN_A0` ... `DIN_A8` | 2d vector of `mm` | Paper sizes |
|
|
551
|
+
| `EARTH_GRAVITY` | `m/s` | |
|
|
552
|
+
| `EARTH_CIRCUMFERENCE` | `m` | |
|
|
553
|
+
| `EARTH_MASS` | `kg` | |
|
|
554
|
+
| `EARTH_RADIUS` | `m` | |
|
|
555
|
+
| `GRAVITATION` | `kg-1·m3·s-2` | Gravitational constant |
|
|
556
|
+
| `SPEED_OF_LIGHT` | `m/s` | |
|
|
557
|
+
| `SPEED_OF_SOUND_IN_AIR` | `m/s` | at 20 ℃ |
|
|
558
|
+
| `SPEED_OF_SOUND_IN_WATER` | `m/s` | at 20 ℃ |
|
|
559
|
+
|
|
560
|
+
Densities of selected materials:
|
|
561
|
+
|
|
562
|
+
| Var name | Unit |
|
|
563
|
+
|--------------|---------|
|
|
564
|
+
| `AIR` | `kg/m3` |
|
|
565
|
+
| `ALUMINIUM` | `kg/m3` |
|
|
566
|
+
| `CONCRETE` | `kg/m3` |
|
|
567
|
+
| `COPPER` | `kg/m3` |
|
|
568
|
+
| `DIAMOND` | `kg/m3` |
|
|
569
|
+
| `GLASS` | `kg/m3` |
|
|
570
|
+
| `GOLD` | `kg/m3` |
|
|
571
|
+
| `ICE` | `kg/m3` |
|
|
572
|
+
| `IRON` | `kg/m3` |
|
|
573
|
+
| `NYLON` | `kg/m3` |
|
|
574
|
+
| `PLASTIC` | `kg/m3` |
|
|
575
|
+
| `PLATINUM` | `kg/m3` |
|
|
576
|
+
| `SAND` | `kg/m3` |
|
|
577
|
+
| `SALT_WATER` | `kg/m3` |
|
|
578
|
+
| `SILICON` | `kg/m3` |
|
|
579
|
+
| `SILVER` | `kg/m3` |
|
|
580
|
+
| `STEEL` | `kg/m3` |
|
|
581
|
+
| `TITANIUM` | `kg/m3` |
|
|
582
|
+
| `WATER` | `kg/m3` |
|
|
583
|
+
| `WOOD` | `kg/m3` |
|
|
542
584
|
|
|
543
585
|
## Status
|
|
544
586
|
|
|
@@ -566,7 +608,7 @@ For Node.js REPL:
|
|
|
566
608
|
const units = await import("@thi.ng/units");
|
|
567
609
|
```
|
|
568
610
|
|
|
569
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 4.
|
|
611
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 4.37 KB
|
|
570
612
|
|
|
571
613
|
## Dependencies
|
|
572
614
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const AIR: import("../unit.js").Quantity<1.2>;
|
|
2
|
+
export declare const ALUMINIUM: import("../unit.js").Quantity<2700>;
|
|
3
|
+
export declare const ALUMINUM: import("../unit.js").Quantity<2700>;
|
|
4
|
+
export declare const CONCRETE: import("../unit.js").Quantity<2400>;
|
|
5
|
+
export declare const COPPER: import("../unit.js").Quantity<8940>;
|
|
6
|
+
export declare const DIAMOND: import("../unit.js").Quantity<3500>;
|
|
7
|
+
export declare const GLASS: import("../unit.js").Quantity<2500>;
|
|
8
|
+
export declare const GOLD: import("../unit.js").Quantity<19320>;
|
|
9
|
+
export declare const ICE: import("../unit.js").Quantity<916.7>;
|
|
10
|
+
export declare const IRON: import("../unit.js").Quantity<7870>;
|
|
11
|
+
export declare const NYLON: import("../unit.js").Quantity<1150>;
|
|
12
|
+
export declare const PLASTIC: import("../unit.js").Quantity<1175>;
|
|
13
|
+
export declare const PLATINUM: import("../unit.js").Quantity<21450>;
|
|
14
|
+
export declare const SAND: import("../unit.js").Quantity<1600>;
|
|
15
|
+
export declare const SALT_WATER: import("../unit.js").Quantity<1030>;
|
|
16
|
+
export declare const SILICON: import("../unit.js").Quantity<2330>;
|
|
17
|
+
export declare const SILVER: import("../unit.js").Quantity<10500>;
|
|
18
|
+
export declare const STEEL: import("../unit.js").Quantity<7850>;
|
|
19
|
+
export declare const TITANIUM: import("../unit.js").Quantity<4540>;
|
|
20
|
+
/**
|
|
21
|
+
* Fresh water @ 4 degree celsius (max. density)
|
|
22
|
+
*/
|
|
23
|
+
export declare const WATER: import("../unit.js").Quantity<1000>;
|
|
24
|
+
export declare const WOOD: import("../unit.js").Quantity<700>;
|
|
25
|
+
//# sourceMappingURL=densities.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { quantity } from "../unit.js";
|
|
2
|
+
import { kg_m3 } from "../units/density.js";
|
|
3
|
+
// https://en.wikipedia.org/wiki/Density#Various_materials
|
|
4
|
+
export const AIR = quantity(1.2, kg_m3);
|
|
5
|
+
export const ALUMINIUM = quantity(2700, kg_m3);
|
|
6
|
+
// for americans...
|
|
7
|
+
export const ALUMINUM = ALUMINIUM;
|
|
8
|
+
export const CONCRETE = quantity(2400, kg_m3);
|
|
9
|
+
export const COPPER = quantity(8940, kg_m3);
|
|
10
|
+
export const DIAMOND = quantity(3500, kg_m3);
|
|
11
|
+
export const GLASS = quantity(2500, kg_m3);
|
|
12
|
+
export const GOLD = quantity(19320, kg_m3);
|
|
13
|
+
export const ICE = quantity(916.7, kg_m3);
|
|
14
|
+
export const IRON = quantity(7870, kg_m3);
|
|
15
|
+
export const NYLON = quantity(1150, kg_m3);
|
|
16
|
+
export const PLASTIC = quantity(1175, kg_m3);
|
|
17
|
+
export const PLATINUM = quantity(21450, kg_m3);
|
|
18
|
+
export const SAND = quantity(1600, kg_m3);
|
|
19
|
+
export const SALT_WATER = quantity(1030, kg_m3);
|
|
20
|
+
export const SILICON = quantity(2330, kg_m3);
|
|
21
|
+
export const SILVER = quantity(10500, kg_m3);
|
|
22
|
+
export const STEEL = quantity(7850, kg_m3);
|
|
23
|
+
export const TITANIUM = quantity(4540, kg_m3);
|
|
24
|
+
/**
|
|
25
|
+
* Fresh water @ 4 degree celsius (max. density)
|
|
26
|
+
*/
|
|
27
|
+
export const WATER = quantity(1000, kg_m3);
|
|
28
|
+
export const WOOD = quantity(700, kg_m3);
|
package/constants/din-sizes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mm } from "../units/length.js";
|
|
2
2
|
import { quantity } from "../unit.js";
|
|
3
|
+
// https://en.wikipedia.org/wiki/ISO_216x
|
|
3
4
|
export const DIN_A0 = quantity([841, 1189], mm);
|
|
4
5
|
export const DIN_A1 = quantity([594, 841], mm);
|
|
5
6
|
export const DIN_A2 = quantity([420, 594], mm);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://en.wikipedia.org/wiki/Earth_radius
|
|
3
|
+
*/
|
|
4
|
+
export declare const EARTH_RADIUS: import("../unit.js").Quantity<6371000>;
|
|
5
|
+
/**
|
|
6
|
+
* At equator
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Reference:
|
|
10
|
+
* - https://en.wikipedia.org/wiki/Earth%27s_circumference
|
|
11
|
+
*/
|
|
12
|
+
export declare const EARTH_CIRCUMFERENCE: import("../unit.js").Quantity<40075017>;
|
|
13
|
+
/**
|
|
14
|
+
* Using equatorial mean as alternative to {@link g0}.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Reference:
|
|
18
|
+
* - https://en.wikipedia.org/wiki/Gravity_of_Earth
|
|
19
|
+
*/
|
|
20
|
+
export declare const EARTH_GRAVITY: import("../unit.js").Quantity<9.78033>;
|
|
21
|
+
/**
|
|
22
|
+
* https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
|
|
23
|
+
*/
|
|
24
|
+
export declare const EARTH_MASS: import("../unit.js").Quantity<5.9722e+24>;
|
|
25
|
+
/**
|
|
26
|
+
* Gravitational constant (kg-1·m3·s-2)
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* Reference:
|
|
30
|
+
* - https://en.wikipedia.org/wiki/Gravitational_constant
|
|
31
|
+
*/
|
|
32
|
+
export declare const GRAVITATION: import("../unit.js").Quantity<6.6743e-11>;
|
|
33
|
+
//# sourceMappingURL=earth.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { quantity, unit } from "../unit.js";
|
|
2
|
+
import { m_s2 } from "../units/accel.js";
|
|
3
|
+
import { m } from "../units/length.js";
|
|
4
|
+
/**
|
|
5
|
+
* https://en.wikipedia.org/wiki/Earth_radius
|
|
6
|
+
*/
|
|
7
|
+
export const EARTH_RADIUS = quantity(6371000, m);
|
|
8
|
+
/**
|
|
9
|
+
* At equator
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Reference:
|
|
13
|
+
* - https://en.wikipedia.org/wiki/Earth%27s_circumference
|
|
14
|
+
*/
|
|
15
|
+
export const EARTH_CIRCUMFERENCE = quantity(40075017, m);
|
|
16
|
+
/**
|
|
17
|
+
* Using equatorial mean as alternative to {@link g0}.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Reference:
|
|
21
|
+
* - https://en.wikipedia.org/wiki/Gravity_of_Earth
|
|
22
|
+
*/
|
|
23
|
+
export const EARTH_GRAVITY = quantity(9.78033, m_s2);
|
|
24
|
+
/**
|
|
25
|
+
* https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
|
|
26
|
+
*/
|
|
27
|
+
export const EARTH_MASS = quantity(5.9722e24, "kg");
|
|
28
|
+
/**
|
|
29
|
+
* Gravitational constant (kg-1·m3·s-2)
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Reference:
|
|
33
|
+
* - https://en.wikipedia.org/wiki/Gravitational_constant
|
|
34
|
+
*/
|
|
35
|
+
export const GRAVITATION = quantity(6.6743e-11, unit([-1, 3, -2, 0, 0, 0, 0], 1));
|
package/constants/velocities.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export * from "./units/temperature.js";
|
|
|
20
20
|
export * from "./units/time.js";
|
|
21
21
|
export * from "./units/velocity.js";
|
|
22
22
|
export * from "./units/volume.js";
|
|
23
|
+
export * from "./constants/densities.js";
|
|
23
24
|
export * from "./constants/din-sizes.js";
|
|
25
|
+
export * from "./constants/earth.js";
|
|
24
26
|
export * from "./constants/velocities.js";
|
|
25
27
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -20,5 +20,7 @@ export * from "./units/temperature.js";
|
|
|
20
20
|
export * from "./units/time.js";
|
|
21
21
|
export * from "./units/velocity.js";
|
|
22
22
|
export * from "./units/volume.js";
|
|
23
|
+
export * from "./constants/densities.js";
|
|
23
24
|
export * from "./constants/din-sizes.js";
|
|
25
|
+
export * from "./constants/earth.js";
|
|
24
26
|
export * from "./constants/velocities.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/units",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Extensible SI unit creation, conversions, quantities & calculations (incl. ~170 predefined units & constants)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -99,9 +99,15 @@
|
|
|
99
99
|
"./api": {
|
|
100
100
|
"default": "./api.js"
|
|
101
101
|
},
|
|
102
|
+
"./constants/densities": {
|
|
103
|
+
"default": "./constants/densities.js"
|
|
104
|
+
},
|
|
102
105
|
"./constants/din-sizes": {
|
|
103
106
|
"default": "./constants/din-sizes.js"
|
|
104
107
|
},
|
|
108
|
+
"./constants/earth": {
|
|
109
|
+
"default": "./constants/earth.js"
|
|
110
|
+
},
|
|
105
111
|
"./constants/velocities": {
|
|
106
112
|
"default": "./constants/velocities.js"
|
|
107
113
|
},
|
|
@@ -173,5 +179,5 @@
|
|
|
173
179
|
"status": "beta",
|
|
174
180
|
"year": 2021
|
|
175
181
|
},
|
|
176
|
-
"gitHead": "
|
|
182
|
+
"gitHead": "f493d89d81d450ca67adf4f574b08840cba87807\n"
|
|
177
183
|
}
|