Skip to content

Instantly share code, notes, and snippets.

@niceaji
Created January 11, 2019 09:29
Show Gist options
  • Select an option

  • Save niceaji/d491cea308696890a5e520b4c42df39b to your computer and use it in GitHub Desktop.

Select an option

Save niceaji/d491cea308696890a5e520b4c42df39b to your computer and use it in GitHub Desktop.
export function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode(parseInt(p1, 16))
}))
}
export function b64DecodeUnicode(str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
return '%' + ('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