Created
August 11, 2022 14:47
Encode and decode base64 with javascript
This file contains hidden or 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
function encodeBase64(str) { | |
return window.btoa(unescape(encodeURIComponent(str))); | |
} | |
function decodeBase64(str) { | |
return decodeURIComponent(escape(window.atob(str))); | |
} | |
// Usage: | |
encodeBase64('✓ à la mode'); // "4pyTIMOgIGxhIG1vZGU=" | |
decodeBase64('4pyTIMOgIGxhIG1vZGU='); // "✓ à la mode" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment