Skip to content

Commit ed5b305

Browse files
authored
feat(exports): Add Rules Export (#331)
* add rules export * add named export for rules
1 parent 22b6478 commit ed5b305

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

dist/psl.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/psl.mjs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
function U(e) {
1+
function $(e) {
22
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
33
}
44
var C, F;
5-
function $() {
5+
function J() {
66
if (F) return C;
77
F = 1;
8-
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 = {
8+
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 = {
99
overflow: "Overflow: input needs wider integers to process",
1010
"not-basic": "Illegal input >= 0x80 (not a basic code point)",
1111
"invalid-input": "Invalid input"
1212
}, _ = s - c, h = Math.floor, I = String.fromCharCode;
1313
function v(a) {
14-
throw new RangeError(P[a]);
14+
throw new RangeError(V[a]);
1515
}
16-
function V(a, i) {
16+
function G(a, i) {
1717
const m = [];
1818
let n = a.length;
1919
for (; n--; )
@@ -23,8 +23,8 @@ function $() {
2323
function L(a, i) {
2424
const m = a.split("@");
2525
let n = "";
26-
m.length > 1 && (n = m[0] + "@", a = m[1]), a = a.replace(R, ".");
27-
const r = a.split("."), p = V(r, i).join(".");
26+
m.length > 1 && (n = m[0] + "@", a = m[1]), a = a.replace(P, ".");
27+
const r = a.split("."), p = G(r, i).join(".");
2828
return n + p;
2929
}
3030
function S(a) {
@@ -41,7 +41,7 @@ function $() {
4141
}
4242
return i;
4343
}
44-
const G = (a) => String.fromCodePoint(...a), W = function(a) {
44+
const W = (a) => String.fromCodePoint(...a), U = function(a) {
4545
return a >= 48 && a < 58 ? 26 + (a - 48) : a >= 65 && a < 91 ? a - 65 : a >= 97 && a < 123 ? a - 97 : s;
4646
}, D = function(a, i) {
4747
return a + 22 + 75 * (a < 26) - ((i != 0) << 5);
@@ -60,7 +60,7 @@ function $() {
6060
const k = n;
6161
for (let l = 1, b = s; ; b += s) {
6262
u >= m && v("invalid-input");
63-
const w = W(a.charCodeAt(u++));
63+
const w = U(a.charCodeAt(u++));
6464
w >= s && v("invalid-input"), w > h((e - n) / l) && v("overflow"), n += w * l;
6565
const x = b <= p ? c : b >= p + o ? o : b - p;
6666
if (w < x)
@@ -121,24 +121,24 @@ function $() {
121121
*/
122122
ucs2: {
123123
decode: S,
124-
encode: G
124+
encode: W
125125
},
126126
decode: E,
127127
encode: B,
128128
toASCII: function(a) {
129129
return L(a, function(i) {
130-
return N.test(i) ? "xn--" + B(i) : i;
130+
return R.test(i) ? "xn--" + B(i) : i;
131131
});
132132
},
133133
toUnicode: function(a) {
134134
return L(a, function(i) {
135-
return H.test(i) ? E(i.slice(4).toLowerCase()) : i;
135+
return N.test(i) ? E(i.slice(4).toLowerCase()) : i;
136136
});
137137
}
138138
}, C;
139139
}
140-
var J = $();
141-
const A = /* @__PURE__ */ U(J), K = [
140+
var K = J();
141+
const A = /* @__PURE__ */ $(K), H = [
142142
"ac",
143143
"com.ac",
144144
"edu.ac",
@@ -9915,7 +9915,7 @@ const A = /* @__PURE__ */ U(J), K = [
99159915
"basicserver.io",
99169916
"virtualserver.io",
99179917
"enterprisecloud.nu"
9918-
], Q = K.reduce(
9918+
], Q = H.reduce(
99199919
(e, s) => {
99209920
const c = s.replace(/^(\*\.|\!)/, ""), o = A.toASCII(c), t = s.charAt(0);
99219921
if (e.has(o))
@@ -9998,11 +9998,12 @@ const A = /* @__PURE__ */ U(J), K = [
99989998
}, aa = (e) => e && O(e).domain || null, oa = (e) => {
99999999
const s = O(e);
1000010000
return !!(s.domain && s.listed);
10001-
}, na = { parse: O, get: aa, isValid: oa };
10001+
}, na = { parse: O, get: aa, isValid: oa, rules: H };
1000210002
export {
1000310003
na as default,
1000410004
Y as errorCodes,
1000510005
aa as get,
1000610006
oa as isValid,
10007-
O as parse
10007+
O as parse,
10008+
H as rules
1000810009
};

dist/psl.umd.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,9 @@ export const isValid = (domain) => {
244244
return Boolean(parsed.domain && parsed.listed);
245245
};
246246

247-
export default { parse, get, isValid };
247+
//
248+
// List of rules from known public suffixes.
249+
//
250+
export { default as rules } from './data/rules.js';
251+
252+
export default { parse, get, isValid, rules };

types/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ export function get(domain: string): string | null;
5050
* Check whether the given domain belongs to a known public suffix
5151
*/
5252
export function isValid(domain: string): boolean;
53+
54+
/**
55+
* An array of TLDs used to parse domains.
56+
*/
57+
export const rules: string[];

0 commit comments

Comments
 (0)