This quickstart uses vite to quickly scaffold a JavaScript project.
npm create vite@latest # select the options you want
npm install dot.wasm # install the library
Now where you want to use the library (in a JS or TS file)
// we need to import it with it's path (the wasm file is not handled properly by vite)
import { init, dot } from "./node_modules/dot.wasm";
Before using the dot
function we need to call init
to instantiate the WebAssembly module.
The dot
function takes two ArrayLike
objects as its arguments. This can either be JavaScript
Array
s or Typed Arrays.
await init();
console.log(
dot(new Float32Array([1, 2]), new Float32Array([3, 4]))
); // 11
This function throws an error if the two arguments:
- are of different lengths
- are of different types
- are not in the list of supported types