Created
October 9, 2015 15:36
-
-
Save geraintluff/21beb1066fc5239304aa to your computer and use it in GitHub Desktop.
Convert base64 to and from web-safe variant
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
// Convert from normal to web-safe, strip trailing "="s | |
function webSafe64(base64) { | |
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); | |
} | |
// Convert from web-safe to normal, add trailing "="s | |
function normal64(base64) { | |
return base64.replace(/\-/g, '+').replace(/_/g, '/') + '=='.substring(0, (3*base64.length)%4); | |
} |
Thanks so much! Super helpful <3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks :D