Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ttulka/as-uuid
AssemblyScript library to generate RFC-compliant UUIDs v4 (random).
https://github.com/ttulka/as-uuid
assemblyscript uuid uuid4 uuidv4
Last synced: about 1 month ago
JSON representation
AssemblyScript library to generate RFC-compliant UUIDs v4 (random).
- Host: GitHub
- URL: https://github.com/ttulka/as-uuid
- Owner: ttulka
- License: mit
- Created: 2021-07-23T06:20:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-02T13:22:47.000Z (about 2 years ago)
- Last Synced: 2024-09-13T20:15:46.869Z (2 months ago)
- Topics: assemblyscript, uuid, uuid4, uuidv4
- Language: TypeScript
- Homepage:
- Size: 65.4 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# as-uuid
[AssemblyScript](https://github.com/AssemblyScript/assemblyscript) library to generate RFC-compliant UUIDs v4 (random) 🚀
## Install
```sh
npm install as-uuid
```## Use
Generate a random UUID string:
```typescript
import uuid from "as-uuid";const id: string = uuid();
id; // "0f5abcd1-c194-47f3-905b-2df7263a084b"
```### Using NativeMath
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:
```js
WebAssembly.instantiateStreaming(fetch('my.wasm'), {
env: {
seed: Date.now,
// ...
}
});
```Notice that the seed is provided automatically when the [loader](https://www.assemblyscript.org/loader.html) is used or when WASI is imported.
More details at https://www.assemblyscript.org/stdlib/math.html#using-nativemath
### Using WASI
Alternatively, [WASI](https://wasi.dev) can be used to import the random number generator:
```typescript
import uuid from "as-uuid/uuid-wasi";const id: string = uuid();
id; // "0f5abcd1-c194-47f3-905b-2df7263a084b"
``````js
WebAssembly.instantiateStreaming(fetch('my.wasm'), {
wasi_snapshot_preview1: // ...
});
```## Build
The `assembly` directory contains AS source code.
```sh
npm i
npm run asbuild
```## Test
The `assembly/__tests__` directory contains all unit tests.
```sh
npm test
npm run test:wasi
```## Licence
[MIT](https://github.com/ttulka/as-uuid/blob/main/LICENSE)