@thi.ng/units 0.2.0 → 0.3.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-03-15T14:55:07Z
3
+ - **Last updated**: 2023-03-16T08:47:43Z
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
@@ -88,7 +88,7 @@ For example, here's how we can define kilograms and meters:
88
88
 
89
89
  ```ts
90
90
  // kilogram, SI dimension 0
91
- const KG = coherent(1);
91
+ const KG = coherent(0);
92
92
  // { dim: [ 1, 0, 0, 0, 0, 0, 0 ], scale: 1, offset: 0, coherent: true }
93
93
 
94
94
  // meters, SI dimension 1
@@ -296,15 +296,15 @@ The following units are provided as "builtins", here grouped by dimension:
296
296
 
297
297
  https://en.wikipedia.org/wiki/Parts-per_notation
298
298
 
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 cent hundred thousand |
305
- | `ppm` | `ppm` | part per million |
306
- | `ppb` | `ppb` | part per billion |
307
- | `ppt` | `ppt` | part per trillion |
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 hundred thousand |
305
+ | `ppm` | `ppm` | part per million |
306
+ | `ppb` | `ppb` | part per billion |
307
+ | `ppt` | `ppt` | part per trillion |
308
308
 
309
309
  #### Power
310
310
 
@@ -472,7 +472,9 @@ Another example using dimensionless units (here angles, arc second ⇒ radian) t
472
472
  compute the distance of 10 arcsec on the earth surface (in meters):
473
473
 
474
474
  ```ts
475
- const R = 6371000; // earth radius in meters
475
+ // earth radius in meters
476
+ // (also available as quantity EARTH_RADIUS, see section below)
477
+ const R = 6371000;
476
478
 
477
479
  convert(10, "arcsec", "rad") * R;
478
480
  // 308.87479623488537
@@ -487,7 +489,7 @@ calculations & conversions using the above mentioned polymorphic functions:
487
489
 
488
490
  Quantities are created via
489
491
  [`quantity()`](https://docs.thi.ng/umbrella/units/functions/quantity-1.html)
490
- which acts a factory function for a thin `Quantity` class wrapper. The latter
492
+ which acts as factory function for a thin `Quantity` class wrapper. The latter
491
493
  also implements the standard
492
494
  [`IDeref`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html) interface
493
495
  to obtain the unwrapped amount (though it only should be used for dimensionless
@@ -502,6 +504,8 @@ convert(div(speedOfLight, quantity(2.4,"GHz")), "mm");
502
504
  // 124.9135
503
505
  ```
504
506
 
507
+ Some examples using vector quantities:
508
+
505
509
  ```ts
506
510
  // DIN A4 paper size (also available as preset)
507
511
  const A4 = quantity([210, 297], "mm");
@@ -511,12 +515,12 @@ convert(A4, "in");
511
515
  // [ 8.2677, 11.6929 ]
512
516
 
513
517
  // or calculate pixel dimensions @ 300 dpi
514
- // the result of the product is dimensionless
518
+ // the result of this product is dimensionless,
515
519
  // so we use the NONE preset as target unit...
516
520
  convert(mul(A4, quantity(300, "dpi")), NONE)
517
521
  // [ 2480.314960629921, 3507.8740157480315 ]
518
522
 
519
- // alternatively dimensionless units can be deref'd directly
523
+ // alternatively, dimensionless units can be deref'd directly
520
524
  mul(A4, quantity(300, "dpi")).deref()
521
525
  // [ 2480.314960629921, 3507.8740157480315 ]
522
526
  ```
@@ -533,12 +537,42 @@ convert(mul(quantity(10, "mm"), quantity(2, "in")), "cm2")
533
537
 
534
538
  The following constants are provided (more to come):
535
539
 
536
- | Var name | Unit |
537
- |---------------------------|----------------|
538
- | `DIN_A0` ... `DIN_A8` | `["mm", "mm"]` |
539
- | `SPEED_OF_LIGHT` | `"m/s"` |
540
- | `SPEED_OF_SOUND_IN_AIR` | `"m/s"` |
541
- | `SPEED_OF_SOUND_IN_WATER` | `"m/s"` |
540
+ | Var name | Unit | Comment |
541
+ |---------------------------|-------------------|------------------------|
542
+ | `DIN_A0` ... `DIN_A8` | 2d vector of `mm` | Paper sizes |
543
+ | `EARTH_GRAVITY` | `m/s` | |
544
+ | `EARTH_CIRCUMFERENCE` | `m` | |
545
+ | `EARTH_MASS` | `kg` | |
546
+ | `EARTH_RADIUS` | `m` | |
547
+ | `GRAVITATION` | `kg-1·m3·s-2` | Gravitational constant |
548
+ | `SPEED_OF_LIGHT` | `m/s` | |
549
+ | `SPEED_OF_SOUND_IN_AIR` | `m/s` | at 20 ℃ |
550
+ | `SPEED_OF_SOUND_IN_WATER` | `m/s` | at 20 ℃ |
551
+
552
+ Densities of selected materials:
553
+
554
+ | Var name | Unit |
555
+ |--------------|---------|
556
+ | `AIR` | `kg/m3` |
557
+ | `ALUMINIUM` | `kg/m3` |
558
+ | `CONCRETE` | `kg/m3` |
559
+ | `COPPER` | `kg/m3` |
560
+ | `DIAMOND` | `kg/m3` |
561
+ | `GLASS` | `kg/m3` |
562
+ | `GOLD` | `kg/m3` |
563
+ | `ICE` | `kg/m3` |
564
+ | `IRON` | `kg/m3` |
565
+ | `NYLON` | `kg/m3` |
566
+ | `PLASTIC` | `kg/m3` |
567
+ | `PLATINUM` | `kg/m3` |
568
+ | `SAND` | `kg/m3` |
569
+ | `SALT_WATER` | `kg/m3` |
570
+ | `SILICON` | `kg/m3` |
571
+ | `SILVER` | `kg/m3` |
572
+ | `STEEL` | `kg/m3` |
573
+ | `TITANIUM` | `kg/m3` |
574
+ | `WATER` | `kg/m3` |
575
+ | `WOOD` | `kg/m3` |
542
576
 
543
577
  ## Status
544
578
 
@@ -566,7 +600,7 @@ For Node.js REPL:
566
600
  const units = await import("@thi.ng/units");
567
601
  ```
568
602
 
569
- Package sizes (brotli'd, pre-treeshake): ESM: 4.05 KB
603
+ Package sizes (brotli'd, pre-treeshake): ESM: 4.37 KB
570
604
 
571
605
  ## Dependencies
572
606
 
@@ -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);
@@ -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));
@@ -1,3 +1,6 @@
1
+ /**
2
+ * https://en.wikipedia.org/wiki/Speed_of_light
3
+ */
1
4
  export declare const SPEED_OF_LIGHT: import("../unit.js").Quantity<299792458>;
2
5
  /**
3
6
  * At 20 degree celsius
@@ -1,5 +1,8 @@
1
1
  import { quantity } from "../unit.js";
2
2
  import { m_s } from "../units/velocity.js";
3
+ /**
4
+ * https://en.wikipedia.org/wiki/Speed_of_light
5
+ */
3
6
  export const SPEED_OF_LIGHT = quantity(299792458, m_s);
4
7
  /**
5
8
  * At 20 degree celsius
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.2.0",
3
+ "version": "0.3.0",
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": "ded6c346ccabc8bf647b848738878bdae8e05d55\n"
182
+ "gitHead": "226659c410d47899bdc702e8cd871e2b66548bb8\n"
177
183
  }