forked from davidchambers/Base64.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
base64.min.js
1 lines (1 loc) · 1.11 KB
/
base64.min.js
1
function InvalidCharacterError(r){this.message=r}var base64={},chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";InvalidCharacterError.prototype=Error(),InvalidCharacterError.prototype.name="InvalidCharacterError",base64.btoa=window.btoa?function(r){return window.btoa(r)}:function(r){for(var a,e,t=0,o=chars,n="";r.charAt(0|t)||(o="=",t%1);n+=o.charAt(63&a>>8-8*(t%1))){if(e=r.charCodeAt(t+=.75),e>255)throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");a=a<<8|e}return n},base64.atob=window.atob?function(r){return window.atob(r)}:function(r){if(r=r.replace(/=+$/,""),1==r.length%4)throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded.");for(var a,e,t=0,o=0,n="";e=r.charAt(o++);~e&&(a=t%4?64*a+e:e,t++%4)?n+=String.fromCharCode(255&a>>(6&-2*t)):0)e=chars.indexOf(e);return n},base64.url={btoa:function(r){var a=base64.btoa(r);return a=a.replace(/\+/g,"-"),a=a.replace(/\//g,"_")},atob:function(r){var a=r;return a=a.replace(/-/g,"+"),a=a.replace(/_/g,"/"),base64.atob(a)}},module.exports=base64;