From 8af14f0923e998c345cb90eb0139494dbd648e8c Mon Sep 17 00:00:00 2001 From: frederikprijck Date: Wed, 26 Jul 2023 16:23:27 +0200 Subject: [PATCH] fix: avoid using var --- lib/base64_url_decode.ts | 4 ++-- lib/index.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/base64_url_decode.ts b/lib/base64_url_decode.ts index 9e3a963..3e27358 100644 --- a/lib/base64_url_decode.ts +++ b/lib/base64_url_decode.ts @@ -3,7 +3,7 @@ import atob from "./atob"; function b64DecodeUnicode(str: string) { return decodeURIComponent( atob(str).replace(/(.)/g, function(m, p) { - var code = p.charCodeAt(0).toString(16).toUpperCase(); + let code = p.charCodeAt(0).toString(16).toUpperCase(); if (code.length < 2) { code = "0" + code; } @@ -13,7 +13,7 @@ function b64DecodeUnicode(str: string) { } export default function(str: string) { - var output = str.replace(/-/g, "+").replace(/_/g, "/"); + let output = str.replace(/-/g, "+").replace(/_/g, "/"); switch (output.length % 4) { case 0: break; diff --git a/lib/index.ts b/lib/index.ts index 0b32a2f..479ae32 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -26,17 +26,18 @@ function jwtDecode( } options = options || {}; - var pos = options.header === true ? 0 : 1; + const pos = options.header === true ? 0 : 1; - var part = token.split(".")[pos]; + const part = token.split(".")[pos]; if (typeof part !== "string") { throw new InvalidTokenError( "Invalid token specified: missing part #" + (pos + 1) ); } + let decoded: string; try { - var decoded = base64_url_decode(part); + decoded = base64_url_decode(part); } catch (e: any) { throw new InvalidTokenError( "Invalid token specified: invalid base64 for part #" +