Last active
October 14, 2023 09:56
-
-
Save spamshaker/84893d092ecd29504242fa8dde23589d to your computer and use it in GitHub Desktop.
Javascript base64 encode/decode using native Browser/Node methods
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
// Encodes any text to base64; | |
export const encodeBase64 = text => btoa(String.fromCodePoint(...Array.from(new TextEncoder().encode(text)))); | |
// Decodes base64 to text; | |
export const decodeBase64 = text => new TextDecoder().decode(Uint8Array.from(atob(text), (m) => m.codePointAt(0))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment