Commit d24faf3
committed
fix(randomUUID): add fallback when crypto.randomUUID is unavailable (HTTP/older envs)
In some environments (non-secure origins like http, older browsers, certain test runners),
`crypto.randomUUID` is not available, causing runtime errors.
This change preserves the existing fast path when `crypto.randomUUID` exists, and adds a
RFC4122 v4-shaped fallback for other cases:
- Detects availability via: typeof crypto !== 'undefined' && crypto.randomUUID
- Uses `crypto.randomUUID.bind(crypto)` when present
- Otherwise formats a UUID using 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(...)
with Math.random, ensuring version (4) and variant (8|9|a|b) bits
- Keeps strict typing with template-literal UUID type for DX
No breaking changes.1 parent ea2328e commit d24faf3
1 file changed
+8
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
86 | 93 | | |
87 | 94 | | |
88 | 95 | | |
| |||
0 commit comments