Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Created July 4, 2021 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AfroThundr3007730/df485b56aa9c064c20a4ab2662126054 to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/df485b56aa9c064c20a4ab2662126054 to your computer and use it in GitHub Desktop.
Unicode string to base64 (wrapper for btoa and atob)
"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