Fix uuidv4 on Node 18

Closes #2718
This commit is contained in:
Cohee
2024-08-27 09:35:00 +00:00
parent a0a1847634
commit 3806dcf9fb
2 changed files with 22 additions and 22 deletions

View File

@ -299,8 +299,8 @@ const color = {
* @returns {string} A UUIDv4 string
*/
function uuidv4() {
if ('randomUUID' in crypto) {
return crypto.randomUUID();
if ('crypto' in global && 'randomUUID' in global.crypto) {
return global.crypto.randomUUID();
}
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0;