QCL can be compiled to WebAssembly via wasm-bindgen.
cargo install wasm-pack
rustup target add wasm32-unknown-unknownmake wasm
# or directly:
wasm-pack build --target web --release -- --features wasmOutput is generated in the pkg/ directory.
Evaluate a QCL expression against a JSON context string. Returns the result as a string.
import init, { eval_json } from "./pkg/qcl.js";
await init();
const result = eval_json('@user.role == "admin"', '{"user": {"role": "admin"}}');
console.log(result); // "true"Evaluate a QCL expression against a JS object. Returns the result as a JS value.
import init, { eval as qclEval } from "./pkg/qcl.js";
await init();
const result = qclEval("@x + 1", { x: 2 });
console.log(result); // 3wasm-pack supports different targets:
| Target | Flag | Use case |
|---|---|---|
| Web (ESM) | --target web |
<script type="module"> |
| Bundler | --target bundler |
Webpack / Vite |
| Node.js | --target nodejs |
Server-side Node |
Example for bundler:
wasm-pack build --target bundler --release -- --features wasm