()
| 4 | |
| 5 | // use the browsers crypto.randomUUID if set |
| 6 | const genUUID = () => { |
| 7 | if (window?.crypto?.randomUUID) return window.crypto.randomUUID(); |
| 8 | |
| 9 | // return a random UUID style string` |
| 10 | return ((1e7).toString() + -1e3 + -4e3 + -8e3 + -1e11).replace( |
| 11 | /[018]/g, |
| 12 | c => |
| 13 | ( |
| 14 | Number(c) ^ |
| 15 | (crypto.getRandomValues(new Uint8Array(1))[0] & |
| 16 | (15 >> (Number(c) / 4))) |
| 17 | ).toString(16) |
| 18 | ); |
| 19 | }; |
| 20 | |
| 21 | const getCookie = (name: string) => { |
| 22 | const value = `; ${document.cookie}`; |