Created
August 11, 2022 14:47
-
-
Save gengue/d1d299b5f5dba06ae9912b6b475b0ee2 to your computer and use it in GitHub Desktop.
Encode and decode base64 with javascript
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
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