-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d8b657
commit 68b244c
Showing
8 changed files
with
11,417 additions
and
11,418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
function b64DecodeUnicode(str: string) { | ||
return decodeURIComponent( | ||
atob(str).replace(/(.)/g, function(m, p) { | ||
let code = p.charCodeAt(0).toString(16).toUpperCase(); | ||
if (code.length < 2) { | ||
code = "0" + code; | ||
} | ||
return "%" + code; | ||
}) | ||
); | ||
return decodeURIComponent( | ||
atob(str).replace(/(.)/g, function(m, p) { | ||
let code = p.charCodeAt(0).toString(16).toUpperCase(); | ||
if (code.length < 2) { | ||
code = "0" + code; | ||
} | ||
return "%" + code; | ||
}) | ||
); | ||
} | ||
|
||
export default function(str: string) { | ||
let output = str.replace(/-/g, "+").replace(/_/g, "/"); | ||
switch (output.length % 4) { | ||
case 0: | ||
break; | ||
case 2: | ||
output += "=="; | ||
break; | ||
case 3: | ||
output += "="; | ||
break; | ||
default: | ||
throw new Error("base64 string is not of the correct length"); | ||
} | ||
let output = str.replace(/-/g, "+").replace(/_/g, "/"); | ||
switch (output.length % 4) { | ||
case 0: | ||
break; | ||
case 2: | ||
output += "=="; | ||
break; | ||
case 3: | ||
output += "="; | ||
break; | ||
default: | ||
throw new Error("base64 string is not of the correct length"); | ||
} | ||
|
||
try { | ||
return b64DecodeUnicode(output); | ||
} catch (err) { | ||
return atob(output); | ||
} | ||
} | ||
try { | ||
return b64DecodeUnicode(output); | ||
} catch (err) { | ||
return atob(output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,4 @@ function jwtDecode( | |
} | ||
} | ||
|
||
export default jwtDecode; | ||
export default jwtDecode; |
Oops, something went wrong.