Git Product home page Git Product logo

as-uuid's Introduction

as-uuid

AssemblyScript library to generate RFC-compliant UUIDs v4 (random) ๐Ÿš€

Install

npm install as-uuid

Use

Generate a random UUID string:

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:

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

Using WASI

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: // ...
});

Build

The assembly directory contains AS source code.

npm i
npm run asbuild

Test

The assembly/__tests__ directory contains all unit tests.

npm test
npm run test:wasi

Licence

MIT

as-uuid's People

Contributors

maxgraey avatar ttulka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

maxgraey

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.