From 01d5dfdd61f221a780932efe37cd5b9216388e4a Mon Sep 17 00:00:00 2001 From: oittaa <8972248+oittaa@users.noreply.github.com> Date: Tue, 17 Sep 2024 15:57:56 +0200 Subject: [PATCH] uuid.js use native randomUUID() if available https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID All the major browsers support it: https://caniuse.com/mdn-api_crypto_randomuuid --- lib/uuid.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/uuid.js b/lib/uuid.js index 2e47de7a..18bb4bcb 100644 --- a/lib/uuid.js +++ b/lib/uuid.js @@ -11,6 +11,9 @@ * @return {string} The generate UUID */ export default function uuid() { + if (typeof(self.crypto.randomUUID) === typeof(Function)) { + return self.crypto.randomUUID() + } return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { const r = (Math.random() * 16) | 0 const v = c === 'x' ? r : (r & 0x3) | 0x8