Utility library written in Rust and compiled to WebAssembly via
wasm-bindgen, designed to be
consumed from Node.js.
| Tool | Tested version | Notes |
|---|---|---|
| Rust (rustc/cargo) | 1.96.0 | edition 2024 (MSRV 1.85) |
wasm32-unknown-unknown target |
— | required to compile to WASM |
wasm-pack |
0.15.0 | generates the JS-consumable package |
| Node.js | ≥ 16 | to use the generated package |
Installing the Rust prerequisites:
# Rust toolchain (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# WebAssembly compilation target
rustup target add wasm32-unknown-unknown
# wasm-pack
cargo install wasm-packwasm-pack is the tool that produces the JS-consumable WebAssembly package: it
compiles the crate to wasm, runs wasm-bindgen to emit the JS/TypeScript glue,
and optimizes the binary with wasm-opt.
The key flag is --target nodejs, which emits CommonJS glue
(require/module.exports) rather than bundler- or browser-oriented output.
# Production build (optimized) — this is the command to generate the package
wasm-pack build --target nodejs --release
# Development build (faster, unoptimized)
wasm-pack build --target nodejs --devNote: plain
cargo build --target wasm32-unknown-unknownonly compiles the crate to a raw.wasm— it does not runwasm-bindgen/wasm-optand does not produce the consumablepkg/. Use it only as a quick compile check.
The output is written to the pkg/ directory (git-ignored):
pkg/
├── package.json # npm manifest of the generated package
├── radar_console_utils.js # JS glue code (entrypoint, "main")
├── radar_console_utils.d.ts # TypeScript types
├── radar_console_utils_bg.wasm # WebAssembly binary
└── radar_console_utils_bg.wasm.d.ts # wasm module types
const utils = require("./pkg/radar_console_utils.js");
// Top-level function
console.log(utils.getApiVersion()); // "1.0.0"
// MathUtils (static methods)
console.log(utils.MathUtils.linear2dB(100)); // 20
console.log(utils.MathUtils.metersByBin(0, 1)); // 10.463...
const power = utils.MathUtils.computeRawPowerFast(
Float64Array.from([1, 2, 3]),
Float64Array.from([4, 5, 6]),
);
console.log(power); // Float64Array [17, 29, 45]
// DataUtils (static methods)
console.log(utils.DataUtils.testComunicazione());getApiVersion(): stringMathUtils.linear2dB(power: number): numberMathUtils.metersByBin(bin: number, miles: number): numberMathUtils.getTargetColor(levels: Float64Array, value: number, minVisibleColorLevel: number): numberMathUtils.computeRawPowerFast(iData: Float64Array, qData: Float64Array): Float64ArrayDataUtils.testComunicazione(): string
# Quick compile check only (does NOT generate pkg/ — see the note above)
cargo build --target wasm32-unknown-unknown
# Lint
cargo clippy --target wasm32-unknown-unknown --all-targetsNote: since this is a WASM-oriented
cdylib, the only exposed functions are those annotated with#[wasm_bindgen]and declared insrc/lib.rs(currently themath_utilsanddata_utilsmodules).