-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase64.min.js
1 lines (1 loc) · 2.26 KB
/
base64.min.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("base64",[],t):"object"==typeof exports?exports.base64=t():e.base64=t()}(window,function(){var u={PADCHAR:"=",ALPHA:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",makeDOMException:function(){try{return new DOMException(DOMException.INVALID_CHARACTER_ERR)}catch(e){var t=new Error("DOM Exception 5");return t.code=t.number=5,t.name=t.description="INVALID_CHARACTER_ERR",t.toString=function(){return"Error: "+t.name+": "+t.message},t}},getbyte64:function(e,t){var n=u.ALPHA.indexOf(e.charAt(t));if(-1===n)throw u.makeDOMException();return n},b64DecodeUnicode:function(e){e=""+e;var t,n,r,o=u.getbyte64,c=e.length;if(0===c)return e;if(c%4!=0)throw u.makeDOMException();t=0,e.charAt(c-1)===u.PADCHAR&&(t=1,e.charAt(c-2)===u.PADCHAR&&(t=2),c-=4);var i=[];for(n=0;n<c;n+=4)r=o(e,n)<<18|o(e,n+1)<<12|o(e,n+2)<<6|o(e,n+3),i.push(String.fromCharCode(r>>16,r>>8&255,255&r));switch(t){case 1:r=o(e,n)<<18|o(e,n+1)<<12|o(e,n+2)<<6,i.push(String.fromCharCode(r>>16,r>>8&255));break;case 2:r=o(e,n)<<18|o(e,n+1)<<12,i.push(String.fromCharCode(r>>16))}return i.join("")},getbyte:function(e,t){var n=e.charCodeAt(t);if(255<n)throw u.makeDOMException();return n},b64EncodeUnicode:function(e){if(1!==arguments.length)throw new SyntaxError("Not enough arguments");var t,n,r=u.PADCHAR,o=u.ALPHA,c=u.getbyte,i=[],a=(e=""+e).length-e.length%3;if(0===e.length)return e;for(t=0;t<a;t+=3)n=c(e,t)<<16|c(e,t+1)<<8|c(e,t+2),i.push(o.charAt(n>>18)),i.push(o.charAt(n>>12&63)),i.push(o.charAt(n>>6&63)),i.push(o.charAt(63&n));switch(e.length-a){case 1:n=c(e,t)<<16,i.push(o.charAt(n>>18)+o.charAt(n>>12&63)+r+r);break;case 2:n=c(e,t)<<16|c(e,t+1)<<8,i.push(o.charAt(n>>18)+o.charAt(n>>12&63)+o.charAt(n>>6&63)+r)}return i.join("")},encode:function(e){return u.b64EncodeUnicode(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode("0x"+t)}))},decode:function(e){return decodeURIComponent(u.b64DecodeUnicode(e).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)}).join(""))}};return window.atob=(atob,function(){return u.decode.apply(this,arguments)}),window.btoa=(btoa,function(){return u.encode.apply(this,arguments)}),u});