Skip to content

Instantly share code, notes, and snippets.

Last active Nov 19, 2017
What would you like to do?
btoa & atob
function btoa(str) {
if ((typeof str) !== 'string') {
str = JSON.stringify(str);
var buffer;
if (str instanceof Buffer) {
buffer = str;
} else {
buffer = new Buffer(str.toString(), 'binary');
return buffer.toString('base64');
function atob(str) {
return new Buffer(str, 'base64').toString('binary');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment