Live video on the AT Protocol
1export const uuidv4 = () => {
2 return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
3 const r = Math.trunc(Math.random() * 16);
4 const v = c == "x" ? r : (r & 0x3) | 0x8;
5 return v.toString(16);
6 });
7};
8
9export const uuidv7 = () => {
10 return "tttttttt-tttt-7xxx-yxxx-xxxxxxxxxxxx"
11 .replace(/[xy]/g, function (c) {
12 const r = Math.trunc(Math.random() * 16);
13 const v = c == "x" ? r : (r & 0x3) | 0x8;
14 return v.toString(16);
15 })
16 .replace(/^[t]{8}-[t]{4}/, function () {
17 const unixtimestamp = Date.now().toString(16).padStart(12, "0");
18 return unixtimestamp.slice(0, 8) + "-" + unixtimestamp.slice(8);
19 });
20};