Use crypto UUID if available

This commit is contained in:
Cohee
2024-06-10 14:18:38 +03:00
parent a20b2a566d
commit d1ed983106
2 changed files with 15 additions and 9 deletions

View File

@ -293,7 +293,14 @@ const color = {
white: (mess) => color.byNum(mess, 37),
};
/**
* Gets a random UUIDv4 string.
* @returns {string} A UUIDv4 string
*/
function uuidv4() {
if ('randomUUID' in crypto) {
return crypto.randomUUID();
}
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);