We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Uint8Array.fromBase64
1 parent ff2c4b2 commit 2210fa6Copy full SHA for 2210fa6
1 file changed
lib/index.ts
@@ -23,6 +23,16 @@ export class InvalidTokenError extends Error {}
23
InvalidTokenError.prototype.name = "InvalidTokenError";
24
25
function b64DecodeUnicode(str: string) {
26
+ if (
27
+ typeof Uint8Array !== "undefined" &&
28
+ "fromBase64" in Uint8Array &&
29
+ typeof Uint8Array.fromBase64 === "function"
30
+ ) {
31
+ // Use native Uint8Array.fromBase64 if available
32
+ const bytes = Uint8Array.fromBase64(str) as Uint8Array;
33
+ return new TextDecoder().decode(bytes);
34
+ }
35
+
36
return decodeURIComponent(
37
atob(str).replace(/(.)/g, (m, p) => {
38
let code = (p as string).charCodeAt(0).toString(16).toUpperCase();
0 commit comments