Skip to content

Commit

Permalink
chore(deps): removed ts-pattern (CorentinTh#565)
Browse files Browse the repository at this point in the history
* fix(deps): update dependency ts-pattern to v5

* chore(deps): removed ts-pattern

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Corentin Thomasset <[email protected]>
  • Loading branch information
renovate[bot] and CorentinTh authored Aug 21, 2023
1 parent 2bcb77a commit 0f1f659
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"qrcode": "^1.5.1",
"randombytes": "^2.1.0",
"sql-formatter": "^12.0.0",
"ts-pattern": "^4.2.2",
"ua-parser-js": "^1.0.35",
"unicode-emoji-json": "^0.4.0",
"unplugin-auto-import": "^0.16.4",
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions src/tools/jwt-parser/jwt-parser.service.ts
Original file line number Diff line number Diff line change
@@ -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 };
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0f1f659

Please sign in to comment.