Skip to content

Instantly share code, notes, and snippets.

@spamshaker
Last active October 14, 2023 09:56
Show Gist options
  • Save spamshaker/84893d092ecd29504242fa8dde23589d to your computer and use it in GitHub Desktop.
Save spamshaker/84893d092ecd29504242fa8dde23589d to your computer and use it in GitHub Desktop.
Javascript base64 encode/decode using native Browser/Node methods
// 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