Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reccomended configurations for typescript-eslint #201

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@
"ignorePatterns": ["**/*.mjs", "**/*.js"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:prettier/recommended"
],
"plugins": ["@typescript-eslint", "import"],
"parserOptions": {
"ecmaVersion": 9
"ecmaVersion": 9,
"project": true
},
"rules": {
"@typescript-eslint/no-empty-interface": "warn",
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/no-explicit-any": "off",
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved
"import/no-default-export": "error",
"@typescript-eslint/no-unused-vars": "error",
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved
"import/extensions": ["error", "always"]
}
}
14 changes: 7 additions & 7 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ InvalidTokenError.prototype.name = "InvalidTokenError";

function b64DecodeUnicode(str: string) {
return decodeURIComponent(
atob(str).replace(/(.)/g, (m, p) => {
let code = p.charCodeAt(0).toString(16).toUpperCase();
atob(str).replace(/(.)/g, (match) => {
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved
let code = match.charCodeAt(0).toString(16).toUpperCase();
if (code.length < 2) {
code = "0" + code;
}
Expand Down Expand Up @@ -78,17 +78,17 @@ export function jwtDecode(token: string, options?: JwtDecodeOptions) {
let decoded: string;
try {
decoded = base64UrlDecode(part);
} catch (e: any) {
} catch (e) {
throw new InvalidTokenError(
`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`,
`Invalid token specified: invalid base64 for part #${pos + 1} (${(e as Error).message})`,
);
}

try {
return JSON.parse(decoded);
} catch (e: any) {
return JSON.parse(decoded) as object;
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
throw new InvalidTokenError(
`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`,
`Invalid token specified: invalid json for part #${pos + 1} (${(e as Error).message})`,
);
}
}
4 changes: 2 additions & 2 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("jwt-decode", () => {
it("should throw InvalidTokenError on nonstring", () => {
const badToken = null;
expect(() => {
jwtDecode(badToken as any);
jwtDecode(badToken as unknown as string);
}).toThrow(InvalidTokenError);
});

Expand All @@ -63,7 +63,7 @@ describe("jwt-decode", () => {
it("should throw InvalidTokenErrors when token is null", () => {
const badToken = null;
expect(() => {
jwtDecode(badToken as any, { header: true });
jwtDecode(badToken as unknown as string, { header: true });
}).toThrow(new InvalidTokenError("Invalid token specified: must be a string"));
});

Expand Down