Skip to content

Instantly share code, notes, and snippets.

@sullof
Last active December 6, 2020 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sullof/b6a62dd35ac89f5bb8aa1b0ad3afa81a to your computer and use it in GitHub Desktop.
Save sullof/b6a62dd35ac89f5bb8aa1b0ad3afa81a to your computer and use it in GitHub Desktop.
Base64Url Class
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