A version 4 UUID generator written in the moonbit language, referring to RFC 4122.
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"