Skip to content

Instantly share code, notes, and snippets.

@emctague
Created July 23, 2017 23:54
Show Gist options
  • Save emctague/6532fa44687df15d8983fa4a78c8a7c0 to your computer and use it in GitHub Desktop.
Save emctague/6532fa44687df15d8983fa4a78c8a7c0 to your computer and use it in GitHub Desktop.
base64 encode/decode for node and browser
// 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