siderust-js 0.1.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/.github/workflows/ci.yml +166 -0
- package/.gitmodules +9 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +661 -0
- package/README.md +138 -0
- package/package.json +12 -0
- package/qtty-js/.github/workflows/ci.yml +151 -0
- package/qtty-js/.gitmodules +3 -0
- package/qtty-js/CHANGELOG.md +31 -0
- package/qtty-js/LICENSE +661 -0
- package/qtty-js/README.md +132 -0
- package/qtty-js/package.json +20 -0
- package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
- package/qtty-js/qtty/CHANGELOG.md +120 -0
- package/qtty-js/qtty/Cargo.lock +1462 -0
- package/qtty-js/qtty/Cargo.toml +12 -0
- package/qtty-js/qtty/LICENSE +661 -0
- package/qtty-js/qtty/README.md +9 -0
- package/qtty-js/qtty/qtty/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty/README.md +8 -0
- package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
- package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
- package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
- package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
- package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
- package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
- package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
- package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
- package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
- package/qtty-js/qtty/qtty/src/f32.rs +108 -0
- package/qtty-js/qtty/qtty/src/f64.rs +30 -0
- package/qtty-js/qtty/qtty/src/i128.rs +111 -0
- package/qtty-js/qtty/qtty/src/i16.rs +111 -0
- package/qtty-js/qtty/qtty/src/i32.rs +111 -0
- package/qtty-js/qtty/qtty/src/i64.rs +111 -0
- package/qtty-js/qtty/qtty/src/i8.rs +111 -0
- package/qtty-js/qtty/qtty/src/lib.rs +238 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
- package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
- package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
- package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty-core/README.md +8 -0
- package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
- package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
- package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
- package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
- package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
- package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
- package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
- package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
- package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
- package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
- package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
- package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
- package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
- package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
- package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
- package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
- package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
- package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
- package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
- package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
- package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
- package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
- package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
- package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
- package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
- package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
- package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
- package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
- package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
- package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
- package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
- package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
- package/qtty-js/qtty/qtty-derive/README.md +8 -0
- package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
- package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
- package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
- package/qtty-js/qtty/qtty-ffi/README.md +9 -0
- package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
- package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
- package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
- package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
- package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
- package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
- package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
- package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
- package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
- package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
- package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
- package/qtty-js/qtty-node/.prettierignore +6 -0
- package/qtty-js/qtty-node/.prettierrc.json +6 -0
- package/qtty-js/qtty-node/README.md +250 -0
- package/qtty-js/qtty-node/c8.config.json +11 -0
- package/qtty-js/qtty-node/eslint.config.js +31 -0
- package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
- package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
- package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
- package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
- package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
- package/qtty-js/qtty-node/index.d.ts +219 -0
- package/qtty-js/qtty-node/index.js +323 -0
- package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
- package/qtty-js/qtty-node/lib/Quantity.js +151 -0
- package/qtty-js/qtty-node/lib/backend.js +25 -0
- package/qtty-js/qtty-node/native.cjs +306 -0
- package/qtty-js/qtty-node/package-lock.json +3223 -0
- package/qtty-js/qtty-node/package.json +70 -0
- package/qtty-js/qtty-node/units.d.ts +299 -0
- package/qtty-js/qtty-node/units.js +210 -0
- package/qtty-js/qtty-web/Cargo.lock +767 -0
- package/qtty-js/qtty-web/Cargo.toml +21 -0
- package/qtty-js/qtty-web/index.d.ts +140 -0
- package/qtty-js/qtty-web/index.js +20 -0
- package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
- package/qtty-js/qtty-web/lib/Quantity.js +75 -0
- package/qtty-js/qtty-web/lib/backend.js +80 -0
- package/qtty-js/qtty-web/package.json +45 -0
- package/qtty-js/qtty-web/src/lib.rs +111 -0
- package/qtty-js/scripts/ci.sh +73 -0
- package/scripts/ci.sh +123 -0
- package/siderust-core/Cargo.lock +787 -0
- package/siderust-core/Cargo.toml +18 -0
- package/siderust-core/DEDUPLICATION.md +124 -0
- package/siderust-core/src/body.rs +120 -0
- package/siderust-core/src/events.rs +184 -0
- package/siderust-core/src/lib.rs +20 -0
- package/siderust-core/src/observer.rs +55 -0
- package/siderust-core/src/position.rs +213 -0
- package/siderust-node/.prettierignore +7 -0
- package/siderust-node/.prettierrc.json +6 -0
- package/siderust-node/Cargo.lock +906 -0
- package/siderust-node/Cargo.toml +29 -0
- package/siderust-node/README.md +109 -0
- package/siderust-node/__test__/index.test.mjs +248 -0
- package/siderust-node/build.rs +5 -0
- package/siderust-node/c8.config.json +3 -0
- package/siderust-node/eslint.config.js +31 -0
- package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
- package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
- package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
- package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
- package/siderust-node/examples/05_target_tracking.mjs +22 -0
- package/siderust-node/examples/06_night_events.mjs +18 -0
- package/siderust-node/examples/07_moon_properties.mjs +21 -0
- package/siderust-node/examples/08_solar_system.mjs +19 -0
- package/siderust-node/examples/09_star_observability.mjs +22 -0
- package/siderust-node/examples/10_time_periods.mjs +9 -0
- package/siderust-node/examples/11_serialization.mjs +31 -0
- package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
- package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
- package/siderust-node/index.d.ts +623 -0
- package/siderust-node/index.js +79 -0
- package/siderust-node/lib/Observer.js +112 -0
- package/siderust-node/lib/Star.js +118 -0
- package/siderust-node/lib/backend.js +63 -0
- package/siderust-node/lib/wrappers.js +566 -0
- package/siderust-node/main.js +20 -0
- package/siderust-node/native.cjs +360 -0
- package/siderust-node/package-lock.json +3261 -0
- package/siderust-node/package.json +71 -0
- package/siderust-node/src/body.rs +74 -0
- package/siderust-node/src/coordinates.rs +372 -0
- package/siderust-node/src/ephemeris.rs +462 -0
- package/siderust-node/src/events.rs +577 -0
- package/siderust-node/src/lib.rs +43 -0
- package/siderust-node/src/observer.rs +132 -0
- package/siderust-node/src/phase.rs +218 -0
- package/siderust-node/src/position.rs +292 -0
- package/siderust-node/src/star.rs +200 -0
- package/siderust-web/Cargo.lock +855 -0
- package/siderust-web/Cargo.toml +34 -0
- package/siderust-web/README.md +100 -0
- package/siderust-web/__test__/index.test.mjs +118 -0
- package/siderust-web/examples/github-pages/README.md +31 -0
- package/siderust-web/examples/github-pages/index.html +135 -0
- package/siderust-web/index.d.ts +311 -0
- package/siderust-web/index.js +66 -0
- package/siderust-web/lib/Observer.js +103 -0
- package/siderust-web/lib/Star.js +116 -0
- package/siderust-web/lib/backend.js +400 -0
- package/siderust-web/lib/wrappers.js +512 -0
- package/siderust-web/package.json +55 -0
- package/siderust-web/src/body.rs +69 -0
- package/siderust-web/src/coordinates.rs +302 -0
- package/siderust-web/src/ephemeris.rs +456 -0
- package/siderust-web/src/events.rs +520 -0
- package/siderust-web/src/lib.rs +51 -0
- package/siderust-web/src/observer.rs +117 -0
- package/siderust-web/src/phase.rs +190 -0
- package/siderust-web/src/position.rs +291 -0
- package/siderust-web/src/star.rs +178 -0
- package/tempoch-js/.github/workflows/ci.yml +142 -0
- package/tempoch-js/.gitmodules +3 -0
- package/tempoch-js/CHANGELOG.md +25 -0
- package/tempoch-js/LICENSE +661 -0
- package/tempoch-js/README.md +126 -0
- package/tempoch-js/package.json +20 -0
- package/tempoch-js/scripts/ci.sh +73 -0
- package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
- package/tempoch-js/tempoch/CHANGELOG.md +82 -0
- package/tempoch-js/tempoch/Cargo.lock +947 -0
- package/tempoch-js/tempoch/Cargo.toml +3 -0
- package/tempoch-js/tempoch/LICENSE +661 -0
- package/tempoch-js/tempoch/README.md +76 -0
- package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
- package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
- package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
- package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
- package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
- package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
- package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
- package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
- package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
- package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
- package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
- package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
- package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
- package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
- package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
- package/tempoch-js/tempoch-node/.prettierignore +6 -0
- package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
- package/tempoch-js/tempoch-node/Cargo.lock +496 -0
- package/tempoch-js/tempoch-node/Cargo.toml +29 -0
- package/tempoch-js/tempoch-node/README.md +265 -0
- package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
- package/tempoch-js/tempoch-node/build.rs +5 -0
- package/tempoch-js/tempoch-node/c8.config.json +3 -0
- package/tempoch-js/tempoch-node/eslint.config.js +31 -0
- package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
- package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
- package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
- package/tempoch-js/tempoch-node/index.d.ts +280 -0
- package/tempoch-js/tempoch-node/index.js +32 -0
- package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
- package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
- package/tempoch-js/tempoch-node/lib/Period.js +133 -0
- package/tempoch-js/tempoch-node/lib/backend.js +38 -0
- package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
- package/tempoch-js/tempoch-node/native.cjs +317 -0
- package/tempoch-js/tempoch-node/package-lock.json +3223 -0
- package/tempoch-js/tempoch-node/package.json +56 -0
- package/tempoch-js/tempoch-node/src/lib.rs +573 -0
- package/tempoch-js/tempoch-web/Cargo.toml +23 -0
- package/tempoch-js/tempoch-web/index.d.ts +95 -0
- package/tempoch-js/tempoch-web/index.js +27 -0
- package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
- package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
- package/tempoch-js/tempoch-web/lib/Period.js +121 -0
- package/tempoch-js/tempoch-web/lib/backend.js +118 -0
- package/tempoch-js/tempoch-web/package.json +46 -0
- package/tempoch-js/tempoch-web/src/lib.rs +184 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@siderust/qtty",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Strongly-typed physical quantities and unit conversions for Node.js, powered by Rust",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./index.js",
|
|
10
|
+
"import": "./index.js",
|
|
11
|
+
"types": "./index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./units": {
|
|
14
|
+
"require": "./units.js",
|
|
15
|
+
"import": "./units.js",
|
|
16
|
+
"types": "./units.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "napi build --release --platform",
|
|
21
|
+
"build:debug": "napi build --platform",
|
|
22
|
+
"format": "prettier --write .",
|
|
23
|
+
"format:check": "prettier --check .",
|
|
24
|
+
"lint": "eslint .",
|
|
25
|
+
"test": "node --test __test__/*.test.mjs",
|
|
26
|
+
"test:coverage": "c8 --config c8.config.json node --test __test__/*.test.mjs",
|
|
27
|
+
"ci": "npm run format:check && npm run lint && npm run build:debug && npm test && npm run test:coverage",
|
|
28
|
+
"prepublishOnly": "napi build --release --platform"
|
|
29
|
+
},
|
|
30
|
+
"napi": {
|
|
31
|
+
"name": "qtty",
|
|
32
|
+
"triples": {
|
|
33
|
+
"defaults": true
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"index.js",
|
|
38
|
+
"index.d.ts",
|
|
39
|
+
"native.cjs",
|
|
40
|
+
"lib/",
|
|
41
|
+
"units.js",
|
|
42
|
+
"units.d.ts",
|
|
43
|
+
"examples/",
|
|
44
|
+
"README.md"
|
|
45
|
+
],
|
|
46
|
+
"keywords": [
|
|
47
|
+
"quantities",
|
|
48
|
+
"units",
|
|
49
|
+
"conversion",
|
|
50
|
+
"physics",
|
|
51
|
+
"science",
|
|
52
|
+
"astronomy",
|
|
53
|
+
"napi",
|
|
54
|
+
"rust",
|
|
55
|
+
"native"
|
|
56
|
+
],
|
|
57
|
+
"license": "AGPL-3.0",
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "https://github.com/Siderust/qtty"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@eslint/js": "^10.0.1",
|
|
64
|
+
"@napi-rs/cli": "^3.5.1",
|
|
65
|
+
"c8": "^11.0.0",
|
|
66
|
+
"eslint": "^10.0.3",
|
|
67
|
+
"globals": "^17.4.0",
|
|
68
|
+
"prettier": "^3.6.2"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import type { Quantity } from './index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A callable unit factory with attached metadata.
|
|
5
|
+
*
|
|
6
|
+
* Call it with a numeric value to produce a `Quantity`:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Meters, Degrees } from '@siderust/qtty/units';
|
|
10
|
+
*
|
|
11
|
+
* const d = Meters(1000); // Quantity { value: 1000, unit: 'Meter' }
|
|
12
|
+
* const a = Degrees(180); // Quantity { value: 180, unit: 'Degree' }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface UnitFactory {
|
|
16
|
+
/** Create a Quantity with this unit. */
|
|
17
|
+
(value: number): Quantity;
|
|
18
|
+
/** Unit name, e.g. `"Meter"`. */
|
|
19
|
+
readonly unit: string;
|
|
20
|
+
/** Unit symbol, e.g. `"m"`. */
|
|
21
|
+
readonly symbol: string;
|
|
22
|
+
/** Dimension name, e.g. `"Length"`. */
|
|
23
|
+
readonly dimension: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ── Length ───────────────────────────────────────────────────────────────────
|
|
27
|
+
export declare const PlanckLengths: UnitFactory;
|
|
28
|
+
export declare const Yoctometers: UnitFactory;
|
|
29
|
+
export declare const Zeptometers: UnitFactory;
|
|
30
|
+
export declare const Attometers: UnitFactory;
|
|
31
|
+
export declare const Femtometers: UnitFactory;
|
|
32
|
+
export declare const Picometers: UnitFactory;
|
|
33
|
+
export declare const Nanometers: UnitFactory;
|
|
34
|
+
export declare const Micrometers: UnitFactory;
|
|
35
|
+
export declare const Millimeters: UnitFactory;
|
|
36
|
+
export declare const Centimeters: UnitFactory;
|
|
37
|
+
export declare const Decimeters: UnitFactory;
|
|
38
|
+
export declare const Meters: UnitFactory;
|
|
39
|
+
export declare const Decameters: UnitFactory;
|
|
40
|
+
export declare const Hectometers: UnitFactory;
|
|
41
|
+
export declare const Kilometers: UnitFactory;
|
|
42
|
+
export declare const Megameters: UnitFactory;
|
|
43
|
+
export declare const Gigameters: UnitFactory;
|
|
44
|
+
export declare const Terameters: UnitFactory;
|
|
45
|
+
export declare const Petameters: UnitFactory;
|
|
46
|
+
export declare const Inches: UnitFactory;
|
|
47
|
+
export declare const Feet: UnitFactory;
|
|
48
|
+
export declare const Yards: UnitFactory;
|
|
49
|
+
export declare const Miles: UnitFactory;
|
|
50
|
+
export declare const NauticalMiles: UnitFactory;
|
|
51
|
+
export declare const AstronomicalUnits: UnitFactory;
|
|
52
|
+
export declare const LightYears: UnitFactory;
|
|
53
|
+
export declare const Parsecs: UnitFactory;
|
|
54
|
+
export declare const Kiloparsecs: UnitFactory;
|
|
55
|
+
export declare const Megaparsecs: UnitFactory;
|
|
56
|
+
export declare const Gigaparsecs: UnitFactory;
|
|
57
|
+
|
|
58
|
+
// ── Time ─────────────────────────────────────────────────────────────────────
|
|
59
|
+
export declare const Attoseconds: UnitFactory;
|
|
60
|
+
export declare const Femtoseconds: UnitFactory;
|
|
61
|
+
export declare const Picoseconds: UnitFactory;
|
|
62
|
+
export declare const Nanoseconds: UnitFactory;
|
|
63
|
+
export declare const Microseconds: UnitFactory;
|
|
64
|
+
export declare const Milliseconds: UnitFactory;
|
|
65
|
+
export declare const Seconds: UnitFactory;
|
|
66
|
+
export declare const Minutes: UnitFactory;
|
|
67
|
+
export declare const Hours: UnitFactory;
|
|
68
|
+
export declare const Days: UnitFactory;
|
|
69
|
+
export declare const Weeks: UnitFactory;
|
|
70
|
+
export declare const Years: UnitFactory;
|
|
71
|
+
export declare const Decades: UnitFactory;
|
|
72
|
+
export declare const Centuries: UnitFactory;
|
|
73
|
+
export declare const Millennia: UnitFactory;
|
|
74
|
+
export declare const JulianYears: UnitFactory;
|
|
75
|
+
export declare const JulianCenturies: UnitFactory;
|
|
76
|
+
export declare const SiderealDays: UnitFactory;
|
|
77
|
+
export declare const SynodicMonths: UnitFactory;
|
|
78
|
+
export declare const SiderealYears: UnitFactory;
|
|
79
|
+
|
|
80
|
+
// ── Angle ────────────────────────────────────────────────────────────────────
|
|
81
|
+
export declare const Milliradians: UnitFactory;
|
|
82
|
+
export declare const Radians: UnitFactory;
|
|
83
|
+
export declare const MicroArcseconds: UnitFactory;
|
|
84
|
+
export declare const MilliArcseconds: UnitFactory;
|
|
85
|
+
export declare const Arcseconds: UnitFactory;
|
|
86
|
+
export declare const Arcminutes: UnitFactory;
|
|
87
|
+
export declare const Degrees: UnitFactory;
|
|
88
|
+
export declare const Gradians: UnitFactory;
|
|
89
|
+
export declare const Turns: UnitFactory;
|
|
90
|
+
export declare const HourAngles: UnitFactory;
|
|
91
|
+
|
|
92
|
+
// ── Mass ─────────────────────────────────────────────────────────────────────
|
|
93
|
+
export declare const Micrograms: UnitFactory;
|
|
94
|
+
export declare const Milligrams: UnitFactory;
|
|
95
|
+
export declare const Grams: UnitFactory;
|
|
96
|
+
export declare const Kilograms: UnitFactory;
|
|
97
|
+
export declare const Tonnes: UnitFactory;
|
|
98
|
+
export declare const Ounces: UnitFactory;
|
|
99
|
+
export declare const Pounds: UnitFactory;
|
|
100
|
+
export declare const Stones: UnitFactory;
|
|
101
|
+
export declare const SolarMasses: UnitFactory;
|
|
102
|
+
export declare const AtomicMassUnits: UnitFactory;
|
|
103
|
+
|
|
104
|
+
// ── Power ────────────────────────────────────────────────────────────────────
|
|
105
|
+
export declare const Milliwatts: UnitFactory;
|
|
106
|
+
export declare const Watts: UnitFactory;
|
|
107
|
+
export declare const Kilowatts: UnitFactory;
|
|
108
|
+
export declare const Megawatts: UnitFactory;
|
|
109
|
+
export declare const Gigawatts: UnitFactory;
|
|
110
|
+
export declare const Terawatts: UnitFactory;
|
|
111
|
+
export declare const SolarLuminosities: UnitFactory;
|
|
112
|
+
|
|
113
|
+
// ── Dynamic access ───────────────────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Look up a unit factory by exact unit name.
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* import { unit } from '@siderust/qtty/units';
|
|
120
|
+
* const km = unit('Kilometer')!(2.5);
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function unit(name: string): UnitFactory | undefined;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* All unit factories as a read-only record indexed by unit name.
|
|
127
|
+
*/
|
|
128
|
+
export declare const units: Readonly<Record<string, UnitFactory>>;
|
|
129
|
+
|
|
130
|
+
// ── Unit name enum ────────────────────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
/** Union of every registered unit name. Use with `Unit` for type-safe lookups. */
|
|
133
|
+
export type UnitName =
|
|
134
|
+
// Length
|
|
135
|
+
| 'PlanckLength'
|
|
136
|
+
| 'Yoctometer'
|
|
137
|
+
| 'Zeptometer'
|
|
138
|
+
| 'Attometer'
|
|
139
|
+
| 'Femtometer'
|
|
140
|
+
| 'Picometer'
|
|
141
|
+
| 'Nanometer'
|
|
142
|
+
| 'Micrometer'
|
|
143
|
+
| 'Millimeter'
|
|
144
|
+
| 'Centimeter'
|
|
145
|
+
| 'Decimeter'
|
|
146
|
+
| 'Meter'
|
|
147
|
+
| 'Decameter'
|
|
148
|
+
| 'Hectometer'
|
|
149
|
+
| 'Kilometer'
|
|
150
|
+
| 'Megameter'
|
|
151
|
+
| 'Gigameter'
|
|
152
|
+
| 'Terameter'
|
|
153
|
+
| 'Petameter'
|
|
154
|
+
| 'Exameter'
|
|
155
|
+
| 'Zettameter'
|
|
156
|
+
| 'Yottameter'
|
|
157
|
+
| 'BohrRadius'
|
|
158
|
+
| 'ClassicalElectronRadius'
|
|
159
|
+
| 'ElectronReducedComptonWavelength'
|
|
160
|
+
| 'AstronomicalUnit'
|
|
161
|
+
| 'LightYear'
|
|
162
|
+
| 'Parsec'
|
|
163
|
+
| 'Kiloparsec'
|
|
164
|
+
| 'Megaparsec'
|
|
165
|
+
| 'Gigaparsec'
|
|
166
|
+
| 'Inch'
|
|
167
|
+
| 'Foot'
|
|
168
|
+
| 'Yard'
|
|
169
|
+
| 'Mile'
|
|
170
|
+
| 'Link'
|
|
171
|
+
| 'Fathom'
|
|
172
|
+
| 'Rod'
|
|
173
|
+
| 'Chain'
|
|
174
|
+
| 'NauticalMile'
|
|
175
|
+
| 'NominalLunarRadius'
|
|
176
|
+
| 'NominalLunarDistance'
|
|
177
|
+
| 'NominalEarthPolarRadius'
|
|
178
|
+
| 'NominalEarthRadius'
|
|
179
|
+
| 'NominalEarthEquatorialRadius'
|
|
180
|
+
| 'EarthMeridionalCircumference'
|
|
181
|
+
| 'EarthEquatorialCircumference'
|
|
182
|
+
| 'NominalJupiterRadius'
|
|
183
|
+
| 'NominalSolarRadius'
|
|
184
|
+
| 'NominalSolarDiameter'
|
|
185
|
+
// Time
|
|
186
|
+
| 'Attosecond'
|
|
187
|
+
| 'Femtosecond'
|
|
188
|
+
| 'Picosecond'
|
|
189
|
+
| 'Nanosecond'
|
|
190
|
+
| 'Microsecond'
|
|
191
|
+
| 'Millisecond'
|
|
192
|
+
| 'Centisecond'
|
|
193
|
+
| 'Decisecond'
|
|
194
|
+
| 'Second'
|
|
195
|
+
| 'Decasecond'
|
|
196
|
+
| 'Hectosecond'
|
|
197
|
+
| 'Kilosecond'
|
|
198
|
+
| 'Megasecond'
|
|
199
|
+
| 'Gigasecond'
|
|
200
|
+
| 'Terasecond'
|
|
201
|
+
| 'Minute'
|
|
202
|
+
| 'Hour'
|
|
203
|
+
| 'Day'
|
|
204
|
+
| 'Week'
|
|
205
|
+
| 'Fortnight'
|
|
206
|
+
| 'Year'
|
|
207
|
+
| 'Decade'
|
|
208
|
+
| 'Century'
|
|
209
|
+
| 'Millennium'
|
|
210
|
+
| 'JulianYear'
|
|
211
|
+
| 'JulianCentury'
|
|
212
|
+
| 'SiderealDay'
|
|
213
|
+
| 'SynodicMonth'
|
|
214
|
+
| 'SiderealYear'
|
|
215
|
+
// Angle
|
|
216
|
+
| 'Milliradian'
|
|
217
|
+
| 'Radian'
|
|
218
|
+
| 'MicroArcsecond'
|
|
219
|
+
| 'MilliArcsecond'
|
|
220
|
+
| 'Arcsecond'
|
|
221
|
+
| 'Arcminute'
|
|
222
|
+
| 'Degree'
|
|
223
|
+
| 'Gradian'
|
|
224
|
+
| 'Turn'
|
|
225
|
+
| 'HourAngle'
|
|
226
|
+
// Mass
|
|
227
|
+
| 'Yoctogram'
|
|
228
|
+
| 'Zeptogram'
|
|
229
|
+
| 'Attogram'
|
|
230
|
+
| 'Femtogram'
|
|
231
|
+
| 'Picogram'
|
|
232
|
+
| 'Nanogram'
|
|
233
|
+
| 'Microgram'
|
|
234
|
+
| 'Milligram'
|
|
235
|
+
| 'Centigram'
|
|
236
|
+
| 'Decigram'
|
|
237
|
+
| 'Gram'
|
|
238
|
+
| 'Decagram'
|
|
239
|
+
| 'Hectogram'
|
|
240
|
+
| 'Kilogram'
|
|
241
|
+
| 'Megagram'
|
|
242
|
+
| 'Gigagram'
|
|
243
|
+
| 'Teragram'
|
|
244
|
+
| 'Petagram'
|
|
245
|
+
| 'Exagram'
|
|
246
|
+
| 'Zettagram'
|
|
247
|
+
| 'Yottagram'
|
|
248
|
+
| 'Grain'
|
|
249
|
+
| 'Ounce'
|
|
250
|
+
| 'Pound'
|
|
251
|
+
| 'Stone'
|
|
252
|
+
| 'ShortTon'
|
|
253
|
+
| 'LongTon'
|
|
254
|
+
| 'Carat'
|
|
255
|
+
| 'Tonne'
|
|
256
|
+
| 'AtomicMassUnit'
|
|
257
|
+
| 'SolarMass'
|
|
258
|
+
// Power
|
|
259
|
+
| 'Yoctowatt'
|
|
260
|
+
| 'Zeptowatt'
|
|
261
|
+
| 'Attowatt'
|
|
262
|
+
| 'Femtowatt'
|
|
263
|
+
| 'Picowatt'
|
|
264
|
+
| 'Nanowatt'
|
|
265
|
+
| 'Microwatt'
|
|
266
|
+
| 'Milliwatt'
|
|
267
|
+
| 'Deciwatt'
|
|
268
|
+
| 'Watt'
|
|
269
|
+
| 'Decawatt'
|
|
270
|
+
| 'Hectowatt'
|
|
271
|
+
| 'Kilowatt'
|
|
272
|
+
| 'Megawatt'
|
|
273
|
+
| 'Gigawatt'
|
|
274
|
+
| 'Terawatt'
|
|
275
|
+
| 'Petawatt'
|
|
276
|
+
| 'Exawatt'
|
|
277
|
+
| 'Zettawatt'
|
|
278
|
+
| 'Yottawatt'
|
|
279
|
+
| 'ErgPerSecond'
|
|
280
|
+
| 'HorsepowerMetric'
|
|
281
|
+
| 'HorsepowerElectric'
|
|
282
|
+
| 'SolarLuminosity';
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Const map of all registered unit names.
|
|
286
|
+
*
|
|
287
|
+
* Use instead of raw string literals to get IDE autocomplete and avoid typos:
|
|
288
|
+
*
|
|
289
|
+
* ```ts
|
|
290
|
+
* import { Unit, Quantity } from '@siderust/qtty';
|
|
291
|
+
*
|
|
292
|
+
* const d = new Quantity(1000, Unit.Meter);
|
|
293
|
+
* const km = d.to(Unit.Kilometer);
|
|
294
|
+
* convert(1, Unit.Meter, Unit.Kilometer);
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* Each key is a string literal type, so `Unit.Meter` has type `'Meter'`.
|
|
298
|
+
*/
|
|
299
|
+
export declare const Unit: { readonly [K in UnitName]: K };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @siderust/qtty — Unit factory constants.
|
|
3
|
+
*
|
|
4
|
+
* Every export is a **callable unit factory**: call it with a number to produce
|
|
5
|
+
* a `Quantity` for that unit.
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* import { Meters, Kilometers, Degrees, Kilograms } from '@siderust/qtty/units';
|
|
9
|
+
*
|
|
10
|
+
* const d = Meters(1000); // Quantity { value: 1000, unit: 'Meter' }
|
|
11
|
+
* const a = Degrees(180); // Quantity { value: 180, unit: 'Degree' }
|
|
12
|
+
* const km = d.to('Kilometer'); // Quantity { value: 1, unit: 'Kilometer' }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Arithmetic shorthand — because JavaScript has no operator overloading, use
|
|
16
|
+
* the factory call instead of multiplication:
|
|
17
|
+
*
|
|
18
|
+
* `Degrees(180)` ≡ `new Quantity(180, 'Degree')`
|
|
19
|
+
* `Kilometers(2.5)` ≡ `new Quantity(2.5, 'Kilometer')`
|
|
20
|
+
*
|
|
21
|
+
* Every factory also exposes the unit metadata as properties:
|
|
22
|
+
*
|
|
23
|
+
* ```js
|
|
24
|
+
* Meters.unit // 'Meter'
|
|
25
|
+
* Meters.symbol // 'm'
|
|
26
|
+
* Meters.dimension // 'Length'
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
'use strict';
|
|
31
|
+
|
|
32
|
+
const { Quantity } = require('./lib/Quantity.js');
|
|
33
|
+
const { listUnits } = require('./lib/backend.js');
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates a unit factory function for the given unit name.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} unitName
|
|
39
|
+
* @param {string} symbol
|
|
40
|
+
* @param {string} dimension
|
|
41
|
+
* @returns {UnitFactory}
|
|
42
|
+
*/
|
|
43
|
+
function makeFactory(unitName, symbol, dimension) {
|
|
44
|
+
/**
|
|
45
|
+
* @param {number} value
|
|
46
|
+
* @returns {import('./index.js').Quantity}
|
|
47
|
+
*/
|
|
48
|
+
function factory(value) {
|
|
49
|
+
return new Quantity(value, unitName);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
factory.unit = unitName;
|
|
53
|
+
factory.symbol = symbol;
|
|
54
|
+
factory.dimension = dimension;
|
|
55
|
+
factory.toString = () => unitName;
|
|
56
|
+
factory[Symbol.toStringTag] = `Unit(${unitName})`;
|
|
57
|
+
|
|
58
|
+
return factory;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Build factories for every registered unit.
|
|
62
|
+
const _all = listUnits();
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* All unit factories indexed by unit name.
|
|
66
|
+
* @type {Record<string, UnitFactory>}
|
|
67
|
+
*/
|
|
68
|
+
const byName = Object.create(null);
|
|
69
|
+
|
|
70
|
+
for (const { name, symbol, dimension } of _all) {
|
|
71
|
+
byName[name] = makeFactory(name, symbol, dimension);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
75
|
+
// Named exports — common units for ergonomic imports
|
|
76
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
77
|
+
|
|
78
|
+
// Length
|
|
79
|
+
exports.PlanckLengths = byName['PlanckLength'];
|
|
80
|
+
exports.Yoctometers = byName['Yoctometer'];
|
|
81
|
+
exports.Zeptometers = byName['Zeptometer'];
|
|
82
|
+
exports.Attometers = byName['Attometer'];
|
|
83
|
+
exports.Femtometers = byName['Femtometer'];
|
|
84
|
+
exports.Picometers = byName['Picometer'];
|
|
85
|
+
exports.Nanometers = byName['Nanometer'];
|
|
86
|
+
exports.Micrometers = byName['Micrometer'];
|
|
87
|
+
exports.Millimeters = byName['Millimeter'];
|
|
88
|
+
exports.Centimeters = byName['Centimeter'];
|
|
89
|
+
exports.Decimeters = byName['Decimeter'];
|
|
90
|
+
exports.Meters = byName['Meter'];
|
|
91
|
+
exports.Decameters = byName['Decameter'];
|
|
92
|
+
exports.Hectometers = byName['Hectometer'];
|
|
93
|
+
exports.Kilometers = byName['Kilometer'];
|
|
94
|
+
exports.Megameters = byName['Megameter'];
|
|
95
|
+
exports.Gigameters = byName['Gigameter'];
|
|
96
|
+
exports.Terameters = byName['Terameter'];
|
|
97
|
+
exports.Petameters = byName['Petameter'];
|
|
98
|
+
exports.Inches = byName['Inch'];
|
|
99
|
+
exports.Feet = byName['Foot'];
|
|
100
|
+
exports.Yards = byName['Yard'];
|
|
101
|
+
exports.Miles = byName['Mile'];
|
|
102
|
+
exports.NauticalMiles = byName['NauticalMile'];
|
|
103
|
+
exports.AstronomicalUnits = byName['AstronomicalUnit'];
|
|
104
|
+
exports.LightYears = byName['LightYear'];
|
|
105
|
+
exports.Parsecs = byName['Parsec'];
|
|
106
|
+
exports.Kiloparsecs = byName['Kiloparsec'];
|
|
107
|
+
exports.Megaparsecs = byName['Megaparsec'];
|
|
108
|
+
exports.Gigaparsecs = byName['Gigaparsec'];
|
|
109
|
+
|
|
110
|
+
// Time
|
|
111
|
+
exports.Attoseconds = byName['Attosecond'];
|
|
112
|
+
exports.Femtoseconds = byName['Femtosecond'];
|
|
113
|
+
exports.Picoseconds = byName['Picosecond'];
|
|
114
|
+
exports.Nanoseconds = byName['Nanosecond'];
|
|
115
|
+
exports.Microseconds = byName['Microsecond'];
|
|
116
|
+
exports.Milliseconds = byName['Millisecond'];
|
|
117
|
+
exports.Seconds = byName['Second'];
|
|
118
|
+
exports.Minutes = byName['Minute'];
|
|
119
|
+
exports.Hours = byName['Hour'];
|
|
120
|
+
exports.Days = byName['Day'];
|
|
121
|
+
exports.Weeks = byName['Week'];
|
|
122
|
+
exports.Years = byName['Year'];
|
|
123
|
+
exports.Decades = byName['Decade'];
|
|
124
|
+
exports.Centuries = byName['Century'];
|
|
125
|
+
exports.Millennia = byName['Millennium'];
|
|
126
|
+
exports.JulianYears = byName['JulianYear'];
|
|
127
|
+
exports.JulianCenturies = byName['JulianCentury'];
|
|
128
|
+
exports.SiderealDays = byName['SiderealDay'];
|
|
129
|
+
exports.SynodicMonths = byName['SynodicMonth'];
|
|
130
|
+
exports.SiderealYears = byName['SiderealYear'];
|
|
131
|
+
|
|
132
|
+
// Angle
|
|
133
|
+
exports.Milliradians = byName['Milliradian'];
|
|
134
|
+
exports.Radians = byName['Radian'];
|
|
135
|
+
exports.MicroArcseconds = byName['MicroArcsecond'];
|
|
136
|
+
exports.MilliArcseconds = byName['MilliArcsecond'];
|
|
137
|
+
exports.Arcseconds = byName['Arcsecond'];
|
|
138
|
+
exports.Arcminutes = byName['Arcminute'];
|
|
139
|
+
exports.Degrees = byName['Degree'];
|
|
140
|
+
exports.Gradians = byName['Gradian'];
|
|
141
|
+
exports.Turns = byName['Turn'];
|
|
142
|
+
exports.HourAngles = byName['HourAngle'];
|
|
143
|
+
|
|
144
|
+
// Mass
|
|
145
|
+
exports.Micrograms = byName['Microgram'];
|
|
146
|
+
exports.Milligrams = byName['Milligram'];
|
|
147
|
+
exports.Grams = byName['Gram'];
|
|
148
|
+
exports.Kilograms = byName['Kilogram'];
|
|
149
|
+
exports.Tonnes = byName['Tonne'];
|
|
150
|
+
exports.Ounces = byName['Ounce'];
|
|
151
|
+
exports.Pounds = byName['Pound'];
|
|
152
|
+
exports.Stones = byName['Stone'];
|
|
153
|
+
exports.SolarMasses = byName['SolarMass'];
|
|
154
|
+
exports.AtomicMassUnits = byName['AtomicMassUnit'];
|
|
155
|
+
|
|
156
|
+
// Power
|
|
157
|
+
exports.Milliwatts = byName['Milliwatt'];
|
|
158
|
+
exports.Watts = byName['Watt'];
|
|
159
|
+
exports.Kilowatts = byName['Kilowatt'];
|
|
160
|
+
exports.Megawatts = byName['Megawatt'];
|
|
161
|
+
exports.Gigawatts = byName['Gigawatt'];
|
|
162
|
+
exports.Terawatts = byName['Terawatt'];
|
|
163
|
+
exports.SolarLuminosities = byName['SolarLuminosity'];
|
|
164
|
+
|
|
165
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
166
|
+
// Dynamic access helpers
|
|
167
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Look up a unit factory by exact unit name.
|
|
171
|
+
*
|
|
172
|
+
* ```js
|
|
173
|
+
* import { unit } from '@siderust/qtty/units';
|
|
174
|
+
* const km = unit('Kilometer')(2.5);
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @param {string} name - Unit name, e.g. `'Kilometer'`.
|
|
178
|
+
* @returns {UnitFactory | undefined}
|
|
179
|
+
*/
|
|
180
|
+
exports.unit = (name) => byName[name];
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* All unit factories as an object indexed by unit name.
|
|
184
|
+
* @type {Readonly<Record<string, UnitFactory>>}
|
|
185
|
+
*/
|
|
186
|
+
exports.units = Object.freeze({ ...byName });
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Const map of all registered unit names.
|
|
190
|
+
*
|
|
191
|
+
* Use instead of raw string literals to get IDE autocomplete and avoid typos:
|
|
192
|
+
*
|
|
193
|
+
* ```js
|
|
194
|
+
* import { Unit } from '@siderust/qtty/units';
|
|
195
|
+
*
|
|
196
|
+
* const d = new Quantity(1000, Unit.Meter);
|
|
197
|
+
* const km = d.to(Unit.Kilometer);
|
|
198
|
+
* convert(1, Unit.Meter, Unit.Kilometer);
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @type {Readonly<Record<string, string>>}
|
|
202
|
+
*/
|
|
203
|
+
exports.Unit = Object.freeze(Object.fromEntries(_all.map((u) => [u.name, u.name])));
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @typedef {object} UnitFactory
|
|
207
|
+
* @property {string} unit - Unit name.
|
|
208
|
+
* @property {string} symbol - Unit symbol.
|
|
209
|
+
* @property {string} dimension - Dimension name.
|
|
210
|
+
*/
|