From ed5b3052540876721a139ccc4935bfa2a112e721 Mon Sep 17 00:00:00 2001 From: Jaden Date: Tue, 3 Dec 2024 10:21:14 +0000 Subject: [PATCH] feat(exports): Add Rules Export (#331) * add rules export * add named export for rules --- dist/psl.cjs | 2 +- dist/psl.mjs | 35 ++++++++++++++++++----------------- dist/psl.umd.cjs | 2 +- index.js | 7 ++++++- types/index.d.ts | 5 +++++ 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/dist/psl.cjs b/dist/psl.cjs index a84438a..c8190d5 100644 --- a/dist/psl.cjs +++ b/dist/psl.cjs @@ -1 +1 @@ -"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function K(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var O,F;function Q(){if(F)return O;F=1;const e=2147483647,s=36,c=1,o=26,t=38,d=700,z=72,y=128,g="-",P=/^xn--/,V=/[^\0-\x7F]/,G=/[\x2E\u3002\uFF0E\uFF61]/g,W={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},C=s-c,h=Math.floor,I=String.fromCharCode;function v(a){throw new RangeError(W[a])}function U(a,i){const m=[];let n=a.length;for(;n--;)m[n]=i(a[n]);return m}function S(a,i){const m=a.split("@");let n="";m.length>1&&(n=m[0]+"@",a=m[1]),a=a.replace(G,".");const r=a.split("."),p=U(r,i).join(".");return n+p}function L(a){const i=[];let m=0;const n=a.length;for(;m=55296&&r<=56319&&mString.fromCodePoint(...a),J=function(a){return a>=48&&a<58?26+(a-48):a>=65&&a<91?a-65:a>=97&&a<123?a-97:s},D=function(a,i){return a+22+75*(a<26)-((i!=0)<<5)},T=function(a,i,m){let n=0;for(a=m?h(a/d):a>>1,a+=h(a/i);a>C*o>>1;n+=s)a=h(a/C);return h(n+(C+1)*a/(a+t))},E=function(a){const i=[],m=a.length;let n=0,r=y,p=z,j=a.lastIndexOf(g);j<0&&(j=0);for(let u=0;u=128&&v("not-basic"),i.push(a.charCodeAt(u));for(let u=j>0?j+1:0;u=m&&v("invalid-input");const w=J(a.charCodeAt(u++));w>=s&&v("invalid-input"),w>h((e-n)/l)&&v("overflow"),n+=w*l;const x=b<=p?c:b>=p+o?o:b-p;if(wh(e/q)&&v("overflow"),l*=q}const f=i.length+1;p=T(n-k,f,k==0),h(n/f)>e-r&&v("overflow"),r+=h(n/f),n%=f,i.splice(n++,0,r)}return String.fromCodePoint(...i)},B=function(a){const i=[];a=L(a);const m=a.length;let n=y,r=0,p=z;for(const k of a)k<128&&i.push(I(k));const j=i.length;let u=j;for(j&&i.push(g);u=n&&lh((e-r)/f)&&v("overflow"),r+=(k-n)*f,n=k;for(const l of a)if(le&&v("overflow"),l===n){let b=r;for(let w=s;;w+=s){const x=w<=p?c:w>=p+o?o:w-p;if(b{const c=s.replace(/^(\*\.|\!)/,""),o=A.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),aa=e=>{const c=A.toASCII(e).split(".");for(let o=0;o{const s=A.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"}},_=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=oa(s);if(c)return{input:e,error:{message:H[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 d=()=>(/xn--/.test(s)&&(o.domain&&(o.domain=A.toASCII(o.domain)),o.subdomain&&(o.subdomain=A.toASCII(o.subdomain))),o),z=aa(s);if(!z)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()),d());o.listed=!0;const y=z.suffix.split("."),g=t.slice(0,t.length-y.length);return z.exception&&g.push(y.shift()),o.tld=y.join("."),!g.length||(z.wildcard&&(y.unshift(g.pop()),o.tld=y.join(".")),!g.length)||(o.sld=g.pop(),o.domain=[o.sld,o.tld].join("."),g.length&&(o.subdomain=g.join("."))),d()},N=e=>e&&_(e).domain||null,R=e=>{const s=_(e);return!!(s.domain&&s.listed)},sa={parse:_,get:N,isValid:R};exports.default=sa;exports.errorCodes=H;exports.get=N;exports.isValid=R;exports.parse=_; +"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function Q(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var O,H;function X(){if(H)return O;H=1;const e=2147483647,s=36,c=1,o=26,t=38,d=700,z=72,y=128,g="-",V=/^xn--/,G=/[^\0-\x7F]/,W=/[\x2E\u3002\uFF0E\uFF61]/g,U={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},C=s-c,h=Math.floor,I=String.fromCharCode;function v(a){throw new RangeError(U[a])}function $(a,i){const m=[];let n=a.length;for(;n--;)m[n]=i(a[n]);return m}function L(a,i){const m=a.split("@");let n="";m.length>1&&(n=m[0]+"@",a=m[1]),a=a.replace(W,".");const r=a.split("."),p=$(r,i).join(".");return n+p}function D(a){const i=[];let m=0;const n=a.length;for(;m=55296&&r<=56319&&mString.fromCodePoint(...a),K=function(a){return a>=48&&a<58?26+(a-48):a>=65&&a<91?a-65:a>=97&&a<123?a-97:s},T=function(a,i){return a+22+75*(a<26)-((i!=0)<<5)},E=function(a,i,m){let n=0;for(a=m?h(a/d):a>>1,a+=h(a/i);a>C*o>>1;n+=s)a=h(a/C);return h(n+(C+1)*a/(a+t))},B=function(a){const i=[],m=a.length;let n=0,r=y,p=z,j=a.lastIndexOf(g);j<0&&(j=0);for(let u=0;u=128&&v("not-basic"),i.push(a.charCodeAt(u));for(let u=j>0?j+1:0;u=m&&v("invalid-input");const w=K(a.charCodeAt(u++));w>=s&&v("invalid-input"),w>h((e-n)/l)&&v("overflow"),n+=w*l;const x=b<=p?c:b>=p+o?o:b-p;if(wh(e/q)&&v("overflow"),l*=q}const f=i.length+1;p=E(n-k,f,k==0),h(n/f)>e-r&&v("overflow"),r+=h(n/f),n%=f,i.splice(n++,0,r)}return String.fromCodePoint(...i)},M=function(a){const i=[];a=D(a);const m=a.length;let n=y,r=0,p=z;for(const k of a)k<128&&i.push(I(k));const j=i.length;let u=j;for(j&&i.push(g);u=n&&lh((e-r)/f)&&v("overflow"),r+=(k-n)*f,n=k;for(const l of a)if(le&&v("overflow"),l===n){let b=r;for(let w=s;;w+=s){const x=w<=p?c:w>=p+o?o:w-p;if(b{const c=s.replace(/^(\*\.|\!)/,""),o=A.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),aa=e=>{const c=A.toASCII(e).split(".");for(let o=0;o{const s=A.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"}},_=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=oa(s);if(c)return{input:e,error:{message:N[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 d=()=>(/xn--/.test(s)&&(o.domain&&(o.domain=A.toASCII(o.domain)),o.subdomain&&(o.subdomain=A.toASCII(o.subdomain))),o),z=aa(s);if(!z)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()),d());o.listed=!0;const y=z.suffix.split("."),g=t.slice(0,t.length-y.length);return z.exception&&g.push(y.shift()),o.tld=y.join("."),!g.length||(z.wildcard&&(y.unshift(g.pop()),o.tld=y.join(".")),!g.length)||(o.sld=g.pop(),o.domain=[o.sld,o.tld].join("."),g.length&&(o.subdomain=g.join("."))),d()},R=e=>e&&_(e).domain||null,P=e=>{const s=_(e);return!!(s.domain&&s.listed)},sa={parse:_,get:R,isValid:P,rules:S};exports.default=sa;exports.errorCodes=N;exports.get=R;exports.isValid=P;exports.parse=_;exports.rules=S; diff --git a/dist/psl.mjs b/dist/psl.mjs index 07758bb..ac9a74d 100644 --- a/dist/psl.mjs +++ b/dist/psl.mjs @@ -1,19 +1,19 @@ -function U(e) { +function $(e) { return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e; } var C, F; -function $() { +function J() { if (F) return C; F = 1; - const e = 2147483647, s = 36, c = 1, o = 26, t = 38, d = 700, z = 72, y = 128, g = "-", H = /^xn--/, N = /[^\0-\x7F]/, R = /[\x2E\u3002\uFF0E\uFF61]/g, P = { + const e = 2147483647, s = 36, c = 1, o = 26, t = 38, d = 700, z = 72, y = 128, g = "-", N = /^xn--/, R = /[^\0-\x7F]/, P = /[\x2E\u3002\uFF0E\uFF61]/g, V = { overflow: "Overflow: input needs wider integers to process", "not-basic": "Illegal input >= 0x80 (not a basic code point)", "invalid-input": "Invalid input" }, _ = s - c, h = Math.floor, I = String.fromCharCode; function v(a) { - throw new RangeError(P[a]); + throw new RangeError(V[a]); } - function V(a, i) { + function G(a, i) { const m = []; let n = a.length; for (; n--; ) @@ -23,8 +23,8 @@ function $() { function L(a, i) { const m = a.split("@"); let n = ""; - m.length > 1 && (n = m[0] + "@", a = m[1]), a = a.replace(R, "."); - const r = a.split("."), p = V(r, i).join("."); + m.length > 1 && (n = m[0] + "@", a = m[1]), a = a.replace(P, "."); + const r = a.split("."), p = G(r, i).join("."); return n + p; } function S(a) { @@ -41,7 +41,7 @@ function $() { } return i; } - const G = (a) => String.fromCodePoint(...a), W = function(a) { + const W = (a) => String.fromCodePoint(...a), U = function(a) { return a >= 48 && a < 58 ? 26 + (a - 48) : a >= 65 && a < 91 ? a - 65 : a >= 97 && a < 123 ? a - 97 : s; }, D = function(a, i) { return a + 22 + 75 * (a < 26) - ((i != 0) << 5); @@ -60,7 +60,7 @@ function $() { const k = n; for (let l = 1, b = s; ; b += s) { u >= m && v("invalid-input"); - const w = W(a.charCodeAt(u++)); + const w = U(a.charCodeAt(u++)); w >= s && v("invalid-input"), w > h((e - n) / l) && v("overflow"), n += w * l; const x = b <= p ? c : b >= p + o ? o : b - p; if (w < x) @@ -121,24 +121,24 @@ function $() { */ ucs2: { decode: S, - encode: G + encode: W }, decode: E, encode: B, toASCII: function(a) { return L(a, function(i) { - return N.test(i) ? "xn--" + B(i) : i; + return R.test(i) ? "xn--" + B(i) : i; }); }, toUnicode: function(a) { return L(a, function(i) { - return H.test(i) ? E(i.slice(4).toLowerCase()) : i; + return N.test(i) ? E(i.slice(4).toLowerCase()) : i; }); } }, C; } -var J = $(); -const A = /* @__PURE__ */ U(J), K = [ +var K = J(); +const A = /* @__PURE__ */ $(K), H = [ "ac", "com.ac", "edu.ac", @@ -9915,7 +9915,7 @@ const A = /* @__PURE__ */ U(J), K = [ "basicserver.io", "virtualserver.io", "enterprisecloud.nu" -], Q = K.reduce( +], Q = H.reduce( (e, s) => { const c = s.replace(/^(\*\.|\!)/, ""), o = A.toASCII(c), t = s.charAt(0); if (e.has(o)) @@ -9998,11 +9998,12 @@ const A = /* @__PURE__ */ U(J), K = [ }, aa = (e) => e && O(e).domain || null, oa = (e) => { const s = O(e); return !!(s.domain && s.listed); -}, na = { parse: O, get: aa, isValid: oa }; +}, na = { parse: O, get: aa, isValid: oa, rules: H }; export { na as default, Y as errorCodes, aa as get, oa as isValid, - O as parse + O as parse, + H as rules }; diff --git a/dist/psl.umd.cjs b/dist/psl.umd.cjs index 04de8b0..9659ba0 100644 --- a/dist/psl.umd.cjs +++ b/dist/psl.umd.cjs @@ -1 +1 @@ -(function(g,A){typeof exports=="object"&&typeof module!="undefined"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(g=typeof globalThis!="undefined"?globalThis:g||self,A(g.psl={}))})(this,function(g){"use strict";function A(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var O,T;function G(){if(T)return O;T=1;const e=2147483647,s=36,c=1,o=26,t=38,j=700,x=72,v=128,h="-",Q=/^xn--/,X=/[^\0-\x7F]/,Y=/[\x2E\u3002\uFF0E\uFF61]/g,Z={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},S=s-c,d=Math.floor,L=String.fromCharCode;function f(a){throw new RangeError(Z[a])}function aa(a,i){const m=[];let n=a.length;for(;n--;)m[n]=i(a[n]);return m}function M(a,i){const m=a.split("@");let n="";m.length>1&&(n=m[0]+"@",a=m[1]),a=a.replace(Y,".");const r=a.split("."),p=aa(r,i).join(".");return n+p}function F(a){const i=[];let m=0;const n=a.length;for(;m=55296&&r<=56319&&mString.fromCodePoint(...a),sa=function(a){return a>=48&&a<58?26+(a-48):a>=65&&a<91?a-65:a>=97&&a<123?a-97:s},H=function(a,i){return a+22+75*(a<26)-((i!=0)<<5)},N=function(a,i,m){let n=0;for(a=m?d(a/j):a>>1,a+=d(a/i);a>S*o>>1;n+=s)a=d(a/S);return d(n+(S+1)*a/(a+t))},R=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=sa(a.charCodeAt(u++));y>=s&&f("invalid-input"),y>d((e-n)/l)&&f("overflow"),n+=y*l;const q=w<=p?c:w>=p+o?o:w-p;if(yd(e/C)&&f("overflow"),l*=C}const z=i.length+1;p=N(n-k,z,k==0),d(n/z)>e-r&&f("overflow"),r+=d(n/z),n%=z,i.splice(n++,0,r)}return String.fromCodePoint(...i)},P=function(a){const i=[];a=F(a);const m=a.length;let n=v,r=0,p=x;for(const k of a)k<128&&i.push(L(k));const b=i.length;let u=b;for(b&&i.push(h);u=n&&ld((e-r)/z)&&f("overflow"),r+=(k-n)*z,n=k;for(const l of a)if(le&&f("overflow"),l===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),$=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=J(s);if(c)return{input:e,error:{message:D[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=$(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()},E=e=>e&&I(e).domain||null,B=e=>{const s=I(e);return!!(s.domain&&s.listed)},K={parse:I,get:E,isValid:B};g.default=K,g.errorCodes=D,g.get=E,g.isValid=B,g.parse=I,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(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"}})}); diff --git a/index.js b/index.js index e23601d..8390b34 100644 --- a/index.js +++ b/index.js @@ -244,4 +244,9 @@ export const isValid = (domain) => { return Boolean(parsed.domain && parsed.listed); }; -export default { parse, get, isValid }; +// +// List of rules from known public suffixes. +// +export { default as rules } from './data/rules.js'; + +export default { parse, get, isValid, rules }; diff --git a/types/index.d.ts b/types/index.d.ts index 15632c9..242be71 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -50,3 +50,8 @@ export function get(domain: string): string | null; * Check whether the given domain belongs to a known public suffix */ export function isValid(domain: string): boolean; + +/** + * An array of TLDs used to parse domains. + */ +export const rules: string[]; \ No newline at end of file