JavaScript in. WebAssembly out.
A jz template turns a piece of JavaScript into a WebAssembly module. Export a function, then call it from your app.
import jz from 'jz'
const { exports } = jz`
export const dist = (x, y) =>
(x*x + y*y) ** 0.5
`
console.log(exports.dist(3, 4)) // 5
The tag compiles and instantiates once. Keep the module around; each call to exports.dist runs WebAssembly. The function itself is ordinary JavaScript, with no type annotations.
npm install jz
Or start in the playground — nothing to install.
Give it a whole loop
A tiny function shows the pattern. Numeric loops are where to try it: process a whole array in one call, so useful work outweighs the cost of crossing into WASM.
import jz from 'jz'
const { exports, memory } = jz`
export const sum = a => {
let total = 0
for (const x of a) total += x
return total
}
`
const values = new Float64Array([1, 2, 3])
console.log(exports.sum(values)) // 6
memory.reset()
The wrapper handles arrays, strings and objects. Heap allocations accumulate until reset; finish the batch before calling memory.reset(), which invalidates prior WASM pointers and views. See the memory contract when keeping state between calls.
Keep the source. Ship the module.
Already have a numeric kernel? Keep it in a regular .js file, export its functions, and compile it during your build:
npx jz kernel.js -o kernel.wasm
The original file remains your JavaScript fallback. Ship the compiled module and load it with instantiate from jz/interop; the compiler stays in the build step. API and CLI reference →
Start with one kernel and run your existing tests against both versions. JZ is experimental and supports a JavaScript subset; measure the full call, including data transfer.