MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / UUIDv1

Function UUIDv1

modules/base/uuid/uuid.js:41–54  ·  view source on GitHub ↗
(time)

Source from the content-addressed store, hash-verified

39}
40// Version 1 (Time-Based) UUID
41function UUIDv1(time) {
42 return [
43 hex((time & 0xf) << 24, 1).substring(0, 1) +
44 hex(Math.random() * 0xfffffff, 7), // add random number since we don't have 100-nanosecond precision
45 hex((time & 0xffff0) >> 4, 4),
46 "1" + hex(time & (0xfff00000 >> 20), 3),
47 hex(Math.random() * 0x3fff | 0x8000, 4),
48 Net.get('MAC')?.split(':').join('') ??
49 hex((Math.random() * 0xffffffff) | 0x02000000, 8) +
50 hex(Math.random() * 0xffff, 4),
51 ]
52 .join('-')
53 .toUpperCase();
54}
55
56// Version 4 (Random) UUID
57function UUIDv4() {

Callers 1

UUIDFunction · 0.85

Calls 2

hexFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected