Skip to content

Instantly share code, notes, and snippets.

@leommoore
Last active November 19, 2017 08:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leommoore/66f9df2d7142f11c9142eaa828b19679 to your computer and use it in GitHub Desktop.
Save leommoore/66f9df2d7142f11c9142eaa828b19679 to your computer and use it in GitHub Desktop.
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