Skip to content

Commit 2210fa6

Browse files
committed
feat: use Uint8Array.fromBase64 if available
Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
1 parent ff2c4b2 commit 2210fa6

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ export class InvalidTokenError extends Error {}
2323
InvalidTokenError.prototype.name = "InvalidTokenError";
2424

2525
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+
2636
return decodeURIComponent(
2737
atob(str).replace(/(.)/g, (m, p) => {
2838
let code = (p as string).charCodeAt(0).toString(16).toUpperCase();

0 commit comments

Comments
 (0)