| 1 |
- const t={};function e(s,n){"string"!=typeof n&&(n=e.defaultChars);const o=function(e){let s=t[e];if(s)return s;s=t[e]=[];for(let t=0;t<128;t++){const e=String.fromCharCode(t);s.push(e)}for(let t=0;t<e.length;t++){const n=e.charCodeAt(t);s[n]="%"+("0"+n.toString(16).toUpperCase()).slice(-2)}return s}(n);return s.replace(/(%[a-f0-9]{2})+/gi,function(t){let e="";for(let s=0,n=t.length;s<n;s+=3){const h=parseInt(t.slice(s+1,s+3),16);if(h<128)e+=o[h];else{if(192==(224&h)&&s+3<n){const n=parseInt(t.slice(s+4,s+6),16);if(128==(192&n)){const t=h<<6&1984|63&n;e+=t<128?"��":String.fromCharCode(t),s+=3;continue}}if(224==(240&h)&&s+6<n){const n=parseInt(t.slice(s+4,s+6),16),o=parseInt(t.slice(s+7,s+9),16);if(128==(192&n)&&128==(192&o)){const t=h<<12&61440|n<<6&4032|63&o;e+=t<2048||t>=55296&&t<=57343?"���":String.fromCharCode(t),s+=6;continue}}if(240==(248&h)&&s+9<n){const n=parseInt(t.slice(s+4,s+6),16),o=parseInt(t.slice(s+7,s+9),16),i=parseInt(t.slice(s+10,s+12),16);if(128==(192&n)&&128==(192&o)&&128==(192&i)){let t=h<<18&1835008|n<<12&258048|o<<6&4032|63&i;t<65536||t>1114111?e+="����":(t-=65536,e+=String.fromCharCode(55296+(t>>10),56320+(1023&t))),s+=9;continue}}e+="�"}}return e})}e.defaultChars=";/?:@&=+$,#",e.componentChars="";const s={};function n(t,e,o){"string"!=typeof e&&(o=e,e=n.defaultChars),void 0===o&&(o=!0);const h=function(t){let e=s[t];if(e)return e;e=s[t]=[];for(let s=0;s<128;s++){const t=String.fromCharCode(s);/^[0-9a-z]$/i.test(t)?e.push(t):e.push("%"+("0"+s.toString(16).toUpperCase()).slice(-2))}for(let s=0;s<t.length;s++)e[t.charCodeAt(s)]=t[s];return e}(e);let i="";for(let s=0,n=t.length;s<n;s++){const e=t.charCodeAt(s);if(o&&37===e&&s+2<n&&/^[0-9a-f]{2}$/i.test(t.slice(s+1,s+3)))i+=t.slice(s,s+3),s+=2;else if(e<128)i+=h[e];else if(e>=55296&&e<=57343){if(e>=55296&&e<=56319&&s+1<n){const e=t.charCodeAt(s+1);if(e>=56320&&e<=57343){i+=encodeURIComponent(t[s]+t[s+1]),s++;continue}}i+="%EF%BF%BD"}else i+=encodeURIComponent(t[s])}return i}function o(t){let e="";return e+=t.protocol||"",e+=t.slashes?"//":"",e+=t.auth?t.auth+"@":"",t.hostname&&-1!==t.hostname.indexOf(":")?e+="["+t.hostname+"]":e+=t.hostname||"",e+=t.port?":"+t.port:"",e+=t.pathname||"",e+=t.search||"",e+=t.hash||"",e}function h(){this.protocol=null,this.slashes=null,this.auth=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.pathname=null}n.defaultChars=";/?:@&=+$,-_.!~*'()#",n.componentChars="-_.!~*'()";const i=/^([a-z0-9.+-]+:)/i,r=/:[0-9]*$/,a=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,l=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),c=["'"].concat(l),f=["%","/","?",";","#"].concat(c),p=["/","?","#"],u=/^[+a-z0-9A-Z_-]{0,63}$/,m=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,g={javascript:!0,"javascript:":!0},d={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0};function C(t,e){if(t&&t instanceof h)return t;const s=new h;return s.parse(t,e),s}h.prototype.parse=function(t,e){let s,n,o,h=t;if(h=h.trim(),!e&&1===t.split("#").length){const t=a.exec(h);if(t)return this.pathname=t[1],t[2]&&(this.search=t[2]),this}let r=i.exec(h);if(r&&(r=r[0],s=r.toLowerCase(),this.protocol=r,h=h.substr(r.length)),(e||r||h.match(/^\/\/[^@\/]+@[^@\/]+/))&&(o="//"===h.substr(0,2),!o||r&&g[r]||(h=h.substr(2),this.slashes=!0)),!g[r]&&(o||r&&!d[r])){let t,e,s=-1;for(let r=0;r<p.length;r++)n=h.indexOf(p[r]),-1!==n&&(-1===s||n<s)&&(s=n);e=-1===s?h.lastIndexOf("@"):h.lastIndexOf("@",s),-1!==e&&(t=h.slice(0,e),h=h.slice(e+1),this.auth=t),s=-1;for(let r=0;r<f.length;r++)n=h.indexOf(f[r]),-1!==n&&(-1===s||n<s)&&(s=n);-1===s&&(s=h.length),":"===h[s-1]&&s--;const o=h.slice(0,s);h=h.slice(s),this.parseHost(o),this.hostname=this.hostname||"";const i="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!i){const t=this.hostname.split(/\./);for(let e=0,s=t.length;e<s;e++){const s=t[e];if(s&&!s.match(u)){let n="";for(let t=0,e=s.length;t<e;t++)s.charCodeAt(t)>127?n+="x":n+=s[t];if(!n.match(u)){const n=t.slice(0,e),o=t.slice(e+1),i=s.match(m);i&&(n.push(i[1]),o.unshift(i[2])),o.length&&(h=o.join(".")+h),this.hostname=n.join(".");break}}}}this.hostname.length>255&&(this.hostname=""),i&&(this.hostname=this.hostname.substr(1,this.hostname.length-2))}const l=h.indexOf("#");-1!==l&&(this.hash=h.substr(l),h=h.slice(0,l));const c=h.indexOf("?");return-1!==c&&(this.search=h.substr(c),h=h.slice(0,c)),h&&(this.pathname=h),d[s]&&this.hostname&&!this.pathname&&(this.pathname=""),this},h.prototype.parseHost=function(t){let e=r.exec(t);e&&(e=e[0],":"!==e&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)};const b=Object.freeze(Object.defineProperty({__proto__:null,decode:e,encode:n,format:o,parse:C},Symbol.toStringTag,{value:"Module"}));export{e as d,n as e,o as f,b as m,C as u};
|