Skip to content

Commit

Permalink
Bug fix: Polyfill crypto.randomUUID for VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkmxy committed Mar 8, 2024
1 parent a6c953b commit 6b45515
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ucla-irl/ndnts-aux",
"version": "1.1.4",
"version": "1.1.5",
"description": "NDNts Auxiliary Package for Web and Deno",
"scripts": {
"test": "deno test --no-check",
Expand Down
10 changes: 7 additions & 3 deletions src/utils/random-uuid.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { v4 as uuidv4 } from 'uuid';

export const randomUUID = (): string => {
if (crypto && crypto.randomUUID) {
return crypto.randomUUID();
} else {
try {
if (globalThis.crypto && globalThis.crypto.randomUUID !== undefined) {
return crypto.randomUUID();
} else {
return uuidv4();
}
} catch {
return uuidv4();
}
};

0 comments on commit 6b45515

Please sign in to comment.