(bytes: number)
| 7 | * @see <https://developer.mozilla.org/en-US/docs/Glossary/Base64#encoded_size_increase> |
| 8 | */ |
| 9 | export const generateRandomString = (bytes: number): string => { |
| 10 | const byteArr = window.crypto.getRandomValues(new Uint8Array(bytes)); |
| 11 | // The types for `map` don't seem to support mapping from one array type to |
| 12 | // another and `String.fromCharCode.apply` wants `number[]` so loop like this |
| 13 | // instead. |
| 14 | const strArr: string[] = []; |
| 15 | for (const byte of byteArr) { |
| 16 | strArr.push(String.fromCharCode(byte)); |
| 17 | } |
| 18 | return btoa(strArr.join("")); |
| 19 | }; |
no test coverage detected