Last active
December 6, 2020 08:15
-
-
Save sullof/b6a62dd35ac89f5bb8aa1b0ad3afa81a to your computer and use it in GitHub Desktop.
Base64Url Class
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
class Base64Url { | |
static encode(str) { | |
return Buffer.from(str).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '') | |
} | |
static decode(str) { | |
for (let i = 1; i < str.length % 4; i++) str += '=' | |
return Buffer.from(str.replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf-8') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment