1 line
2.2 KiB
JavaScript
1 line
2.2 KiB
JavaScript
'use strict';var sp_punycode=function(){function a(K){throw new RangeError(y[K])}function b(K,L){for(var M=[],N=K.length;N--;)M[N]=L(K[N]);return M}function c(K,L){var M=K.split('@'),N='';1<M.length&&(N=M[0]+'@',K=M[1]),K=K.replace(x,'.');var O=K.split('.'),P=b(O,L).join('.');return N+P}function d(K){for(var O,L=[],M=0,N=K.length;M<N;)if(O=K.charCodeAt(M++),55296<=O&&56319>=O&&M<N){var P=K.charCodeAt(M++);56320==(64512&P)?L.push(((1023&O)<<10)+(1023&P)+65536):(L.push(O),M--)}else L.push(O);return L}var e=2147483647,f=36,g=1,h=26,p=72,r=128,s='-',u=/^xn--/,v=/[^\0-\x7E]/,x=/[\x2E\u3002\uFF0E\uFF61]/g,y={overflow:'Overflow: input needs wider integers to process','not-basic':'Illegal input >= 0x80 (not a basic code point)','invalid-input':'Invalid input'},z=f-g,A=Math.floor,B=String.fromCharCode,D=function(K){return 10>K-48?K-22:26>K-65?K-65:26>K-97?K-97:f},E=function(K,L){return K+22+75*(26>K)-((0!=L)<<5)},F=function(K,L,M){var N=0;for(K=M?A(K/700):K>>1,K+=A(K/L);K>z*h>>1;N+=f)K=A(K/z);return A(N+(z+1)*K/(K+38))},G=function(K){var L=[],M=K.length,N=0,O=r,P=p,Q=K.lastIndexOf(s);0>Q&&(Q=0);for(var R=0;R<Q;++R)128<=K.charCodeAt(R)&&a('not-basic'),L.push(K.charCodeAt(R));for(var T,S=0<Q?Q+1:0;S<M;){T=N;for(var U=1,V=f;;V+=f){S>=M&&a('invalid-input');var W=D(K.charCodeAt(S++));(W>=f||W>A((e-N)/U))&&a('overflow'),N+=W*U;var X=V<=P?g:V>=P+h?h:V-P;if(W<X)break;var Y=f-X;U>A(e/Y)&&a('overflow'),U*=Y}var Z=L.length+1;P=F(N-T,Z,0==T),A(N/Z)>e-O&&a('overflow'),O+=A(N/Z),N%=Z,L.splice(N++,0,O)}return String.fromCodePoint.prototype.apply(null,L)};var H=function(K){var L=[];K=d(K);var M=K.length,N=r,O=0,P=p;for(var Q of K)128>Q&&L.push(B(Q));var R=L.length,S=R;for(R&&L.push(s);S<M;){var T=e;for(var Q of K)Q>=N&&Q<T&&(T=Q);var U=S+1;T-N>A((e-O)/U)&&a('overflow'),O+=(T-N)*U,N=T;for(var Q of K)if(Q<N&&++O>e&&a('overflow'),Q==N){for(var X,V=O,W=f;;W+=f){if(X=W<=P?g:W>=P+h?h:W-P,V<X)break;var Y=V-X,Z=f-X;L.push(B(E(X+Y%Z,0))),V=A(Y/Z)}L.push(B(E(V,0))),P=F(O,U,S==R),O=0,++S}++O,++N}return L.join('')};return{version:'2.1.0',ucs2:{decode:d,encode:K=>String.fromCodePoint.prototype.apply(null,K)},decode:G,encode:H,toASCII:function(K){return c(K,function(L){return v.test(L)?'xn--'+H(L):L})},toUnicode:function(K){return c(K,function(L){return u.test(L)?G(L.slice(4).toLowerCase()):L})}}}(); |