Skip to content

Nyuudoukumo/uuidv4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uuidv4

A version 4 UUID generator written in the moonbit language, referring to RFC 4122.

Uasge

Use by api

moon add Nyuudoukumo/uuidv4

In moon.pkg.json

{
    "import": [
        {"path": "Nyuudoukumo/uuidv4/lib", "alias": "uuid"}
    ]
}

The randomUUID() will return a uuid as a String

extern "js" fn seed() -> Bytes =
  #|() => {
  #|  const crypto = require('crypto');
  #|  const timestamp = (Date.now()).toString();
  #|  const hash = crypto.createHash('sha256');
  #|  hash.update(timestamp);
  #|  const hashHex = hash.digest('hex');
  #|  const seed = Buffer.from(hashHex, 'hex');
  #|  return seed;
  #|};

fn main {
  println(@uuid.randomUUID(seed))
}

Notice, this package currently relies on JavaScript FFI:

moon run "src\main"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published