Skip to content

Commit

Permalink
fix: avoid using var
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Jul 28, 2023
1 parent b78191d commit 8af14f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/base64_url_decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 #" +
Expand Down

0 comments on commit 8af14f0

Please sign in to comment.