Convert a string to base64

var encodedData = btoa(stringToEncode);

https://developer.mozilla.org/en-US/docs/Web/API/btoa