chore(deps): removed ts-pattern

This commit is contained in:
Corentin Thomasset 2023-08-21 19:00:19 +02:00
parent a9e9e14656
commit 3dcb4e9f4c
No known key found for this signature in database
GPG key ID: DBD997E935996158
3 changed files with 9 additions and 13 deletions

View file

@ -73,7 +73,6 @@
"qrcode": "^1.5.1",
"randombytes": "^2.1.0",
"sql-formatter": "^12.0.0",
"ts-pattern": "^5.0.0",
"ua-parser-js": "^1.0.35",
"unicode-emoji-json": "^0.4.0",
"unplugin-auto-import": "^0.16.4",

7
pnpm-lock.yaml generated
View file

@ -125,9 +125,6 @@ dependencies:
sql-formatter:
specifier: ^12.0.0
version: 12.0.0
ts-pattern:
specifier: ^5.0.0
version: 5.0.0
ua-parser-js:
specifier: ^1.0.35
version: 1.0.35
@ -8122,10 +8119,6 @@ packages:
typescript: 4.9.3
dev: true
/ts-pattern@5.0.0:
resolution: {integrity: sha512-FDTdTujq2GvMmrwYM0Om6pMilRAUKvBApEN+YniTQui/HGjFwaI6WAx9SepD+yDBf4q29JLf6yqGB8uvdzysEg==}
dev: false
/tsconfig-paths@3.14.2:
resolution: {integrity: sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==}
dependencies:

View file

@ -1,6 +1,5 @@
import jwtDecode, { type JwtHeader, type JwtPayload } from 'jwt-decode';
import _ from 'lodash';
import { match } from 'ts-pattern';
import { ALGORITHM_DESCRIPTIONS, CLAIM_DESCRIPTIONS } from './jwt-parser.constants';
export { decodeJwt };
@ -32,10 +31,15 @@ function parseClaims({ claim, value }: { claim: string; value: unknown }) {
}
function getFriendlyValue({ claim, value }: { claim: string; value: unknown }) {
return match(claim)
.with('exp', 'nbf', 'iat', () => dateFormatter(value))
.with('alg', () => (_.isString(value) ? ALGORITHM_DESCRIPTIONS[value] : undefined))
.otherwise(() => undefined);
if (['exp', 'nbf', 'iat'].includes(claim)) {
return dateFormatter(value);
}
if (claim === 'alg' && _.isString(value)) {
return ALGORITHM_DESCRIPTIONS[value];
}
return undefined;
}
function dateFormatter(value: unknown) {