Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

用代码实现把字符串转换成base64编码

Sunny-117 opened this issue · comments

commented
function encode(str){
    const encodestr = encodeURI(str);
    const base64 = btoa(encodestr);
    return base64;
}
function strToBase64(str) {
      str = encodeURI(str);
      return btoa(str);
}
function base64ToStr(base64) {
      base64 = atob(base64);
      return decodeURI(base64);
}