From 8ce1d7887ee9e8727b9d1c3d97a4ecf4788bd37d Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 11 Sep 2025 10:08:46 +0700 Subject: [PATCH] feat: use `Uint8Array.fromBase64` if available Signed-off-by: Alfi Maulana --- lib/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/index.ts b/lib/index.ts index 46bec6a..61965fa 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -35,6 +35,11 @@ function b64DecodeUnicode(str: string) { } function base64UrlDecode(str: string) { + if ("fromBase64" in Uint8Array && typeof Uint8Array.fromBase64 === "function") { + const bytes = Uint8Array.fromBase64(str, { alphabet: "base64url" }) as Uint8Array; + return new TextDecoder().decode(bytes); + } + let output = str.replace(/-/g, "+").replace(/_/g, "/"); switch (output.length % 4) { case 0: