Skip to content

Instantly share code, notes, and snippets.

@fostyfost
Created October 4, 2021 16:07
Show Gist options
  • Save fostyfost/6e368488e8f1c63eca4abaa5950d9f2f to your computer and use it in GitHub Desktop.
Save fostyfost/6e368488e8f1c63eca4abaa5950d9f2f to your computer and use it in GitHub Desktop.
Isomorphic Base64
export const toBase64 = (str: string): string => {
return typeof window === 'undefined' ? Buffer.from(str).toString('base64') : btoa(str)
}
export const fromBase64 = (str: string): string => {
return typeof window === 'undefined' ? Buffer.from(str, 'base64').toString() : atob(str)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment