code: function toBase64(str) {
    //node
    if(typeof Buffer === 'function') {
      return new Buffer(str).toString('base64');
    }
  
    //browser
    if(typeof btoa === 'function') {
      return btoa(str);
    }
  
    throw new Error('No base64 encoder available.');
  }
docs: Because JS can't do base 64 on its own (wtf?)