Removed window reference from jwtDecode
All checks were successful
Build / Build NPM Project (push) Successful in 27s
Build / Tag Version (push) Successful in 7s

This commit is contained in:
Zakary Timson 2024-09-30 16:18:07 -04:00
parent c1043e65e2
commit e40f410830
3 changed files with 5 additions and 5 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.16.8", "version": "0.16.9",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.16.8", "version": "0.16.9",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.12", "@types/jest": "^29.5.12",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.16.8", "version": "0.16.9",
"description": "Utility library", "description": "Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",

View File

@ -6,10 +6,10 @@ import {JSONAttemptParse} from './objects.ts';
* @param {string} token JWT to decode * @param {string} token JWT to decode
* @return {unknown} JWT payload * @return {unknown} JWT payload
*/ */
export function decodeJwt<T>(token: string): T { export function jwtDecode<T>(token: string): T {
const base64 = token.split('.')[1] const base64 = token.split('.')[1]
.replace(/-/g, '+').replace(/_/g, '/'); .replace(/-/g, '+').replace(/_/g, '/');
return <T>JSONAttemptParse(decodeURIComponent(window.atob(base64).split('').map(function(c) { return <T>JSONAttemptParse(decodeURIComponent(atob(base64).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''))); }).join('')));
} }