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,156 @@
|
|
|
1
|
+
# FFI Unit Definitions
|
|
2
|
+
# Format: discriminant,dimension,name,symbol,ratio[,rust_type]
|
|
3
|
+
# Discriminant encoding: DSSCC where D=dimension (1 digit), SS=system (2 digits), CC=counter (2 digits)
|
|
4
|
+
# Ratio is the conversion factor to the canonical unit for that dimension
|
|
5
|
+
# Canonical units: Meter (Length), Second (Time), Radian (Angle), Gram (Mass), Watt (Power)
|
|
6
|
+
# rust_type (optional 6th field): Rust quantity type path for auto-generating From/TryFrom impls
|
|
7
|
+
|
|
8
|
+
# Length units (1xxxx): 100xx=SI, 110xx=Astronomical, 120xx=Imperial, 130xx=Nautical, 150xx=Nominal
|
|
9
|
+
10000,Length,PlanckLength,l_P,1.616255e-35,qtty::length::PlanckLengths
|
|
10
|
+
10001,Length,Yoctometer,ym,1e-24,qtty::length::Yoctometers
|
|
11
|
+
10002,Length,Zeptometer,zm,1e-21,qtty::length::Zeptometers
|
|
12
|
+
10003,Length,Attometer,am,1e-18,qtty::length::Attometers
|
|
13
|
+
10004,Length,Femtometer,fm,1e-15,qtty::length::Femtometers
|
|
14
|
+
10005,Length,Picometer,pm,1e-12,qtty::length::Picometers
|
|
15
|
+
10006,Length,Nanometer,nm,1e-9,qtty::length::Nanometers
|
|
16
|
+
10007,Length,Micrometer,µm,1e-6,qtty::length::Micrometers
|
|
17
|
+
10008,Length,Millimeter,mm,0.001,qtty::length::Millimeters
|
|
18
|
+
10009,Length,Centimeter,cm,0.01,qtty::length::Centimeters
|
|
19
|
+
10010,Length,Decimeter,dm,0.1,qtty::length::Decimeters
|
|
20
|
+
10011,Length,Meter,m,1.0,qtty::length::Meters
|
|
21
|
+
10012,Length,Decameter,dam,10.0,qtty::length::Decameters
|
|
22
|
+
10013,Length,Hectometer,hm,100.0,qtty::length::Hectometers
|
|
23
|
+
10014,Length,Kilometer,km,1000.0,qtty::length::Kilometers
|
|
24
|
+
10015,Length,Megameter,Mm,1e6,qtty::length::Megameters
|
|
25
|
+
10016,Length,Gigameter,Gm,1e9,qtty::length::Gigameters
|
|
26
|
+
10017,Length,Terameter,Tm,1e12,qtty::length::Terameters
|
|
27
|
+
10018,Length,Petameter,Pm,1e15,qtty::length::Petameters
|
|
28
|
+
10019,Length,Exameter,Em,1e18,qtty::length::Exameters
|
|
29
|
+
10020,Length,Zettameter,Zm,1e21,qtty::length::Zettameters
|
|
30
|
+
10021,Length,Yottameter,Ym,1e24,qtty::length::Yottameters
|
|
31
|
+
11000,Length,BohrRadius,a₀,5.29177210903e-11,qtty::length::BohrRadii
|
|
32
|
+
11001,Length,ClassicalElectronRadius,r_e,2.8179403262e-15,qtty::length::ClassicalElectronRadii
|
|
33
|
+
11002,Length,ElectronReducedComptonWavelength,λ̄_e,3.8615926796e-13,qtty::length::ElectronReducedComptonWavelengths
|
|
34
|
+
11003,Length,AstronomicalUnit,au,149597870700.0,qtty::length::AstronomicalUnits
|
|
35
|
+
11004,Length,LightYear,ly,9460730472580800.0,qtty::length::LightYears
|
|
36
|
+
11005,Length,Parsec,pc,30856775814913672.8,qtty::length::Parsecs
|
|
37
|
+
11006,Length,Kiloparsec,kpc,3.085_677_581_491_367e19,qtty::length::Kiloparsecs
|
|
38
|
+
11007,Length,Megaparsec,Mpc,3.085_677_581_491_367e22,qtty::length::Megaparsecs
|
|
39
|
+
11008,Length,Gigaparsec,Gpc,3.085_677_581_491_367e25,qtty::length::Gigaparsecs
|
|
40
|
+
12000,Length,Inch,in,0.0254,qtty::length::Inches
|
|
41
|
+
12001,Length,Foot,ft,0.3048,qtty::length::Feet
|
|
42
|
+
12002,Length,Yard,yd,0.9144,qtty::length::Yards
|
|
43
|
+
12003,Length,Mile,mi,1609.344,qtty::length::Miles
|
|
44
|
+
13000,Length,Link,lk,0.201168,qtty::length::Links
|
|
45
|
+
13001,Length,Fathom,ftm,1.8288,qtty::length::Fathoms
|
|
46
|
+
13002,Length,Rod,rd,5.0292,qtty::length::Rods
|
|
47
|
+
13003,Length,Chain,ch,20.1168,qtty::length::Chains
|
|
48
|
+
13004,Length,NauticalMile,nmi,1852.0,qtty::length::NauticalMiles
|
|
49
|
+
15000,Length,NominalLunarRadius,R_☾,1.7374e6,qtty::length::nominal::LunarRadii
|
|
50
|
+
15001,Length,NominalLunarDistance,LD,3.844e8,qtty::length::nominal::LunarDistances
|
|
51
|
+
15002,Length,NominalEarthPolarRadius,R_⊕pol,6.3568e6,qtty::length::nominal::EarthPolarRadii
|
|
52
|
+
15003,Length,NominalEarthRadius,R_⊕,6.3781e6,qtty::length::nominal::EarthRadii
|
|
53
|
+
15004,Length,NominalEarthEquatorialRadius,R_⊕eq,6.3781e6,qtty::length::nominal::EarthEquatorialRadii
|
|
54
|
+
15005,Length,EarthMeridionalCircumference,C_mer,40007862.917,qtty::length::EarthMeridionalCircumferences
|
|
55
|
+
15006,Length,EarthEquatorialCircumference,C_eq,40075016.686,qtty::length::EarthEquatorialCircumferences
|
|
56
|
+
15007,Length,NominalJupiterRadius,R_♃,7.1492e7,qtty::length::nominal::JupiterRadii
|
|
57
|
+
15008,Length,NominalSolarRadius,R_☉,6.957e8,qtty::length::nominal::SolarRadiuses
|
|
58
|
+
15009,Length,NominalSolarDiameter,D_☉,1.3914e9,qtty::length::nominal::SolarDiameters
|
|
59
|
+
# Time units (2xxxx): 200xx=SI, 210xx=Common, 220xx=Calendar, 230xx=Astronomical
|
|
60
|
+
20000,Time,Attosecond,as,1e-18,qtty::time::Attoseconds
|
|
61
|
+
20001,Time,Femtosecond,fs,1e-15,qtty::time::Femtoseconds
|
|
62
|
+
20002,Time,Picosecond,ps,1e-12,qtty::time::Picoseconds
|
|
63
|
+
20003,Time,Nanosecond,ns,1e-9,qtty::time::Nanoseconds
|
|
64
|
+
20004,Time,Microsecond,µs,1e-6,qtty::time::Microseconds
|
|
65
|
+
20005,Time,Millisecond,ms,0.001,qtty::time::Milliseconds
|
|
66
|
+
20006,Time,Centisecond,cs,0.01,qtty::time::Centiseconds
|
|
67
|
+
20007,Time,Decisecond,ds,0.1,qtty::time::Deciseconds
|
|
68
|
+
20008,Time,Second,s,1.0,qtty::time::Seconds
|
|
69
|
+
20009,Time,Decasecond,das,10.0,qtty::time::Decaseconds
|
|
70
|
+
20010,Time,Hectosecond,hs,100.0,qtty::time::Hectoseconds
|
|
71
|
+
20011,Time,Kilosecond,ks,1000.0,qtty::time::Kiloseconds
|
|
72
|
+
20012,Time,Megasecond,Ms,1e6,qtty::time::Megaseconds
|
|
73
|
+
20013,Time,Gigasecond,Gs,1e9,qtty::time::Gigaseconds
|
|
74
|
+
20014,Time,Terasecond,Ts,1e12,qtty::time::Teraseconds
|
|
75
|
+
21000,Time,Minute,min,60.0,qtty::time::Minutes
|
|
76
|
+
21001,Time,Hour,h,3600.0,qtty::time::Hours
|
|
77
|
+
21002,Time,Day,d,86400.0,qtty::time::Days
|
|
78
|
+
21003,Time,Week,wk,604800.0,qtty::time::Weeks
|
|
79
|
+
21004,Time,Fortnight,fn,1209600.0,qtty::time::Fortnights
|
|
80
|
+
22000,Time,Year,yr,31557600.0,qtty::time::Years
|
|
81
|
+
22001,Time,Decade,dec,315576000.0,qtty::time::Decades
|
|
82
|
+
22002,Time,Century,c,3155760000.0,qtty::time::Centuries
|
|
83
|
+
22003,Time,Millennium,mill,31557600000.0,qtty::time::Millennia
|
|
84
|
+
22004,Time,JulianYear,a,31557600.0,qtty::time::JulianYears
|
|
85
|
+
22005,Time,JulianCentury,jc,3155760000.0,qtty::time::JulianCenturies
|
|
86
|
+
23000,Time,SiderealDay,sd,86164.0905,qtty::time::SiderealDays
|
|
87
|
+
23001,Time,SynodicMonth,mo_s,2551442.976,qtty::time::SynodicMonths
|
|
88
|
+
23002,Time,SiderealYear,yr_s,31558149.7635456,qtty::time::SiderealYears
|
|
89
|
+
# Angle units (3xxxx): 300xx=Radian, 310xx=Degree, 320xx=Other
|
|
90
|
+
30000,Angle,Milliradian,mrad,0.001,qtty::angular::Milliradians
|
|
91
|
+
30001,Angle,Radian,rad,1.0,qtty::angular::Radians
|
|
92
|
+
31000,Angle,MicroArcsecond,µas,4.84813681109536e-12,qtty::angular::MicroArcseconds
|
|
93
|
+
31001,Angle,MilliArcsecond,mas,4.84813681109536e-9,qtty::angular::MilliArcseconds
|
|
94
|
+
31002,Angle,Arcsecond,″,4.84813681109536e-6,qtty::angular::Arcseconds
|
|
95
|
+
31003,Angle,Arcminute,′,0.0002908882086657216,qtty::angular::Arcminutes
|
|
96
|
+
31004,Angle,Degree,°,0.017453292519943295,qtty::angular::Degrees
|
|
97
|
+
32000,Angle,Gradian,gon,0.015707963267948967,qtty::angular::Gradians
|
|
98
|
+
32001,Angle,Turn,tr,std::f64::consts::TAU,qtty::angular::Turns
|
|
99
|
+
32002,Angle,HourAngle,ʰ,0.2617993877991494,qtty::angular::HourAngles
|
|
100
|
+
# Mass units (4xxxx): 400xx=SI, 410xx=Imperial, 420xx=Special
|
|
101
|
+
40000,Mass,Yoctogram,yg,1e-24,qtty::mass::Yoctograms
|
|
102
|
+
40001,Mass,Zeptogram,zg,1e-21,qtty::mass::Zeptograms
|
|
103
|
+
40002,Mass,Attogram,ag,1e-18,qtty::mass::Attograms
|
|
104
|
+
40003,Mass,Femtogram,fg,1e-15,qtty::mass::Femtograms
|
|
105
|
+
40004,Mass,Picogram,pg,1e-12,qtty::mass::Picograms
|
|
106
|
+
40005,Mass,Nanogram,ng,1e-9,qtty::mass::Nanograms
|
|
107
|
+
40006,Mass,Microgram,µg,1e-6,qtty::mass::Micrograms
|
|
108
|
+
40007,Mass,Milligram,mg,0.001,qtty::mass::Milligrams
|
|
109
|
+
40008,Mass,Centigram,cg,0.01,qtty::mass::Centigrams
|
|
110
|
+
40009,Mass,Decigram,dg,0.1,qtty::mass::Decigrams
|
|
111
|
+
40010,Mass,Gram,g,1.0,qtty::mass::Grams
|
|
112
|
+
40011,Mass,Decagram,dag,10.0,qtty::mass::Decagrams
|
|
113
|
+
40012,Mass,Hectogram,hg,100.0,qtty::mass::Hectograms
|
|
114
|
+
40013,Mass,Kilogram,kg,1000.0,qtty::mass::Kilograms
|
|
115
|
+
40014,Mass,Megagram,Mg,1e6,qtty::mass::Megagrams
|
|
116
|
+
40015,Mass,Gigagram,Gg,1e9,qtty::mass::Gigagrams
|
|
117
|
+
40016,Mass,Teragram,Tg,1e12,qtty::mass::Teragrams
|
|
118
|
+
40017,Mass,Petagram,Pg,1e15,qtty::mass::Petagrams
|
|
119
|
+
40018,Mass,Exagram,Eg,1e18,qtty::mass::Exagrams
|
|
120
|
+
40019,Mass,Zettagram,Zg,1e21,qtty::mass::Zettagrams
|
|
121
|
+
40020,Mass,Yottagram,Yg,1e24,qtty::mass::Yottagrams
|
|
122
|
+
41000,Mass,Grain,gr,0.06479891,qtty::mass::Grains
|
|
123
|
+
41001,Mass,Ounce,oz,28.349523125,qtty::mass::Ounces
|
|
124
|
+
41002,Mass,Pound,lb,453.59237,qtty::mass::Pounds
|
|
125
|
+
41003,Mass,Stone,st,6350.29318,qtty::mass::Stones
|
|
126
|
+
41004,Mass,ShortTon,ton,907184.74,qtty::mass::ShortTons
|
|
127
|
+
41005,Mass,LongTon,ton_l,1016046.9088,qtty::mass::LongTons
|
|
128
|
+
42000,Mass,Carat,ct,0.2,qtty::mass::Carats
|
|
129
|
+
42001,Mass,Tonne,t,1e6,qtty::mass::Tonnes
|
|
130
|
+
42002,Mass,AtomicMassUnit,u,1.66053906892e-24,qtty::mass::AtomicMassUnits
|
|
131
|
+
42003,Mass,SolarMass,M_☉,1.988416e33,qtty::mass::SolarMasses
|
|
132
|
+
# Power units (5xxxx): 500xx=SI, 510xx=Other
|
|
133
|
+
50000,Power,Yoctowatt,yW,1e-24,qtty::power::Yoctowatts
|
|
134
|
+
50001,Power,Zeptowatt,zW,1e-21,qtty::power::Zeptowatts
|
|
135
|
+
50002,Power,Attowatt,aW,1e-18,qtty::power::Attowatts
|
|
136
|
+
50003,Power,Femtowatt,fW,1e-15,qtty::power::Femtowatts
|
|
137
|
+
50004,Power,Picowatt,pW,1e-12,qtty::power::Picowatts
|
|
138
|
+
50005,Power,Nanowatt,nW,1e-9,qtty::power::Nanowatts
|
|
139
|
+
50006,Power,Microwatt,µW,1e-6,qtty::power::Microwatts
|
|
140
|
+
50007,Power,Milliwatt,mW,0.001,qtty::power::Milliwatts
|
|
141
|
+
50008,Power,Deciwatt,dW,0.1,qtty::power::Deciwatts
|
|
142
|
+
50009,Power,Watt,W,1.0,qtty::power::Watts
|
|
143
|
+
50010,Power,Decawatt,daW,10.0,qtty::power::Decawatts
|
|
144
|
+
50011,Power,Hectowatt,hW,100.0,qtty::power::Hectowatts
|
|
145
|
+
50012,Power,Kilowatt,kW,1000.0,qtty::power::Kilowatts
|
|
146
|
+
50013,Power,Megawatt,MW,1e6,qtty::power::Megawatts
|
|
147
|
+
50014,Power,Gigawatt,GW,1e9,qtty::power::Gigawatts
|
|
148
|
+
50015,Power,Terawatt,TW,1e12,qtty::power::Terawatts
|
|
149
|
+
50016,Power,Petawatt,PW,1e15,qtty::power::Petawatts
|
|
150
|
+
50017,Power,Exawatt,EW,1e18,qtty::power::Exawatts
|
|
151
|
+
50018,Power,Zettawatt,ZW,1e21,qtty::power::Zettawatts
|
|
152
|
+
50019,Power,Yottawatt,YW,1e24,qtty::power::Yottawatts
|
|
153
|
+
51000,Power,ErgPerSecond,erg/s,1e-7
|
|
154
|
+
51001,Power,HorsepowerMetric,PS,735.49875,qtty::power::HorsepowerMetrics
|
|
155
|
+
51002,Power,HorsepowerElectric,hp_e,746.0,qtty::power::HorsepowerElectrics
|
|
156
|
+
51003,Power,SolarLuminosity,L_☉,3.828e26,qtty::power::SolarLuminosities
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# @siderust/qtty
|
|
2
|
+
|
|
3
|
+
Strongly-typed physical quantities and unit conversions for Node.js, powered by
|
|
4
|
+
Rust.
|
|
5
|
+
|
|
6
|
+
`@siderust/qtty` gives you compile-time safe, zero-overhead unit conversions in
|
|
7
|
+
JavaScript and TypeScript by delegating all math to the Rust `qtty` library via
|
|
8
|
+
a native Node addon built with [napi-rs](https://napi.rs).
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @siderust/qtty
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The package ships a prebuilt native addon. If a prebuilt binary is not available
|
|
17
|
+
for your platform you will need a Rust toolchain (`rustup`) and the napi-rs CLI:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @napi-rs/cli
|
|
21
|
+
cd node_modules/@siderust/qtty && napi build --release --platform
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
const { Quantity, DerivedQuantity, convert } = require('@siderust/qtty');
|
|
28
|
+
|
|
29
|
+
// Create a quantity and convert
|
|
30
|
+
const distance = new Quantity(1000, 'Meter');
|
|
31
|
+
const km = distance.to('Kilometer');
|
|
32
|
+
console.log(km.value); // 1
|
|
33
|
+
console.log(km.unit); // "Kilometer"
|
|
34
|
+
|
|
35
|
+
// Arithmetic with automatic unit conversion
|
|
36
|
+
const a = new Quantity(1, 'Kilometer');
|
|
37
|
+
const b = new Quantity(500, 'Meter');
|
|
38
|
+
const total = a.add(b); // 1.5 km
|
|
39
|
+
const doubled = total.mul(2); // 3.0 km
|
|
40
|
+
|
|
41
|
+
// Derived (compound) quantities
|
|
42
|
+
const velocity = new DerivedQuantity(100, 'Meter', 'Second');
|
|
43
|
+
const kmh = velocity.to('Kilometer', 'Hour');
|
|
44
|
+
console.log(kmh.value); // 360
|
|
45
|
+
|
|
46
|
+
// One-shot value conversion
|
|
47
|
+
const hours = convert(7200, 'Second', 'Hour'); // 2
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Unit factories — arithmetic-style construction
|
|
51
|
+
|
|
52
|
+
Import named unit factory functions to create quantities without typing
|
|
53
|
+
`new Quantity(…)`. Each factory is callable and reads like an expression:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
// Both lines produce the same Quantity:
|
|
57
|
+
const a = Degrees(180); // factory style
|
|
58
|
+
const b = new Quantity(180, 'Degree'); // class style
|
|
59
|
+
|
|
60
|
+
// Works for any dimension:
|
|
61
|
+
const dist = Kilometers(1000);
|
|
62
|
+
const mass = Kilograms(70);
|
|
63
|
+
const time = Hours(24);
|
|
64
|
+
const power = Kilowatts(3.5);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Because JavaScript has no operator overloading, `180 * Degrees` cannot
|
|
68
|
+
return a `Quantity` — write `Degrees(180)` instead.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import {
|
|
72
|
+
Meters, Kilometers, Miles, AstronomicalUnits, LightYears, Parsecs,
|
|
73
|
+
Seconds, Minutes, Hours, Days, Years, JulianYears,
|
|
74
|
+
Degrees, Radians, Arcseconds,
|
|
75
|
+
Grams, Kilograms, SolarMasses,
|
|
76
|
+
Watts, Kilowatts, SolarLuminosities,
|
|
77
|
+
} from '@siderust/qtty/units';
|
|
78
|
+
|
|
79
|
+
// Factory metadata
|
|
80
|
+
console.log(Meters.unit); // 'Meter'
|
|
81
|
+
console.log(Meters.symbol); // 'm'
|
|
82
|
+
console.log(Meters.dimension); // 'Length'
|
|
83
|
+
|
|
84
|
+
// Convert straight from the factory call
|
|
85
|
+
const rad = Degrees(180).to('Radian'); // π rad
|
|
86
|
+
const pc = LightYears(1).to('Parsec'); // 0.3066 pc
|
|
87
|
+
|
|
88
|
+
// Chain arithmetic
|
|
89
|
+
const total = Kilometers(1).add(Meters(500)); // 1.5 km
|
|
90
|
+
const speed = Meters(100).div(1).to('Kilometer').mul(3600); // naive example
|
|
91
|
+
|
|
92
|
+
// Dynamic lookup by name
|
|
93
|
+
import { unit, units } from '@siderust/qtty/units';
|
|
94
|
+
const factory = unit('SolarMass'); // UnitFactory | undefined
|
|
95
|
+
const sun = factory!(1); // Quantity { value: 1, unit: 'SolarMass' }
|
|
96
|
+
|
|
97
|
+
// All factories as a record
|
|
98
|
+
const lengthNames = Object.values(units)
|
|
99
|
+
.filter(f => f.dimension === 'Length')
|
|
100
|
+
.map(f => f.unit);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## TypeScript
|
|
104
|
+
|
|
105
|
+
Full type information is provided out of the box:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { Quantity, convert, isCompatible } from '@siderust/qtty';
|
|
109
|
+
import { Degrees, Kilometers, Hours, type UnitFactory } from '@siderust/qtty/units';
|
|
110
|
+
|
|
111
|
+
// Using the class
|
|
112
|
+
const q: Quantity = new Quantity(180, 'Degree');
|
|
113
|
+
const rad: Quantity = q.to('Radian');
|
|
114
|
+
console.log(rad.value); // 3.141592653589793
|
|
115
|
+
|
|
116
|
+
// Using factories
|
|
117
|
+
const angle: Quantity = Degrees(180); // identical result
|
|
118
|
+
const speed: Quantity = Kilometers(100).div(Hours(1).value);
|
|
119
|
+
|
|
120
|
+
// Type of a factory
|
|
121
|
+
const f: UnitFactory = Degrees;
|
|
122
|
+
console.log(f.unit); // 'Degree'
|
|
123
|
+
console.log(f.symbol); // '°'
|
|
124
|
+
console.log(f.dimension); // 'Angle'
|
|
125
|
+
|
|
126
|
+
const ok: boolean = isCompatible('Meter', 'Kilometer'); // true
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## API
|
|
130
|
+
|
|
131
|
+
### `Quantity`
|
|
132
|
+
|
|
133
|
+
| Member | Description |
|
|
134
|
+
| --------------------------- | ------------------------------------------------------ |
|
|
135
|
+
| `new Quantity(value, unit)` | Create a quantity. Unit is a string like `"Meter"`. |
|
|
136
|
+
| `.value` | The numeric value (getter). |
|
|
137
|
+
| `.unit` | The unit name (getter). |
|
|
138
|
+
| `.symbol` | The unit symbol, e.g. `"m"` (getter). |
|
|
139
|
+
| `.dimension` | The dimension name, e.g. `"Length"` (getter). |
|
|
140
|
+
| `.to(unit)` | Convert to another unit. Throws on dimension mismatch. |
|
|
141
|
+
| `.add(other)` | Add another quantity (same dimension). |
|
|
142
|
+
| `.sub(other)` | Subtract another quantity (same dimension). |
|
|
143
|
+
| `.mul(scalar)` | Multiply by a number. |
|
|
144
|
+
| `.div(scalar)` | Divide by a number. |
|
|
145
|
+
| `.neg()` | Negate. |
|
|
146
|
+
| `.compatible(other)` | Check dimension compatibility. |
|
|
147
|
+
| `.format(precision?)` | Format as string, e.g. `"1000 m"`. |
|
|
148
|
+
| `.toJson()` | Return `{ value, unit }` plain object. |
|
|
149
|
+
| `.toString()` | Same as `.format()`. |
|
|
150
|
+
|
|
151
|
+
### `DerivedQuantity`
|
|
152
|
+
|
|
153
|
+
| Member | Description |
|
|
154
|
+
| ------------------------------------------ | ------------------------------------------- |
|
|
155
|
+
| `new DerivedQuantity(value, num, den)` | Create a compound quantity (e.g. m/s). |
|
|
156
|
+
| `.value` | Numeric value. |
|
|
157
|
+
| `.numerator` / `.denominator` | Unit names. |
|
|
158
|
+
| `.symbol` | Compound symbol, e.g. `"m/s"`. |
|
|
159
|
+
| `.to(num, den)` | Convert to different units. |
|
|
160
|
+
| `.mul(scalar)` / `.div(scalar)` / `.neg()` | Arithmetic. |
|
|
161
|
+
| `.format(precision?)` / `.toString()` | Formatting. |
|
|
162
|
+
| `.toJson()` | Return `{ value, numerator, denominator }`. |
|
|
163
|
+
|
|
164
|
+
### Free functions
|
|
165
|
+
|
|
166
|
+
| Function | Description |
|
|
167
|
+
| ---------------------------- | --------------------------------------------------------------- |
|
|
168
|
+
| `convert(value, from, to)` | Convert a bare number between units. |
|
|
169
|
+
| `isCompatible(unitA, unitB)` | Check if two units share a dimension. |
|
|
170
|
+
| `unitDimension(unit)` | Get the dimension name for a unit. |
|
|
171
|
+
| `unitSymbol(unit)` | Get the symbol for a unit. |
|
|
172
|
+
| `isValidUnit(unit)` | Check if a unit name is recognized. |
|
|
173
|
+
| `listUnits()` | Return all registered units as `{ name, symbol, dimension }[]`. |
|
|
174
|
+
| `ffiVersion()` | FFI ABI version number. |
|
|
175
|
+
|
|
176
|
+
### `@siderust/qtty/units` — unit factories
|
|
177
|
+
|
|
178
|
+
Every named export is a `UnitFactory`: call it with a number to get a `Quantity`.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import { Degrees, Kilometers, Kilograms, Watts } from '@siderust/qtty/units';
|
|
182
|
+
|
|
183
|
+
Degrees(180); // Quantity(180, 'Degree')
|
|
184
|
+
Kilometers(2.5); // Quantity(2.5, 'Kilometer')
|
|
185
|
+
Kilograms(70); // Quantity(70, 'Kilogram')
|
|
186
|
+
Watts(1500); // Quantity(1500, 'Watt')
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Use `unit(name)` for dynamic lookup and `units` for the full registry.
|
|
190
|
+
|
|
191
|
+
### Supported dimensions and units
|
|
192
|
+
|
|
193
|
+
| Dimension | Example units |
|
|
194
|
+
| ---------- | -------------------------------------------------------------------------- |
|
|
195
|
+
| **Length** | `Meter`, `Kilometer`, `Mile`, `AstronomicalUnit`, `Parsec`, `LightYear`, … |
|
|
196
|
+
| **Time** | `Second`, `Minute`, `Hour`, `Day`, `Year`, `JulianCentury`, … |
|
|
197
|
+
| **Angle** | `Radian`, `Degree`, `Arcminute`, `Arcsecond`, `HourAngle`, … |
|
|
198
|
+
| **Mass** | `Gram`, `Kilogram`, `Pound`, `SolarMass`, `AtomicMassUnit`, … |
|
|
199
|
+
| **Power** | `Watt`, `Kilowatt`, `Megawatt`, `SolarLuminosity`, … |
|
|
200
|
+
|
|
201
|
+
Use `isValidUnit(name)` to check at runtime, or see the
|
|
202
|
+
[units.csv](../qtty/qtty-ffi/units.csv) for the full list.
|
|
203
|
+
|
|
204
|
+
## Examples
|
|
205
|
+
|
|
206
|
+
Runnable examples are in the [examples/](examples/) folder:
|
|
207
|
+
|
|
208
|
+
| File | What it shows |
|
|
209
|
+
| ------------------------------------------------- | ----------------------------------------------------------------------- |
|
|
210
|
+
| [quickstart.mjs](examples/quickstart.mjs) | Construction, conversion, `convert()`, `isCompatible()` |
|
|
211
|
+
| [unit_factories.mjs](examples/unit_factories.mjs) | Factory-style construction, metadata, dynamic `unit()`/`units` |
|
|
212
|
+
| [arithmetic.mjs](examples/arithmetic.mjs) | `.add()`, `.sub()`, `.mul()`, `.div()`, velocity with `DerivedQuantity` |
|
|
213
|
+
| [astronomy.mjs](examples/astronomy.mjs) | Parsec/ly/AU scales, angular measures, solar units |
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
node examples/quickstart.mjs
|
|
217
|
+
node examples/unit_factories.mjs
|
|
218
|
+
node examples/arithmetic.mjs
|
|
219
|
+
node examples/astronomy.mjs
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Building from source
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Prerequisites: Rust toolchain
|
|
226
|
+
npm install
|
|
227
|
+
npx napi build --release --platform
|
|
228
|
+
npm test
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Architecture
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
┌──────────────┐ napi-rs ┌──────────────┐ path dep ┌───────────┐
|
|
235
|
+
│ JavaScript │ ◄─────────────► │ qtty-node │ ◄──────────────► │ qtty-ffi │
|
|
236
|
+
│ / TypeScript│ native addon │ (Rust crate) │ registry & │ registry │
|
|
237
|
+
└──────────────┘ └──────────────┘ conversion └───────────┘
|
|
238
|
+
│
|
|
239
|
+
┌────┴────┐
|
|
240
|
+
│ qtty │
|
|
241
|
+
│ (core) │
|
|
242
|
+
└─────────┘
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
All conversion math lives in Rust. The Node layer is a thin wrapper that
|
|
246
|
+
translates between JavaScript strings/numbers and Rust types.
|
|
247
|
+
|
|
248
|
+
## License
|
|
249
|
+
|
|
250
|
+
AGPL-3.0 — see [LICENSE](../LICENSE).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const js = require('@eslint/js');
|
|
2
|
+
const globals = require('globals');
|
|
3
|
+
|
|
4
|
+
const baseRules = {
|
|
5
|
+
...js.configs.recommended.rules,
|
|
6
|
+
'no-console': 'off',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
module.exports = [
|
|
10
|
+
{
|
|
11
|
+
ignores: ['coverage/**', 'node_modules/**', 'target/**', '*.d.ts', '*.node', 'index.js'],
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
files: ['**/*.js'],
|
|
15
|
+
languageOptions: {
|
|
16
|
+
ecmaVersion: 'latest',
|
|
17
|
+
sourceType: 'commonjs',
|
|
18
|
+
globals: globals.node,
|
|
19
|
+
},
|
|
20
|
+
rules: baseRules,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
files: ['**/*.mjs'],
|
|
24
|
+
languageOptions: {
|
|
25
|
+
ecmaVersion: 'latest',
|
|
26
|
+
sourceType: 'module',
|
|
27
|
+
globals: globals.node,
|
|
28
|
+
},
|
|
29
|
+
rules: baseRules,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* arithmetic.mjs — Arithmetic operations on quantities.
|
|
3
|
+
*
|
|
4
|
+
* Run: node examples/arithmetic.mjs
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Meters, Kilometers, Kilograms, Grams } from '../units.js';
|
|
8
|
+
import { DerivedQuantity } from '../index.js';
|
|
9
|
+
|
|
10
|
+
console.log('─── Scalar arithmetic ──────────────────────────────────────────────');
|
|
11
|
+
|
|
12
|
+
const base = Meters(100);
|
|
13
|
+
console.log(` Meters(100).mul(3) = ${base.mul(3)}`); // 300 m
|
|
14
|
+
console.log(` Meters(100).div(4) = ${base.div(4)}`); // 25 m
|
|
15
|
+
console.log(` Meters(100).neg() = ${base.neg()}`); // -100 m
|
|
16
|
+
|
|
17
|
+
console.log('\n─── Quantity addition and subtraction ──────────────────────────────');
|
|
18
|
+
|
|
19
|
+
// Add two lengths, each in different units — result is in the left unit.
|
|
20
|
+
const a = Kilometers(1);
|
|
21
|
+
const b = Meters(500);
|
|
22
|
+
console.log(` Kilometers(1) + Meters(500) = ${a.add(b)}`); // 1.5 km
|
|
23
|
+
console.log(` Kilometers(1) - Meters(500) = ${a.sub(b)}`); // 0.5 km
|
|
24
|
+
|
|
25
|
+
// Add with explicit conversion
|
|
26
|
+
const totalInMeters = Kilometers(1).to('Meter').add(Meters(500));
|
|
27
|
+
console.log(` In Meters: ${totalInMeters}`); // 1500 m
|
|
28
|
+
|
|
29
|
+
console.log('\n─── Chaining conversions and arithmetic ────────────────────────────');
|
|
30
|
+
|
|
31
|
+
// Trip: 3 legs in mixed units, total in km
|
|
32
|
+
const leg1 = Meters(800);
|
|
33
|
+
const leg2 = Kilometers(1.2);
|
|
34
|
+
const leg3 = Meters(400);
|
|
35
|
+
|
|
36
|
+
const total = leg1.to('Kilometer').add(leg2).add(leg3.to('Kilometer'));
|
|
37
|
+
console.log(` Total trip: ${total.format(3)}`); // 2.400 km
|
|
38
|
+
console.log(` In meters: ${total.to('Meter')}`); // 2400 m
|
|
39
|
+
console.log(` In miles: ${total.to('Mile').format(4)}`); // 1.4913 mi
|
|
40
|
+
|
|
41
|
+
console.log('\n─── Derived quantities (velocity = distance / time) ────────────────');
|
|
42
|
+
|
|
43
|
+
// 100 m/s converted to km/h
|
|
44
|
+
const velocity = new DerivedQuantity(100, 'Meter', 'Second');
|
|
45
|
+
const kmh = velocity.to('Kilometer', 'Hour');
|
|
46
|
+
console.log(` 100 m/s → ${kmh.format(1)}`); // 360.0 km/h
|
|
47
|
+
|
|
48
|
+
// Scaling
|
|
49
|
+
const doubled = kmh.mul(2);
|
|
50
|
+
console.log(` 360 km/h × 2 = ${doubled}`); // 720 km/h
|
|
51
|
+
|
|
52
|
+
// Back to SI
|
|
53
|
+
const back = kmh.to('Meter', 'Second');
|
|
54
|
+
console.log(` 360 km/h → ${back.format(6)}`); // 100.000000 m/s
|
|
55
|
+
|
|
56
|
+
console.log('\n─── Mass arithmetic ─────────────────────────────────────────────────');
|
|
57
|
+
|
|
58
|
+
const kg = Kilograms(5);
|
|
59
|
+
const g = Grams(500);
|
|
60
|
+
const combined = kg.add(g); // 5.5 kg
|
|
61
|
+
console.log(` 5 kg + 500 g = ${combined.format(2)}`);
|
|
62
|
+
|
|
63
|
+
const perItem = combined.div(10);
|
|
64
|
+
console.log(` Per 10 items: ${perItem.format(3)}`); // 0.550 kg
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* astronomy.mjs — Astronomy-oriented unit conversions.
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates the wide range of astronomical units available.
|
|
5
|
+
*
|
|
6
|
+
* Run: node examples/astronomy.mjs
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AstronomicalUnits,
|
|
11
|
+
LightYears,
|
|
12
|
+
Parsecs,
|
|
13
|
+
Kiloparsecs,
|
|
14
|
+
Gigaparsecs,
|
|
15
|
+
Degrees,
|
|
16
|
+
MilliArcseconds,
|
|
17
|
+
HourAngles,
|
|
18
|
+
JulianYears,
|
|
19
|
+
SiderealYears,
|
|
20
|
+
SolarMasses,
|
|
21
|
+
Kilograms,
|
|
22
|
+
SolarLuminosities,
|
|
23
|
+
} from '../units.js';
|
|
24
|
+
|
|
25
|
+
console.log('─── Distance scales ────────────────────────────────────────────────');
|
|
26
|
+
|
|
27
|
+
const oneAU = AstronomicalUnits(1);
|
|
28
|
+
console.log(` 1 AU = ${oneAU.to('Kilometer').value.toExponential(4)} km`);
|
|
29
|
+
console.log(` 1 AU = ${oneAU.to('LightYear').value.toExponential(4)} ly`);
|
|
30
|
+
console.log(` 1 AU = ${oneAU.to('Parsec').value.toExponential(4)} pc`);
|
|
31
|
+
|
|
32
|
+
const oneLY = LightYears(1);
|
|
33
|
+
console.log(` 1 ly = ${oneLY.to('AstronomicalUnit').format(2)}`);
|
|
34
|
+
console.log(` 1 ly = ${oneLY.to('Parsec').format(6)}`);
|
|
35
|
+
|
|
36
|
+
const onePc = Parsecs(1);
|
|
37
|
+
console.log(` 1 pc = ${onePc.to('LightYear').format(4)}`); // 3.2616 ly
|
|
38
|
+
console.log(` 1 pc = ${onePc.to('AstronomicalUnit').value.toExponential(4)} AU`);
|
|
39
|
+
|
|
40
|
+
// Cosmological distances
|
|
41
|
+
const andromeda = Kiloparsecs(778);
|
|
42
|
+
console.log(`\n Andromeda Galaxy: ${andromeda.to('Megaparsec').format(3)}`);
|
|
43
|
+
console.log(` Andromeda Galaxy: ${andromeda.to('LightYear').value.toExponential(3)} ly`);
|
|
44
|
+
|
|
45
|
+
const hubbleHorizon = Gigaparsecs(14);
|
|
46
|
+
console.log(` Hubble horizon : ${hubbleHorizon.value} Gpc`);
|
|
47
|
+
|
|
48
|
+
console.log('\n─── Angular measurements ────────────────────────────────────────────');
|
|
49
|
+
|
|
50
|
+
const arcOne = Degrees(1);
|
|
51
|
+
console.log(` 1° = ${arcOne.to('Arcminute').value} ′`);
|
|
52
|
+
console.log(` 1° = ${arcOne.to('Arcsecond').value} ″`);
|
|
53
|
+
console.log(` 1° = ${arcOne.to('Radian').format(8)}`);
|
|
54
|
+
|
|
55
|
+
// Parallax of Proxima Centauri: 768.5 mas
|
|
56
|
+
const proxParallax = MilliArcseconds(768.5);
|
|
57
|
+
const proxParallaxArcsec = proxParallax.to('Arcsecond');
|
|
58
|
+
// Distance in parsecs = 1 / parallax_in_arcsec
|
|
59
|
+
const proxDistPc = Parsecs(1 / proxParallaxArcsec.value);
|
|
60
|
+
console.log(`\n Proxima Centauri parallax: ${proxParallax} = ${proxParallaxArcsec.format(4)}`);
|
|
61
|
+
console.log(` Distance: ${proxDistPc.format(4)} = ${proxDistPc.to('LightYear').format(4)}`);
|
|
62
|
+
|
|
63
|
+
// Hour angles (right ascension)
|
|
64
|
+
const ra = HourAngles(6.75); // RA of Betelgeuse
|
|
65
|
+
console.log(`\n Betelgeuse RA: ${ra} = ${ra.to('Degree').format(4)}`);
|
|
66
|
+
|
|
67
|
+
console.log('\n─── Time scales ─────────────────────────────────────────────────────');
|
|
68
|
+
|
|
69
|
+
const oneYear = JulianYears(1);
|
|
70
|
+
console.log(` 1 Julian year = ${oneYear.to('Day').format(4)}`);
|
|
71
|
+
console.log(` 1 Julian year = ${oneYear.to('Second').value.toExponential(4)} s`);
|
|
72
|
+
|
|
73
|
+
const oneSiderealYear = SiderealYears(1);
|
|
74
|
+
console.log(` 1 Sidereal year = ${oneSiderealYear.to('Day').format(6)}`);
|
|
75
|
+
const diff = SiderealYears(1).to('Second').sub(JulianYears(1).to('Second'));
|
|
76
|
+
console.log(` Sidereal − Julian year = ${diff.format(2)}`);
|
|
77
|
+
|
|
78
|
+
console.log('\n─── Masses ──────────────────────────────────────────────────────────');
|
|
79
|
+
|
|
80
|
+
const oneSolar = SolarMasses(1);
|
|
81
|
+
console.log(` 1 M_☉ = ${oneSolar.to('Kilogram').value.toExponential(4)} kg`);
|
|
82
|
+
|
|
83
|
+
const earthMass = Kilograms(5.972e24);
|
|
84
|
+
console.log(` Earth = ${earthMass.to('SolarMass').value.toExponential(4)} M_☉`);
|
|
85
|
+
|
|
86
|
+
console.log('\n─── Luminosity ──────────────────────────────────────────────────────');
|
|
87
|
+
|
|
88
|
+
const oneSolarLum = SolarLuminosities(1);
|
|
89
|
+
console.log(` 1 L_☉ = ${oneSolarLum.to('Watt').value.toExponential(4)} W`);
|
|
90
|
+
console.log(` 1 L_☉ = ${oneSolarLum.to('Megawatt').value.toExponential(4)} MW`);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* quickstart.mjs — Basic quantity creation and conversion.
|
|
3
|
+
*
|
|
4
|
+
* Run: node examples/quickstart.mjs
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Quantity, convert, isCompatible } from '../index.js';
|
|
8
|
+
|
|
9
|
+
console.log('─── Construction ───────────────────────────────────────────');
|
|
10
|
+
|
|
11
|
+
const distance = new Quantity(1000, 'Meter');
|
|
12
|
+
console.log(`Created: ${distance}`); // 1000 m
|
|
13
|
+
console.log(`value: ${distance.value}`); // 1000
|
|
14
|
+
console.log(`unit: ${distance.unit}`); // Meter
|
|
15
|
+
console.log(`symbol: ${distance.symbol}`); // m
|
|
16
|
+
console.log(`dim: ${distance.dimension}`); // Length
|
|
17
|
+
|
|
18
|
+
console.log('\n─── Conversions ────────────────────────────────────────────');
|
|
19
|
+
|
|
20
|
+
const km = distance.to('Kilometer');
|
|
21
|
+
console.log(`1000 m → ${km}`); // 1 km
|
|
22
|
+
|
|
23
|
+
const ft = distance.to('Foot');
|
|
24
|
+
console.log(`1000 m → ${ft.format(2)}`); // 3280.84 ft
|
|
25
|
+
|
|
26
|
+
const mi = distance.to('Mile');
|
|
27
|
+
console.log(`1000 m → ${mi.format(4)}`); // 0.6214 mi
|
|
28
|
+
|
|
29
|
+
console.log('\n─── Free convert() ─────────────────────────────────────────');
|
|
30
|
+
|
|
31
|
+
console.log(`7200 s → ${convert(7200, 'Second', 'Hour')} h`); // 2
|
|
32
|
+
console.log(`180 deg → ${convert(180, 'Degree', 'Radian').toFixed(6)} rad`); // 3.141593
|
|
33
|
+
|
|
34
|
+
console.log('\n─── Compatibility check ────────────────────────────────────');
|
|
35
|
+
console.log(`Meter ↔ Kilometer? ${isCompatible('Meter', 'Kilometer')}`); // true
|
|
36
|
+
console.log(`Meter ↔ Second? ${isCompatible('Meter', 'Second')}`); // false
|