mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 17:43:03 +03:00
14 lines
363 B
TypeScript
14 lines
363 B
TypeScript
|
export const generateUUID = (): string => {
|
||
|
const array = new Uint32Array(4);
|
||
|
window.crypto.getRandomValues(array);
|
||
|
let idx = -1;
|
||
|
|
||
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
||
|
idx++;
|
||
|
const r = (array[idx >> 3] >> ((idx % 8) * 4)) & 15;
|
||
|
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
||
|
|
||
|
return v.toString(16);
|
||
|
});
|
||
|
};
|