Last active
November 19, 2017 08:00
-
-
Save leommoore/66f9df2d7142f11c9142eaa828b19679 to your computer and use it in GitHub Desktop.
btoa & atob
This file contains 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
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