DEV Community

loading...

Discussion on: Encoding mess with Javascript

Collapse
jpantunes profile image
JP Antunes

Try these, they seem to work with all the examples from Stack Overflow

const asciiToBase64 = ascii => Buffer.from(ascii).toString('base64');
const base64ToAscii = b64 => Buffer.from(b64, 'base64').toString();
Collapse
antho1404 profile image
Anthony Author

Yes, that works well but only in node environment. In javascript in the browser, Buffer is not accessible and thus you need to go with the atob or btoa solution (if you don't want some complex webpack that can simulate a buffer or any external buffer-ish libraries).