-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase64.min.js
1 lines (1 loc) · 4.89 KB
/
base64.min.js
1
!function(r,e){"use strict";function a(r,e){for(var a=new Array(Math.ceil(r.length/3)<<2>>>0),n=0,t=0;n+3<=r.length;n+=3){var o=r[n],c=r[n+1],f=r[n+2];a[t++]=e[o>>>2&63],a[t++]=e[(3&o)<<4|c>>>4&15],a[t++]=e[(15&c)<<2|f>>>6&3],a[t++]=e[63&f]}if(r.length-n!=0){switch(r.length-n){case 1:a[t++]=e[r[n]>>>2&63],a[t++]=e[(3&r[n])<<4];break;case 2:a[t++]=e[r[n]>>>2&63],a[t++]=e[(3&r[n])<<4|r[n+1]>>>4&15],a[t++]=e[(15&r[n+1])<<2];break;default:throw new Error("Wrong size of base64 final chunk.")}for(var h=t;h<a.length;++h)a[h]=w}return a}function n(r,e){for(var a=new Array(3*(r.length>>>2)),n=0,t=0;n+4<=r.length;n+=4){var o=e[127&r.charCodeAt(n)],c=e[127&r.charCodeAt(n+1)],f=e[127&r.charCodeAt(n+2)],h=e[127&r.charCodeAt(n+3)];if(o<0||c<0||f<0||h<0)throw new Error("Out of base64 character range. [offset="+n+"]");a[t++]=o<<2|c>>>4,a[t++]=(15&c)<<4|f>>>2,a[t++]=(3&f)<<6|h}if(r.length-n!=0)switch(r.length-n){case 2:if(o=e[127&r.charCodeAt(n)],c=e[127&r.charCodeAt(n+1)],o<0||c<1)throw new Error("Out of base64 character range. [offset="+(r.length-n)+"]");a[t++]=o<<2|c>>>4;break;case 3:if(o=e[127&r.charCodeAt(n)],c=e[127&r.charCodeAt(n+1)],f=e[127&r.charCodeAt(n+2)],o<0||c<0||f<0)throw new Error("Out of base64 character range. [offset="+(r.length-n)+"]");a[t++]=o<<2|c>>>4,a[t++]=(15&c)<<4|f>>>2;break;default:throw new Error("Wrong size of base64 final chunk.")}return a}function t(r){for(var e=0,a=0,n=0;n<r.length;++n)a=r.charCodeAt(n),e+=a>=55296&&a<=56319?++n>=r.length?0:4:a<=127?1:a<=2047?2:3;for(var t=new Array(e),n=0,o=0;n<r.length;++n){if(a=r.charCodeAt(n),a>=56320&&a<=57343)throw new Error("Encounter an unpaired surrogate. [char="+a+"]");if(a>=55296&&a<=56319){if(++n>=r.length)throw new Error("Encounter an unpaired surrogate. [char="+a+"]");var c=r.charCodeAt(n);if(c<56320||c>57343)throw new Error("Encounter an unpaired surrogate. [char="+a+", tail="+c+"]");a=((1023&a)<<10|1023&c)+65536}a<=127?t[o++]=a:a<=2047?(t[o++]=(a>>>6)+192,t[o++]=(63&a)+128):a<=65535?(t[o++]=(a>>>12)+224,t[o++]=(a>>>6&63)+128,t[o++]=(63&a)+128):(t[o++]=(a>>>18)+240,t[o++]=(a>>>12&63)+128,t[o++]=(a>>>6&63)+128,t[o++]=(63&a)+128)}return t}function o(r){for(var e=0,a=0,n=0;n<r.length;++n)a=r[n],e+=a<=127?1:240==(240&a)?(n+=3)>=r.length?0:2:224==(224&a)?(n+=2)>=r.length?0:1:192==(192&a)?(n+=1)>=r.length?0:1:0;for(var t=new Array(e),o=0,n=0,c=0;n<r.length;++n){if(a=r[n],a>=128){if(a<194||a>244)throw new Error("Invaild utf-8 character. [offset="+n+", char="+a+"]");if(240==(240&a))c=n+3,a=7&a;else if(224==(224&a))c=n+2,a=15&a;else{if(192!=(192&a))throw new Error("Invaild utf-8 character. [offset="+n+", char="+a+"]");c=n+1,a=31&a}if(c>=r.length)throw new Error("Encounter an unpaired surrogate. [char="+a+"]");for(;n+1<=c;){var f=r[++n];if(f<128||f>191)throw new Error("Invaild utf-8 trialing character. [offset="+n+", char="+a+"]");a=a<<6|63&f}}if(a>=55296&&a<=57343)throw new Error("Encounter an unpaired surrogate. [char="+a+"]");a>=65536?(t[o++]=(a>>10)+55232,t[o++]=(1023&a)+56320):t[o++]=a}return t}function c(r){return String.fromCharCode.apply(null,r)}function f(r){return r.replace(g,"")}function h(r,e){switch(e=e||"base64",e.toLowerCase()){case"base64":return c(a(t(r),u));case"base64-urlsafe":case"base64urlsafe":case"base64-url":case"base64url":return c(a(t(r),l));default:throw new Error("Unknow codec algorithms.")}}function s(r,e){switch(e=e||"base64",e.toLowerCase()){case"base64":return c(o(n(f(r),i)));case"base64-urlsafe":case"base64urlsafe":case"base64-url":case"base64url":return c(o(n(f(r),d)));default:throw new Error("Unknow codec algorithms.")}}var u=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47],i=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1],l=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,45,95],d=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,63,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1],w=61,g=/=+$/;"function"==typeof define&&define.amd?define(function(){return{encode:h,decode:s}}):"undefined"!=typeof exports?(exports.encode=h,exports.decode=s):r.base64={encode:h,decode:s}}("undefined"==typeof window?this:window);