Created
July 4, 2021 02:28
-
-
Save AfroThundr3007730/df485b56aa9c064c20a4ab2662126054 to your computer and use it in GitHub Desktop.
Unicode string to base64 (wrapper for btoa and atob)
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
"use strict" | |
const u_btoa = str => btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (_match, pl) => String.fromCharCode('0x' + pl))) | |
const u_atob = str => decodeURIComponent(atob(str).split('').map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join('')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment