Skip to content

Instantly share code, notes, and snippets.

@ZakharDay
Created February 19, 2022 12:23
Show Gist options
  • Save ZakharDay/f19d65a9aa7863ee6720f02460c8e961 to your computer and use it in GitHub Desktop.
Save ZakharDay/f19d65a9aa7863ee6720f02460c8e961 to your computer and use it in GitHub Desktop.
let text = "поздравляю со сдачей сессии"
let encoded = btoa(text)
let decoded = atob(encoded)
function utf8_to_b64( str ) {
return window.btoa(unescape(encodeURIComponent( str )));
}
function b64_to_utf8( str ) {
return decodeURIComponent(escape(window.atob( str )));
}
encoded = utf8_to_b64(text)
let urlSafeEncoded = encoded.replaceAll('/', '_').replaceAll('+', '-')
let urlSafeDecoded = urlSafeEncoded.replaceAll('_', '/').replaceAll('-', '+')
decoded = b64_to_utf8(urlSafeDecoded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment