gxc-lett-js/lib/src/web-api/uuidv4.ts
Andrey Kernichniy 0d1df855a3
All checks were successful
CI / build (push) Successful in 33s
Release package version 1.0.1
Added type for uuidv4
2026-03-14 14:03:10 +07:00

12 lines
413 B
TypeScript

export type UUID_V4 = `${string}-${string}-${string}-${string}-${string}`;
export const uuidv4 = (): UUID_V4 => {
if (crypto.randomUUID == null) {
"10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) =>
// eslint-disable-next-line no-bitwise
(+c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))).toString(16),
);
} else {
return crypto.randomUUID();
}
};