Created
May 31, 2017 18:42
-
-
Save Fordi/f0a1cdf109bb7d21a7f0a94e1f2b43df to your computer and use it in GitHub Desktop.
DOM btoa / atob UTF-8 suppport
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
((win, btoa, atob) => Object.assign(win, { | |
btoa: (str) => btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode(parseInt(p1, 16)))), | |
atob: (str) => decodeURIComponent(atob(str).split('').map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join('')) | |
}))(this, btoa, atob); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment