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,21 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "qtty-web"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
authors = ["VPRamon <vallespuigramon@gmail.com>"]
|
|
6
|
+
license = "AGPL-3.0"
|
|
7
|
+
repository = "https://github.com/Siderust/qtty"
|
|
8
|
+
description = "Browser/WASM bindings for qtty — physical quantities and unit conversions in the browser"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
|
|
11
|
+
[lib]
|
|
12
|
+
crate-type = ["cdylib", "rlib"]
|
|
13
|
+
|
|
14
|
+
[dependencies]
|
|
15
|
+
qtty-ffi = { path = "../qtty/qtty-ffi" }
|
|
16
|
+
serde_json = "1.0"
|
|
17
|
+
wasm-bindgen = "0.2"
|
|
18
|
+
serde = { version = "1.0", features = ["derive"] }
|
|
19
|
+
serde-wasm-bindgen = "0.6"
|
|
20
|
+
js-sys = "0.3"
|
|
21
|
+
console_error_panic_hook = "0.1"
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
// ─── Initialisation ────────────────────────────────────────────────────────
|
|
4
|
+
/**
|
|
5
|
+
* Initialise the WASM module. Must be called (and `await`-ed) before any
|
|
6
|
+
* other function in this package.
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import { init, Quantity } from '@siderust/qtty-web';
|
|
10
|
+
* await init();
|
|
11
|
+
* const d = new Quantity(1000, 'Meter');
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function init(
|
|
15
|
+
module_or_path?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module
|
|
16
|
+
): Promise<void>;
|
|
17
|
+
|
|
18
|
+
// ─── Types ─────────────────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
/** Plain JSON-serializable representation of a quantity. */
|
|
21
|
+
export interface QuantityJson {
|
|
22
|
+
value: number;
|
|
23
|
+
unit: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Plain JSON-serializable representation of a derived quantity. */
|
|
27
|
+
export interface DerivedQuantityJson {
|
|
28
|
+
value: number;
|
|
29
|
+
numerator: string;
|
|
30
|
+
denominator: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Metadata about a single unit returned by `listUnits`. */
|
|
34
|
+
export interface UnitInfo {
|
|
35
|
+
name: string;
|
|
36
|
+
symbol: string;
|
|
37
|
+
dimension: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ─── Quantity ──────────────────────────────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
export class Quantity {
|
|
43
|
+
constructor(value: number, unit: string);
|
|
44
|
+
get value(): number;
|
|
45
|
+
get unit(): string;
|
|
46
|
+
get symbol(): string;
|
|
47
|
+
get dimension(): string;
|
|
48
|
+
to(unit: string): Quantity;
|
|
49
|
+
compatible(other: Quantity): boolean;
|
|
50
|
+
add(other: Quantity): Quantity;
|
|
51
|
+
sub(other: Quantity): Quantity;
|
|
52
|
+
mul(scalar: number): Quantity;
|
|
53
|
+
div(scalar: number): Quantity;
|
|
54
|
+
neg(): Quantity;
|
|
55
|
+
format(precision?: number | null): string;
|
|
56
|
+
toJson(): QuantityJson;
|
|
57
|
+
toString(): string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ─── DerivedQuantity ──────────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
export class DerivedQuantity {
|
|
63
|
+
constructor(value: number, numerator: string, denominator: string);
|
|
64
|
+
get value(): number;
|
|
65
|
+
get numerator(): string;
|
|
66
|
+
get denominator(): string;
|
|
67
|
+
get symbol(): string;
|
|
68
|
+
to(numerator: string, denominator: string): DerivedQuantity;
|
|
69
|
+
mul(scalar: number): DerivedQuantity;
|
|
70
|
+
div(scalar: number): DerivedQuantity;
|
|
71
|
+
neg(): DerivedQuantity;
|
|
72
|
+
format(precision?: number | null): string;
|
|
73
|
+
toJson(): DerivedQuantityJson;
|
|
74
|
+
toString(): string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ─── Free functions ───────────────────────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
export function convert(value: number, fromUnit: string, toUnit: string): number;
|
|
80
|
+
export function isCompatible(unitA: string, unitB: string): boolean;
|
|
81
|
+
export function unitDimension(unit: string): string;
|
|
82
|
+
export function unitSymbol(unit: string): string;
|
|
83
|
+
export function isValidUnit(unit: string): boolean;
|
|
84
|
+
export function ffiVersion(): number;
|
|
85
|
+
export function listUnits(): UnitInfo[];
|
|
86
|
+
|
|
87
|
+
// ─── Unit const map ──────────────────────────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
/** Union of every registered unit name. */
|
|
90
|
+
export type UnitName =
|
|
91
|
+
// Length
|
|
92
|
+
| 'PlanckLength' | 'Yoctometer' | 'Zeptometer' | 'Attometer' | 'Femtometer'
|
|
93
|
+
| 'Picometer' | 'Nanometer' | 'Micrometer' | 'Millimeter' | 'Centimeter'
|
|
94
|
+
| 'Decimeter' | 'Meter' | 'Decameter' | 'Hectometer' | 'Kilometer'
|
|
95
|
+
| 'Megameter' | 'Gigameter' | 'Terameter' | 'Petameter' | 'Exameter'
|
|
96
|
+
| 'Zettameter' | 'Yottameter' | 'BohrRadius' | 'ClassicalElectronRadius'
|
|
97
|
+
| 'ElectronReducedComptonWavelength' | 'AstronomicalUnit' | 'LightYear'
|
|
98
|
+
| 'Parsec' | 'Kiloparsec' | 'Megaparsec' | 'Gigaparsec'
|
|
99
|
+
| 'Inch' | 'Foot' | 'Yard' | 'Mile' | 'Link' | 'Fathom' | 'Rod' | 'Chain'
|
|
100
|
+
| 'NauticalMile' | 'NominalLunarRadius' | 'NominalLunarDistance'
|
|
101
|
+
| 'NominalEarthPolarRadius' | 'NominalEarthRadius' | 'NominalEarthEquatorialRadius'
|
|
102
|
+
| 'EarthMeridionalCircumference' | 'EarthEquatorialCircumference'
|
|
103
|
+
| 'NominalJupiterRadius' | 'NominalSolarRadius' | 'NominalSolarDiameter'
|
|
104
|
+
// Time
|
|
105
|
+
| 'Attosecond' | 'Femtosecond' | 'Picosecond' | 'Nanosecond' | 'Microsecond'
|
|
106
|
+
| 'Millisecond' | 'Centisecond' | 'Decisecond' | 'Second' | 'Decasecond'
|
|
107
|
+
| 'Hectosecond' | 'Kilosecond' | 'Megasecond' | 'Gigasecond' | 'Terasecond'
|
|
108
|
+
| 'Minute' | 'Hour' | 'Day' | 'Week' | 'Fortnight' | 'Year' | 'Decade'
|
|
109
|
+
| 'Century' | 'Millennium' | 'JulianYear' | 'JulianCentury'
|
|
110
|
+
| 'SiderealDay' | 'SynodicMonth' | 'SiderealYear'
|
|
111
|
+
// Angle
|
|
112
|
+
| 'Milliradian' | 'Radian' | 'MicroArcsecond' | 'MilliArcsecond'
|
|
113
|
+
| 'Arcsecond' | 'Arcminute' | 'Degree' | 'Gradian' | 'Turn' | 'HourAngle'
|
|
114
|
+
// Mass
|
|
115
|
+
| 'Yoctogram' | 'Zeptogram' | 'Attogram' | 'Femtogram' | 'Picogram'
|
|
116
|
+
| 'Nanogram' | 'Microgram' | 'Milligram' | 'Centigram' | 'Decigram'
|
|
117
|
+
| 'Gram' | 'Decagram' | 'Hectogram' | 'Kilogram' | 'Megagram' | 'Gigagram'
|
|
118
|
+
| 'Teragram' | 'Petagram' | 'Exagram' | 'Zettagram' | 'Yottagram'
|
|
119
|
+
| 'Grain' | 'Ounce' | 'Pound' | 'Stone' | 'ShortTon' | 'LongTon'
|
|
120
|
+
| 'Carat' | 'Tonne' | 'AtomicMassUnit' | 'SolarMass'
|
|
121
|
+
// Power
|
|
122
|
+
| 'Yoctowatt' | 'Zeptowatt' | 'Attowatt' | 'Femtowatt' | 'Picowatt'
|
|
123
|
+
| 'Nanowatt' | 'Microwatt' | 'Milliwatt' | 'Deciwatt' | 'Watt' | 'Decawatt'
|
|
124
|
+
| 'Hectowatt' | 'Kilowatt' | 'Megawatt' | 'Gigawatt' | 'Terawatt' | 'Petawatt'
|
|
125
|
+
| 'Exawatt' | 'Zettawatt' | 'Yottawatt'
|
|
126
|
+
| 'ErgPerSecond' | 'HorsepowerMetric' | 'HorsepowerElectric' | 'SolarLuminosity';
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Const map of all registered unit names (available after `init()`).
|
|
130
|
+
*
|
|
131
|
+
* `Unit.Meter === 'Meter'` — each key equals its own name.
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* import { init, Quantity, Unit } from '@siderust/qtty-web';
|
|
135
|
+
* await init();
|
|
136
|
+
* const d = new Quantity(1000, Unit.Meter);
|
|
137
|
+
* const km = d.to(Unit.Kilometer);
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare const Unit: { readonly [K in UnitName]: K };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @siderust/qtty-web — Physical quantities and unit conversions for the browser.
|
|
3
|
+
*
|
|
4
|
+
* Call `init()` (and `await` it) before using any other export.
|
|
5
|
+
*
|
|
6
|
+
* @module @siderust/qtty-web
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export { init, Unit } from './lib/backend.js';
|
|
10
|
+
export { Quantity } from './lib/Quantity.js';
|
|
11
|
+
export { DerivedQuantity } from './lib/DerivedQuantity.js';
|
|
12
|
+
export {
|
|
13
|
+
convert,
|
|
14
|
+
isCompatible,
|
|
15
|
+
unitDimension,
|
|
16
|
+
unitSymbol,
|
|
17
|
+
isValidUnit,
|
|
18
|
+
ffiVersion,
|
|
19
|
+
listUnits,
|
|
20
|
+
} from './lib/backend.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @siderust/qtty-web — DerivedQuantity façade class (browser/WASM).
|
|
3
|
+
*
|
|
4
|
+
* Identical API to the Node version.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as backend from './backend.js';
|
|
8
|
+
|
|
9
|
+
export class DerivedQuantity {
|
|
10
|
+
constructor(value, numerator, denominator) {
|
|
11
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
12
|
+
throw new Error('DerivedQuantity value must be a finite number');
|
|
13
|
+
}
|
|
14
|
+
if (!backend.isValidUnit(numerator)) {
|
|
15
|
+
throw new Error(`Unknown numerator unit: "${numerator}"`);
|
|
16
|
+
}
|
|
17
|
+
if (!backend.isValidUnit(denominator)) {
|
|
18
|
+
throw new Error(`Unknown denominator unit: "${denominator}"`);
|
|
19
|
+
}
|
|
20
|
+
this._value = value;
|
|
21
|
+
this._numerator = numerator;
|
|
22
|
+
this._denominator = denominator;
|
|
23
|
+
this._numSymbol = backend.unitSymbol(numerator);
|
|
24
|
+
this._denSymbol = backend.unitSymbol(denominator);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get value() { return this._value; }
|
|
28
|
+
get numerator() { return this._numerator; }
|
|
29
|
+
get denominator() { return this._denominator; }
|
|
30
|
+
get symbol() { return `${this._numSymbol}/${this._denSymbol}`; }
|
|
31
|
+
|
|
32
|
+
to(numerator, denominator) {
|
|
33
|
+
const numFactor = backend.convert(1, this._numerator, numerator);
|
|
34
|
+
const denFactor = backend.convert(1, this._denominator, denominator);
|
|
35
|
+
return new DerivedQuantity(this._value * numFactor / denFactor, numerator, denominator);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
mul(scalar) { return new DerivedQuantity(this._value * scalar, this._numerator, this._denominator); }
|
|
39
|
+
div(scalar) { return new DerivedQuantity(this._value / scalar, this._numerator, this._denominator); }
|
|
40
|
+
neg() { return new DerivedQuantity(-this._value, this._numerator, this._denominator); }
|
|
41
|
+
|
|
42
|
+
format(precision) {
|
|
43
|
+
const v = precision != null && precision >= 0
|
|
44
|
+
? this._value.toFixed(precision)
|
|
45
|
+
: String(this._value);
|
|
46
|
+
return `${v} ${this.symbol}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
toJson() {
|
|
50
|
+
return {
|
|
51
|
+
value: this._value,
|
|
52
|
+
numerator: this._numerator,
|
|
53
|
+
denominator: this._denominator,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
toString() { return this.format(); }
|
|
58
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @siderust/qtty-web — Quantity façade class (browser/WASM).
|
|
3
|
+
*
|
|
4
|
+
* Identical API to the Node version. This module uses the WASM backend
|
|
5
|
+
* for unit conversions and metadata.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as backend from './backend.js';
|
|
9
|
+
|
|
10
|
+
export class Quantity {
|
|
11
|
+
/**
|
|
12
|
+
* @param {number} value Numeric value.
|
|
13
|
+
* @param {string} unit Unit name, e.g. `"Meter"`, `"Kilometer"`.
|
|
14
|
+
*/
|
|
15
|
+
constructor(value, unit) {
|
|
16
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
17
|
+
throw new Error('Quantity value must be a finite number');
|
|
18
|
+
}
|
|
19
|
+
if (!backend.isValidUnit(unit)) {
|
|
20
|
+
throw new Error(`Unknown unit: "${unit}". Use listUnits() to list valid units.`);
|
|
21
|
+
}
|
|
22
|
+
this._value = value;
|
|
23
|
+
this._unit = unit;
|
|
24
|
+
this._symbol = backend.unitSymbol(unit);
|
|
25
|
+
this._dimension = backend.unitDimension(unit);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get value() { return this._value; }
|
|
29
|
+
get unit() { return this._unit; }
|
|
30
|
+
get symbol() { return this._symbol; }
|
|
31
|
+
get dimension() { return this._dimension; }
|
|
32
|
+
|
|
33
|
+
to(targetUnit) {
|
|
34
|
+
const converted = backend.convert(this._value, this._unit, targetUnit);
|
|
35
|
+
return new Quantity(converted, targetUnit);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
compatible(other) {
|
|
39
|
+
return backend.isCompatible(this._unit, other._unit);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
add(other) {
|
|
43
|
+
if (!this.compatible(other)) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Cannot add quantities with different dimensions: ${this._dimension} vs ${other._dimension}`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const otherInMyUnit = backend.convert(other._value, other._unit, this._unit);
|
|
49
|
+
return new Quantity(this._value + otherInMyUnit, this._unit);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
sub(other) {
|
|
53
|
+
if (!this.compatible(other)) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Cannot subtract quantities with different dimensions: ${this._dimension} vs ${other._dimension}`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const otherInMyUnit = backend.convert(other._value, other._unit, this._unit);
|
|
59
|
+
return new Quantity(this._value - otherInMyUnit, this._unit);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
mul(scalar) { return new Quantity(this._value * scalar, this._unit); }
|
|
63
|
+
div(scalar) { return new Quantity(this._value / scalar, this._unit); }
|
|
64
|
+
neg() { return new Quantity(-this._value, this._unit); }
|
|
65
|
+
|
|
66
|
+
format(precision) {
|
|
67
|
+
const v = precision != null && precision >= 0
|
|
68
|
+
? this._value.toFixed(precision)
|
|
69
|
+
: String(this._value);
|
|
70
|
+
return `${v} ${this._symbol}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
toJson() { return { value: this._value, unit: this._unit }; }
|
|
74
|
+
toString() { return this.format(); }
|
|
75
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @siderust/qtty-web — Internal WASM backend abstraction.
|
|
3
|
+
*
|
|
4
|
+
* Loads the wasm-bindgen generated module and re-exports the primitive
|
|
5
|
+
* free functions that the shared JS façade classes need.
|
|
6
|
+
*
|
|
7
|
+
* @module @siderust/qtty-web/lib/backend
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
let wasm = null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initialise the WASM module. Must be called before any other function.
|
|
15
|
+
* @param {RequestInfo | URL | Response | BufferSource | WebAssembly.Module} [module_or_path]
|
|
16
|
+
*/
|
|
17
|
+
export async function init(module_or_path) {
|
|
18
|
+
const mod = await import('../pkg/qtty_web.js');
|
|
19
|
+
await mod.default(module_or_path);
|
|
20
|
+
wasm = mod;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function ensureInit() {
|
|
24
|
+
if (!wasm) {
|
|
25
|
+
throw new Error('@siderust/qtty-web: call init() before using any function');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function convert(value, fromUnit, toUnit) {
|
|
30
|
+
ensureInit();
|
|
31
|
+
return wasm.convert(value, fromUnit, toUnit);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isCompatible(unitA, unitB) {
|
|
35
|
+
ensureInit();
|
|
36
|
+
return wasm.isCompatible(unitA, unitB);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function unitDimension(unit) {
|
|
40
|
+
ensureInit();
|
|
41
|
+
return wasm.unitDimension(unit);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function unitSymbol(unit) {
|
|
45
|
+
ensureInit();
|
|
46
|
+
return wasm.unitSymbol(unit);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function isValidUnit(unit) {
|
|
50
|
+
ensureInit();
|
|
51
|
+
return wasm.isValidUnit(unit);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function listUnits() {
|
|
55
|
+
ensureInit();
|
|
56
|
+
return wasm.listUnits();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function ffiVersion() {
|
|
60
|
+
ensureInit();
|
|
61
|
+
return wasm.ffiVersion();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Const map of all registered unit names. Available after `init()`.
|
|
66
|
+
* `Unit.Meter === 'Meter'` — every key equals its own name.
|
|
67
|
+
* @type {Readonly<{[key: string]: string}>}
|
|
68
|
+
*/
|
|
69
|
+
export const Unit = new Proxy(Object.freeze({}), {
|
|
70
|
+
get(_, prop) {
|
|
71
|
+
if (typeof prop !== 'string') return undefined;
|
|
72
|
+
ensureInit();
|
|
73
|
+
return prop;
|
|
74
|
+
},
|
|
75
|
+
has(_, prop) {
|
|
76
|
+
if (typeof prop !== 'string') return false;
|
|
77
|
+
ensureInit();
|
|
78
|
+
return wasm.isValidUnit(prop);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@siderust/qtty-web",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Strongly-typed physical quantities and unit conversions for the browser — powered by Rust + WebAssembly",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"import": "./index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "wasm-pack build --target web --out-dir pkg --release --scope siderust",
|
|
16
|
+
"build:dev": "wasm-pack build --target web --out-dir pkg --dev --scope siderust",
|
|
17
|
+
"build:bundler": "wasm-pack build --target bundler --out-dir pkg --release --scope siderust",
|
|
18
|
+
"clean": "rm -rf pkg/"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"pkg/qtty_web_bg.wasm",
|
|
22
|
+
"pkg/qtty_web.js",
|
|
23
|
+
"pkg/qtty_web.d.ts",
|
|
24
|
+
"lib/",
|
|
25
|
+
"index.js",
|
|
26
|
+
"index.d.ts",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"keywords": [
|
|
30
|
+
"quantities",
|
|
31
|
+
"units",
|
|
32
|
+
"conversion",
|
|
33
|
+
"physics",
|
|
34
|
+
"science",
|
|
35
|
+
"wasm",
|
|
36
|
+
"webassembly",
|
|
37
|
+
"browser",
|
|
38
|
+
"rust"
|
|
39
|
+
],
|
|
40
|
+
"license": "AGPL-3.0",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/Siderust/qtty"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//! Browser/WASM bindings for `qtty` physical quantities — free-function backend.
|
|
2
|
+
//!
|
|
3
|
+
//! This crate provides the same set of primitive free functions as the Node
|
|
4
|
+
//! backend (`qtty-node`) but using `wasm-bindgen` instead of `napi-rs`.
|
|
5
|
+
//! The public JS façade classes (`Quantity`, `DerivedQuantity`) are shared
|
|
6
|
+
//! across both backends.
|
|
7
|
+
|
|
8
|
+
use qtty_ffi::registry;
|
|
9
|
+
use qtty_ffi::{DimensionId, UnitId};
|
|
10
|
+
use wasm_bindgen::prelude::*;
|
|
11
|
+
|
|
12
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
13
|
+
// Helpers
|
|
14
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
fn parse_unit(name: &str) -> Result<UnitId, JsValue> {
|
|
17
|
+
let json = format!("\"{}\"", name);
|
|
18
|
+
serde_json::from_str::<UnitId>(&json)
|
|
19
|
+
.map_err(|_| JsValue::from_str(&format!("Unknown unit: \"{name}\"")))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fn dimension_to_string(dim: DimensionId) -> &'static str {
|
|
23
|
+
match dim {
|
|
24
|
+
DimensionId::Length => "Length",
|
|
25
|
+
DimensionId::Time => "Time",
|
|
26
|
+
DimensionId::Angle => "Angle",
|
|
27
|
+
DimensionId::Mass => "Mass",
|
|
28
|
+
DimensionId::Power => "Power",
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
33
|
+
// Free functions (backend primitives for the JS façade)
|
|
34
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
#[wasm_bindgen]
|
|
37
|
+
pub fn convert(value: f64, from_unit: &str, to_unit: &str) -> Result<f64, JsValue> {
|
|
38
|
+
let src = parse_unit(from_unit)?;
|
|
39
|
+
let dst = parse_unit(to_unit)?;
|
|
40
|
+
registry::convert_value(value, src, dst)
|
|
41
|
+
.map_err(|code| JsValue::from_str(&format!("Conversion error (code {})", code)))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#[wasm_bindgen(js_name = "isCompatible")]
|
|
45
|
+
pub fn is_compatible(unit_a: &str, unit_b: &str) -> Result<bool, JsValue> {
|
|
46
|
+
let a = parse_unit(unit_a)?;
|
|
47
|
+
let b = parse_unit(unit_b)?;
|
|
48
|
+
Ok(registry::compatible(a, b))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#[wasm_bindgen(js_name = "unitDimension")]
|
|
52
|
+
pub fn unit_dimension(unit: &str) -> Result<String, JsValue> {
|
|
53
|
+
let id = parse_unit(unit)?;
|
|
54
|
+
registry::dimension(id)
|
|
55
|
+
.map(|d| dimension_to_string(d).to_string())
|
|
56
|
+
.ok_or_else(|| JsValue::from_str(&format!("Unknown unit: \"{unit}\"")))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#[wasm_bindgen(js_name = "unitSymbol")]
|
|
60
|
+
pub fn unit_symbol(unit: &str) -> Result<String, JsValue> {
|
|
61
|
+
let id = parse_unit(unit)?;
|
|
62
|
+
if registry::meta(id).is_none() {
|
|
63
|
+
return Err(JsValue::from_str(&format!("Unknown unit: \"{unit}\"")));
|
|
64
|
+
}
|
|
65
|
+
Ok(id.symbol().to_string())
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#[wasm_bindgen(js_name = "isValidUnit")]
|
|
69
|
+
pub fn is_valid_unit(unit: &str) -> bool {
|
|
70
|
+
parse_unit(unit)
|
|
71
|
+
.ok()
|
|
72
|
+
.and_then(|id| registry::meta(id))
|
|
73
|
+
.is_some()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[wasm_bindgen(js_name = "ffiVersion")]
|
|
77
|
+
pub fn ffi_version() -> u32 {
|
|
78
|
+
qtty_ffi::qtty_ffi_version()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#[wasm_bindgen(js_name = "listUnits")]
|
|
82
|
+
pub fn list_units() -> JsValue {
|
|
83
|
+
let ranges: &[(u32, u32)] = &[
|
|
84
|
+
(10000, 16000),
|
|
85
|
+
(20000, 24000),
|
|
86
|
+
(30000, 33000),
|
|
87
|
+
(40000, 43000),
|
|
88
|
+
(50000, 52000),
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
let arr = js_sys::Array::new();
|
|
92
|
+
for &(start, end) in ranges {
|
|
93
|
+
for discriminant in start..end {
|
|
94
|
+
if let Some(id) = UnitId::from_u32(discriminant) {
|
|
95
|
+
if let Some(meta) = registry::meta(id) {
|
|
96
|
+
let obj = js_sys::Object::new();
|
|
97
|
+
js_sys::Reflect::set(&obj, &"name".into(), &id.name().into()).unwrap();
|
|
98
|
+
js_sys::Reflect::set(&obj, &"symbol".into(), &id.symbol().into()).unwrap();
|
|
99
|
+
js_sys::Reflect::set(
|
|
100
|
+
&obj,
|
|
101
|
+
&"dimension".into(),
|
|
102
|
+
&dimension_to_string(meta.dim).into(),
|
|
103
|
+
)
|
|
104
|
+
.unwrap();
|
|
105
|
+
arr.push(&obj);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
arr.into()
|
|
111
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
5
|
+
PACKAGE_DIR="$ROOT_DIR/qtty-node"
|
|
6
|
+
STEP="${1:-all}"
|
|
7
|
+
|
|
8
|
+
run_install() {
|
|
9
|
+
cd "$PACKAGE_DIR"
|
|
10
|
+
npm ci
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
run_format() {
|
|
14
|
+
cd "$PACKAGE_DIR"
|
|
15
|
+
npm run format:check
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
run_lint() {
|
|
19
|
+
cd "$PACKAGE_DIR"
|
|
20
|
+
npm run lint
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
run_build() {
|
|
24
|
+
cd "$PACKAGE_DIR"
|
|
25
|
+
if [[ "${BUILD_MODE:-debug}" == "release" ]]; then
|
|
26
|
+
npm run build
|
|
27
|
+
else
|
|
28
|
+
npm run build:debug
|
|
29
|
+
fi
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
run_test() {
|
|
33
|
+
cd "$PACKAGE_DIR"
|
|
34
|
+
npm test
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
run_coverage() {
|
|
38
|
+
cd "$PACKAGE_DIR"
|
|
39
|
+
npm run test:coverage
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
case "$STEP" in
|
|
43
|
+
install)
|
|
44
|
+
run_install
|
|
45
|
+
;;
|
|
46
|
+
format)
|
|
47
|
+
run_format
|
|
48
|
+
;;
|
|
49
|
+
lint)
|
|
50
|
+
run_lint
|
|
51
|
+
;;
|
|
52
|
+
build)
|
|
53
|
+
run_build
|
|
54
|
+
;;
|
|
55
|
+
test)
|
|
56
|
+
run_test
|
|
57
|
+
;;
|
|
58
|
+
coverage)
|
|
59
|
+
run_coverage
|
|
60
|
+
;;
|
|
61
|
+
all)
|
|
62
|
+
run_install
|
|
63
|
+
run_format
|
|
64
|
+
run_lint
|
|
65
|
+
run_build
|
|
66
|
+
run_test
|
|
67
|
+
run_coverage
|
|
68
|
+
;;
|
|
69
|
+
*)
|
|
70
|
+
echo "Usage: $0 [install|format|lint|build|test|coverage|all]" >&2
|
|
71
|
+
exit 1
|
|
72
|
+
;;
|
|
73
|
+
esac
|