Created
July 20, 2019 08:18
-
-
Save rainyjune/29535529807bed76c7a2815c0f07f58a to your computer and use it in GitHub Desktop.
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
// ucs-2 string to base64 encoded ascii | |
function utoa(str) { | |
return window.btoa(unescape(encodeURIComponent(str))); | |
} | |
// base64 encoded ascii to ucs-2 string | |
function atou(str) { | |
return decodeURIComponent(escape(window.atob(str))); | |
} | |
// Usage: | |
utoa('✓ à la mode'); // 4pyTIMOgIGxhIG1vZGU= | |
atou('4pyTIMOgIGxhIG1vZGU='); // "✓ à la mode" | |
utoa('I \u2661 Unicode!'); // SSDimaEgVW5pY29kZSE= | |
atou('SSDimaEgVW5pY29kZSE='); // "I ♡ Unicode!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment