Created
October 4, 2021 16:07
-
-
Save fostyfost/6e368488e8f1c63eca4abaa5950d9f2f to your computer and use it in GitHub Desktop.
Isomorphic Base64
This file contains hidden or 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
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