AssemblyScript library to generate RFC-compliant UUIDs v4 (random) 🚀
npm install as-uuid
Generate a random UUID string:
import uuid from "as-uuid";
const id: string = uuid();
id; // "0f5abcd1-c194-47f3-905b-2df7263a084b"
The library use Math.random
by default to generate random numbers.
This requires a seed for the random number generator to be imported from the host:
WebAssembly.instantiateStreaming(fetch('my.wasm'), {
env: {
seed: Date.now,
// ...
}
});
Notice that the seed is provided automatically when the loader is used or when WASI is imported.
More details at https://www.assemblyscript.org/stdlib/math.html#using-nativemath
Alternatively, WASI can be used to import the random number generator:
import uuid from "as-uuid/uuid-wasi";
const id: string = uuid();
id; // "0f5abcd1-c194-47f3-905b-2df7263a084b"
WebAssembly.instantiateStreaming(fetch('my.wasm'), {
wasi_snapshot_preview1: // ...
});
The assembly
directory contains AS source code.
npm i
npm run asbuild
The assembly/__tests__
directory contains all unit tests.
npm test
npm run test:wasi