2025-08-08 07:06:47 +02:00
|
|
|
To build and use this:
|
|
|
|
|
|
|
|
|
|
1. Install wasm-pack (if you haven't already):
|
|
|
|
|
```bash
|
|
|
|
|
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. Build the WASM module:
|
|
|
|
|
```bash
|
|
|
|
|
wasm-pack build --target web --out-dir pkg
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
3. Serve the HTML file using a local HTTP server (required for ES modules):
|
|
|
|
|
```bash
|
|
|
|
|
python3 -m http.server 8000
|
|
|
|
|
# or
|
|
|
|
|
npx serve .
|
|
|
|
|
```
|
2025-08-08 07:17:39 +02:00
|
|
|
|
|
|
|
|
4. Use the API:
|
|
|
|
|
```js
|
|
|
|
|
try {
|
2025-08-08 09:57:55 +02:00
|
|
|
const result = evaluate_cel("name + ' is ' + string(age)", {name: "Alice", age: 30});
|
2025-08-08 07:17:39 +02:00
|
|
|
console.log(result);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
```
|