(function(k,A){typeof exports=="object"&&typeof module!="undefined"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(k=typeof globalThis!="undefined"?globalThis:k||self,A(k.psl={}))})(this,function(k){"use strict";function A(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var O,D;function W(){if(D)return O;D=1;const e=2147483647,s=36,c=1,o=26,t=38,j=700,x=72,v=128,h="-",X=/^xn--/,Y=/[^\0-\x7F]/,Z=/[\x2E\u3002\uFF0E\uFF61]/g,aa={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},L=s-c,d=Math.floor,T=String.fromCharCode;function f(a){throw new RangeError(aa[a])}function oa(a,i){const m=[];let n=a.length;for(;n--;)m[n]=i(a[n]);return m}function F(a,i){const m=a.split("@");let n="";m.length>1&&(n=m[0]+"@",a=m[1]),a=a.replace(Z,".");const r=a.split("."),p=oa(r,i).join(".");return n+p}function H(a){const i=[];let m=0;const n=a.length;for(;m=55296&&r<=56319&&mString.fromCodePoint(...a),ia=function(a){return a>=48&&a<58?26+(a-48):a>=65&&a<91?a-65:a>=97&&a<123?a-97:s},N=function(a,i){return a+22+75*(a<26)-((i!=0)<<5)},R=function(a,i,m){let n=0;for(a=m?d(a/j):a>>1,a+=d(a/i);a>L*o>>1;n+=s)a=d(a/L);return d(n+(L+1)*a/(a+t))},P=function(a){const i=[],m=a.length;let n=0,r=v,p=x,b=a.lastIndexOf(h);b<0&&(b=0);for(let u=0;u=128&&f("not-basic"),i.push(a.charCodeAt(u));for(let u=b>0?b+1:0;u=m&&f("invalid-input");const y=ia(a.charCodeAt(u++));y>=s&&f("invalid-input"),y>d((e-n)/g)&&f("overflow"),n+=y*g;const q=w<=p?c:w>=p+o?o:w-p;if(yd(e/C)&&f("overflow"),g*=C}const z=i.length+1;p=R(n-l,z,l==0),d(n/z)>e-r&&f("overflow"),r+=d(n/z),n%=z,i.splice(n++,0,r)}return String.fromCodePoint(...i)},V=function(a){const i=[];a=H(a);const m=a.length;let n=v,r=0,p=x;for(const l of a)l<128&&i.push(T(l));const b=i.length;let u=b;for(b&&i.push(h);u=n&&gd((e-r)/z)&&f("overflow"),r+=(l-n)*z,n=l;for(const g of a)if(ge&&f("overflow"),g===n){let w=r;for(let y=s;;y+=s){const q=y<=p?c:y>=p+o?o:y-p;if(w{const c=s.replace(/^(\*\.|\!)/,""),o=_.toASCII(c),t=s.charAt(0);if(e.has(o))throw new Error(`Multiple rules found for ${s} (${o})`);return e.set(o,{rule:s,suffix:c,punySuffix:o,wildcard:t==="*",exception:t==="!"}),e},new Map),J=e=>{const c=_.toASCII(e).split(".");for(let o=0;o{const s=_.toASCII(e);if(s.length<1)return"DOMAIN_TOO_SHORT";if(s.length>255)return"DOMAIN_TOO_LONG";const c=s.split(".");let o;for(let t=0;t63)return"LABEL_TOO_LONG";if(o.charAt(0)==="-")return"LABEL_STARTS_WITH_DASH";if(o.charAt(o.length-1)==="-")return"LABEL_ENDS_WITH_DASH";if(!/^[a-z0-9\-_]+$/.test(o))return"LABEL_INVALID_CHARS"}},I=e=>{if(typeof e!="string")throw new TypeError("Domain name must be a string.");let s=e.slice(0).toLowerCase();s.charAt(s.length-1)==="."&&(s=s.slice(0,s.length-1));const c=K(s);if(c)return{input:e,error:{message:E[c],code:c}};const o={input:e,tld:null,sld:null,domain:null,subdomain:null,listed:!1},t=s.split(".");if(t[t.length-1]==="local")return o;const j=()=>(/xn--/.test(s)&&(o.domain&&(o.domain=_.toASCII(o.domain)),o.subdomain&&(o.subdomain=_.toASCII(o.subdomain))),o),x=J(s);if(!x)return t.length<2?o:(o.tld=t.pop(),o.sld=t.pop(),o.domain=[o.sld,o.tld].join("."),t.length&&(o.subdomain=t.pop()),j());o.listed=!0;const v=x.suffix.split("."),h=t.slice(0,t.length-v.length);return x.exception&&h.push(v.shift()),o.tld=v.join("."),!h.length||(x.wildcard&&(v.unshift(h.pop()),o.tld=v.join(".")),!h.length)||(o.sld=h.pop(),o.domain=[o.sld,o.tld].join("."),h.length&&(o.subdomain=h.join("."))),j()},B=e=>e&&I(e).domain||null,M=e=>{const s=I(e);return!!(s.domain&&s.listed)},Q={parse:I,get:B,isValid:M,rules:S};k.default=Q,k.errorCodes=E,k.get=B,k.isValid=M,k.parse=I,k.rules=S,Object.defineProperties(k,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});