Created
July 23, 2017 23:54
-
-
Save emctague/6532fa44687df15d8983fa4a78c8a7c0 to your computer and use it in GitHub Desktop.
base64 encode/decode for node and browser
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
// Simple Base64 encode/decode that works in node and the browser. | |
var base64 = { | |
encode: function (text) { | |
if (typeof btoa === 'function') | |
return btoa(text) | |
else | |
return new Buffer(text).toString('base64') | |
}, | |
decode: function (text) { | |
if (typeof atob === 'function') | |
return atob(text) | |
else | |
return new Buffer(text, 'base64').toString('utf8') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment