@structured-world/structured-public-domains 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -0
- package/dist/chunk-EON4VJGA.js +121 -0
- package/dist/index.cjs +161 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +34 -0
- package/dist/psl-data.cjs +3 -0
- package/{structured_public_domains_bg.wasm → dist/psl.bin} +0 -0
- package/dist/tiny.cjs +293 -0
- package/dist/tiny.d.cts +45 -0
- package/dist/tiny.d.ts +45 -0
- package/dist/tiny.js +167 -0
- package/dist/trie-jGeN4GI6.d.cts +11 -0
- package/dist/trie-jGeN4GI6.d.ts +11 -0
- package/package.json +42 -28
- package/browser.d.ts +0 -17
- package/browser.js +0 -44
- package/index.d.cts +0 -3
- package/index.d.ts +0 -28
- package/node.cjs +0 -30
- package/node.js +0 -35
- package/structured_public_domains.d.ts +0 -87
- package/structured_public_domains.js +0 -309
- package/structured_public_domains_node.cjs +0 -219
- package/structured_public_domains_node.d.cts +0 -47
package/dist/tiny.d.cts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { D as DomainInfo } from './trie-jGeN4GI6.cjs';
|
|
2
|
+
|
|
3
|
+
/** Default data source: the prebuilt trie served from this package via jsDelivr's CDN. */
|
|
4
|
+
declare const DEFAULT_PSL_URL: string;
|
|
5
|
+
/** Options for {@link load}. */
|
|
6
|
+
interface LoadOptions {
|
|
7
|
+
/** Where to fetch `psl.bin` from. Defaults to {@link DEFAULT_PSL_URL}. */
|
|
8
|
+
url?: string;
|
|
9
|
+
/** Custom fetch implementation (e.g. for proxies/tests). Defaults to the global `fetch`. */
|
|
10
|
+
fetch?: typeof fetch;
|
|
11
|
+
/** Enable the persistent local cache (Node file / browser CacheStorage). Default `true`. */
|
|
12
|
+
cache?: boolean;
|
|
13
|
+
/** Cache freshness window in milliseconds. Default 24h. */
|
|
14
|
+
cacheTtlMs?: number;
|
|
15
|
+
/** Node only: directory for the cache file. Defaults to an OS temp subdir. */
|
|
16
|
+
cacheDir?: string;
|
|
17
|
+
/** Re-fetch even if already loaded / cached. Default `false`. */
|
|
18
|
+
force?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Fetch, cache, and parse the PSL trie. Idempotent: a second call is a no-op
|
|
22
|
+
* unless `force` is set. Must be awaited before {@link lookup} and friends.
|
|
23
|
+
*
|
|
24
|
+
* @throws if the data cannot be fetched or is implausibly small / corrupt.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { load, registrableDomain } from '@structured-world/structured-public-domains/tiny';
|
|
29
|
+
* await load();
|
|
30
|
+
* registrableDomain('sub.example.co.uk'); // "example.co.uk"
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function load(opts?: LoadOptions): Promise<void>;
|
|
34
|
+
/** Whether {@link load} has completed and the lookup API is ready. */
|
|
35
|
+
declare function isLoaded(): boolean;
|
|
36
|
+
/** Look up a domain. Requires a prior `await load()`. See the main entry's `lookup`. */
|
|
37
|
+
declare function lookup(domain: string): DomainInfo | undefined;
|
|
38
|
+
/** Extract the registrable domain (eTLD+1). Requires a prior `await load()`. */
|
|
39
|
+
declare function registrableDomain(domain: string): string | undefined;
|
|
40
|
+
/** Whether a domain's suffix is a known PSL entry. Requires a prior `await load()`. */
|
|
41
|
+
declare function isKnownSuffix(domain: string): boolean;
|
|
42
|
+
/** The raw binary trie blob that was loaded (defensive copy). Requires a prior `await load()`. */
|
|
43
|
+
declare function pslData(): Uint8Array;
|
|
44
|
+
|
|
45
|
+
export { DEFAULT_PSL_URL, DomainInfo, type LoadOptions, isKnownSuffix, isLoaded, load, lookup, pslData, registrableDomain };
|
package/dist/tiny.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { D as DomainInfo } from './trie-jGeN4GI6.js';
|
|
2
|
+
|
|
3
|
+
/** Default data source: the prebuilt trie served from this package via jsDelivr's CDN. */
|
|
4
|
+
declare const DEFAULT_PSL_URL: string;
|
|
5
|
+
/** Options for {@link load}. */
|
|
6
|
+
interface LoadOptions {
|
|
7
|
+
/** Where to fetch `psl.bin` from. Defaults to {@link DEFAULT_PSL_URL}. */
|
|
8
|
+
url?: string;
|
|
9
|
+
/** Custom fetch implementation (e.g. for proxies/tests). Defaults to the global `fetch`. */
|
|
10
|
+
fetch?: typeof fetch;
|
|
11
|
+
/** Enable the persistent local cache (Node file / browser CacheStorage). Default `true`. */
|
|
12
|
+
cache?: boolean;
|
|
13
|
+
/** Cache freshness window in milliseconds. Default 24h. */
|
|
14
|
+
cacheTtlMs?: number;
|
|
15
|
+
/** Node only: directory for the cache file. Defaults to an OS temp subdir. */
|
|
16
|
+
cacheDir?: string;
|
|
17
|
+
/** Re-fetch even if already loaded / cached. Default `false`. */
|
|
18
|
+
force?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Fetch, cache, and parse the PSL trie. Idempotent: a second call is a no-op
|
|
22
|
+
* unless `force` is set. Must be awaited before {@link lookup} and friends.
|
|
23
|
+
*
|
|
24
|
+
* @throws if the data cannot be fetched or is implausibly small / corrupt.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { load, registrableDomain } from '@structured-world/structured-public-domains/tiny';
|
|
29
|
+
* await load();
|
|
30
|
+
* registrableDomain('sub.example.co.uk'); // "example.co.uk"
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function load(opts?: LoadOptions): Promise<void>;
|
|
34
|
+
/** Whether {@link load} has completed and the lookup API is ready. */
|
|
35
|
+
declare function isLoaded(): boolean;
|
|
36
|
+
/** Look up a domain. Requires a prior `await load()`. See the main entry's `lookup`. */
|
|
37
|
+
declare function lookup(domain: string): DomainInfo | undefined;
|
|
38
|
+
/** Extract the registrable domain (eTLD+1). Requires a prior `await load()`. */
|
|
39
|
+
declare function registrableDomain(domain: string): string | undefined;
|
|
40
|
+
/** Whether a domain's suffix is a known PSL entry. Requires a prior `await load()`. */
|
|
41
|
+
declare function isKnownSuffix(domain: string): boolean;
|
|
42
|
+
/** The raw binary trie blob that was loaded (defensive copy). Requires a prior `await load()`. */
|
|
43
|
+
declare function pslData(): Uint8Array;
|
|
44
|
+
|
|
45
|
+
export { DEFAULT_PSL_URL, DomainInfo, type LoadOptions, isKnownSuffix, isLoaded, load, lookup, pslData, registrableDomain };
|
package/dist/tiny.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { parseTrie, lookupTrie } from './chunk-EON4VJGA.js';
|
|
2
|
+
|
|
3
|
+
// src/tiny.ts
|
|
4
|
+
var PSL_RANGE = "0.0" ;
|
|
5
|
+
var DEFAULT_PSL_URL = `https://cdn.jsdelivr.net/npm/@structured-world/structured-public-domains@${PSL_RANGE}/dist/psl.bin`;
|
|
6
|
+
var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
7
|
+
var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
8
|
+
var cachedBytes;
|
|
9
|
+
var cachedTrie;
|
|
10
|
+
var inFlight;
|
|
11
|
+
var latestGen = 0;
|
|
12
|
+
var latestSettled;
|
|
13
|
+
function load(opts = {}) {
|
|
14
|
+
if (cachedTrie !== void 0 && opts.force !== true) return Promise.resolve();
|
|
15
|
+
if (inFlight !== void 0 && opts.force !== true) return inFlight;
|
|
16
|
+
const gen = ++latestGen;
|
|
17
|
+
const pending = doLoad(opts, gen);
|
|
18
|
+
latestSettled = pending;
|
|
19
|
+
inFlight = pending;
|
|
20
|
+
pending.finally(() => {
|
|
21
|
+
if (inFlight === pending) inFlight = void 0;
|
|
22
|
+
}).catch(() => void 0);
|
|
23
|
+
return pending;
|
|
24
|
+
}
|
|
25
|
+
function mirrorLatest() {
|
|
26
|
+
return latestSettled ?? Promise.resolve();
|
|
27
|
+
}
|
|
28
|
+
async function doLoad(opts, gen) {
|
|
29
|
+
let data;
|
|
30
|
+
let trie;
|
|
31
|
+
try {
|
|
32
|
+
[data, trie] = await fetchAndParse(opts);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
if (gen !== latestGen) return mirrorLatest();
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
if (gen !== latestGen) return mirrorLatest();
|
|
38
|
+
cachedBytes = data;
|
|
39
|
+
cachedTrie = trie;
|
|
40
|
+
}
|
|
41
|
+
async function fetchAndParse(opts) {
|
|
42
|
+
const url = opts.url ?? DEFAULT_PSL_URL;
|
|
43
|
+
const ttlMs = opts.cacheTtlMs ?? DEFAULT_TTL_MS;
|
|
44
|
+
const useCache = opts.cache ?? true;
|
|
45
|
+
const doFetch = opts.fetch ?? globalThis.fetch;
|
|
46
|
+
if (useCache && opts.force !== true) {
|
|
47
|
+
const cached = await readCache(url, ttlMs, opts.cacheDir);
|
|
48
|
+
if (cached !== void 0) {
|
|
49
|
+
try {
|
|
50
|
+
return [cached, parseTrie(cached)];
|
|
51
|
+
} catch {
|
|
52
|
+
await deleteCache(url, opts.cacheDir).catch(() => void 0);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (typeof doFetch !== "function") {
|
|
57
|
+
throw new Error("no fetch implementation available; pass `fetch` in LoadOptions");
|
|
58
|
+
}
|
|
59
|
+
const data = await fetchBytes(doFetch, url);
|
|
60
|
+
const trie = parseTrie(data);
|
|
61
|
+
if (useCache) await writeCache(url, data, opts.cacheDir).catch(() => void 0);
|
|
62
|
+
return [data, trie];
|
|
63
|
+
}
|
|
64
|
+
function isLoaded() {
|
|
65
|
+
return cachedTrie !== void 0;
|
|
66
|
+
}
|
|
67
|
+
function requireTrie() {
|
|
68
|
+
if (cachedTrie === void 0) {
|
|
69
|
+
throw new Error("PSL data not loaded \u2014 call `await load()` before lookups");
|
|
70
|
+
}
|
|
71
|
+
return cachedTrie;
|
|
72
|
+
}
|
|
73
|
+
function lookup(domain) {
|
|
74
|
+
return lookupTrie(requireTrie(), domain);
|
|
75
|
+
}
|
|
76
|
+
function registrableDomain(domain) {
|
|
77
|
+
return lookup(domain)?.registrableDomain;
|
|
78
|
+
}
|
|
79
|
+
function isKnownSuffix(domain) {
|
|
80
|
+
return lookup(domain)?.known ?? false;
|
|
81
|
+
}
|
|
82
|
+
function pslData() {
|
|
83
|
+
if (cachedBytes === void 0) {
|
|
84
|
+
throw new Error("PSL data not loaded \u2014 call `await load()` before pslData()");
|
|
85
|
+
}
|
|
86
|
+
return cachedBytes.slice();
|
|
87
|
+
}
|
|
88
|
+
async function fetchBytes(doFetch, url) {
|
|
89
|
+
const res = await doFetch(url);
|
|
90
|
+
if (!res.ok) {
|
|
91
|
+
throw new Error(`failed to fetch PSL data from ${url}: ${res.status} ${res.statusText}`);
|
|
92
|
+
}
|
|
93
|
+
const data = new Uint8Array(await res.arrayBuffer());
|
|
94
|
+
if (data.length < 1024) {
|
|
95
|
+
throw new Error(`PSL data from ${url} is implausibly small (${data.length} bytes)`);
|
|
96
|
+
}
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
function cacheKey(url) {
|
|
100
|
+
let h = 2166136261;
|
|
101
|
+
for (let i = 0; i < url.length; i++) {
|
|
102
|
+
h ^= url.charCodeAt(i);
|
|
103
|
+
h = Math.imul(h, 16777619);
|
|
104
|
+
}
|
|
105
|
+
return (h >>> 0).toString(16).padStart(8, "0");
|
|
106
|
+
}
|
|
107
|
+
async function readCache(url, ttlMs, cacheDir) {
|
|
108
|
+
try {
|
|
109
|
+
return isNode ? await readNodeCache(url, ttlMs, cacheDir) : await readBrowserCache(url, ttlMs);
|
|
110
|
+
} catch {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function writeCache(url, data, cacheDir) {
|
|
115
|
+
if (isNode) await writeNodeCache(url, data, cacheDir);
|
|
116
|
+
else await writeBrowserCache(url, data);
|
|
117
|
+
}
|
|
118
|
+
async function deleteCache(url, cacheDir) {
|
|
119
|
+
if (isNode) {
|
|
120
|
+
const { fs, file } = await nodeCache(url, cacheDir);
|
|
121
|
+
fs.rmSync(file, { force: true });
|
|
122
|
+
} else if (typeof caches !== "undefined") {
|
|
123
|
+
const cache = await caches.open("structured-public-domains");
|
|
124
|
+
await cache.delete(url);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
var nodeRequire = (m) => import(
|
|
128
|
+
/* @vite-ignore */
|
|
129
|
+
m
|
|
130
|
+
);
|
|
131
|
+
async function nodeCache(url, cacheDir) {
|
|
132
|
+
const fs = await nodeRequire("node:fs");
|
|
133
|
+
const os = await nodeRequire("node:os");
|
|
134
|
+
const path = await nodeRequire("node:path");
|
|
135
|
+
const dir = cacheDir ?? path.join(os.tmpdir(), "structured-public-domains-cache");
|
|
136
|
+
return { fs, dir, file: path.join(dir, `psl-${cacheKey(url)}.bin`) };
|
|
137
|
+
}
|
|
138
|
+
async function readNodeCache(url, ttlMs, cacheDir) {
|
|
139
|
+
const { fs, file } = await nodeCache(url, cacheDir);
|
|
140
|
+
const stat = fs.statSync(file);
|
|
141
|
+
if (Date.now() - stat.mtimeMs >= ttlMs) return void 0;
|
|
142
|
+
return new Uint8Array(fs.readFileSync(file));
|
|
143
|
+
}
|
|
144
|
+
async function writeNodeCache(url, data, cacheDir) {
|
|
145
|
+
const { fs, dir, file } = await nodeCache(url, cacheDir);
|
|
146
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
147
|
+
const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
148
|
+
fs.writeFileSync(tmp, data);
|
|
149
|
+
fs.renameSync(tmp, file);
|
|
150
|
+
}
|
|
151
|
+
async function readBrowserCache(url, ttlMs) {
|
|
152
|
+
if (typeof caches === "undefined") return void 0;
|
|
153
|
+
const cache = await caches.open("structured-public-domains");
|
|
154
|
+
const res = await cache.match(url);
|
|
155
|
+
if (res == null) return void 0;
|
|
156
|
+
const cachedAt = Number(res.headers.get("x-cached-at") ?? "0");
|
|
157
|
+
if (!Number.isFinite(cachedAt) || Date.now() - cachedAt >= ttlMs) return void 0;
|
|
158
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
159
|
+
}
|
|
160
|
+
async function writeBrowserCache(url, data) {
|
|
161
|
+
if (typeof caches === "undefined") return;
|
|
162
|
+
const cache = await caches.open("structured-public-domains");
|
|
163
|
+
const body = data.slice();
|
|
164
|
+
await cache.put(url, new Response(body, { headers: { "x-cached-at": String(Date.now()) } }));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { DEFAULT_PSL_URL, isKnownSuffix, isLoaded, load, lookup, pslData, registrableDomain };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Result of a PSL lookup. */
|
|
2
|
+
interface DomainInfo {
|
|
3
|
+
/** The public suffix (e.g. `"co.uk"`, `"com"`, `"github.io"`). */
|
|
4
|
+
readonly suffix: string;
|
|
5
|
+
/** The registrable domain (eTLD+1), or `undefined` if the input is itself a suffix. */
|
|
6
|
+
readonly registrableDomain: string | undefined;
|
|
7
|
+
/** Whether the suffix matched an explicit PSL rule (vs the `*` fallback). */
|
|
8
|
+
readonly known: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type { DomainInfo as D };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Result of a PSL lookup. */
|
|
2
|
+
interface DomainInfo {
|
|
3
|
+
/** The public suffix (e.g. `"co.uk"`, `"com"`, `"github.io"`). */
|
|
4
|
+
readonly suffix: string;
|
|
5
|
+
/** The registrable domain (eTLD+1), or `undefined` if the input is itself a suffix. */
|
|
6
|
+
readonly registrableDomain: string | undefined;
|
|
7
|
+
/** Whether the suffix matched an explicit PSL rule (vs the `*` fallback). */
|
|
8
|
+
readonly known: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type { DomainInfo as D };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@structured-world/structured-public-domains",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Compact Public Suffix List (PSL)
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "Compact Public Suffix List (PSL) as a native TypeScript package: embedded ~108KB binary trie, synchronous zero-dependency lookups, ESM + CommonJS. Checked daily against publicsuffix.org.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -12,46 +12,60 @@
|
|
|
12
12
|
"public-suffix",
|
|
13
13
|
"domain",
|
|
14
14
|
"tld",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
15
|
+
"etld",
|
|
16
|
+
"registrable-domain",
|
|
17
|
+
"trie",
|
|
18
|
+
"validation"
|
|
18
19
|
],
|
|
19
20
|
"type": "module",
|
|
20
|
-
"main": "./
|
|
21
|
-
"
|
|
21
|
+
"main": "./dist/index.cjs",
|
|
22
|
+
"module": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
22
24
|
"exports": {
|
|
23
25
|
".": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"default": "./node.js"
|
|
28
|
-
},
|
|
29
|
-
"require": {
|
|
30
|
-
"types": "./index.d.cts",
|
|
31
|
-
"default": "./node.cjs"
|
|
32
|
-
}
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
33
29
|
},
|
|
34
|
-
"
|
|
35
|
-
"types": "./
|
|
36
|
-
"default": "./
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./dist/index.d.cts",
|
|
32
|
+
"default": "./dist/index.cjs"
|
|
37
33
|
}
|
|
38
34
|
},
|
|
39
|
-
"./
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
"./tiny": {
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./dist/tiny.d.ts",
|
|
38
|
+
"default": "./dist/tiny.js"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./dist/tiny.d.cts",
|
|
42
|
+
"default": "./dist/tiny.cjs"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"./psl.bin": "./dist/psl.bin"
|
|
43
46
|
},
|
|
47
|
+
"sideEffects": false,
|
|
44
48
|
"files": [
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"*.d.ts",
|
|
48
|
-
"*.d.cts",
|
|
49
|
-
"*.wasm"
|
|
49
|
+
"dist",
|
|
50
|
+
"README.md"
|
|
50
51
|
],
|
|
51
52
|
"publishConfig": {
|
|
52
53
|
"access": "public"
|
|
53
54
|
},
|
|
54
55
|
"engines": {
|
|
55
56
|
"node": ">=18"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"gen:data": "node scripts/gen-data.mjs",
|
|
60
|
+
"build": "npm run gen:data && tsup && node -e \"const fs=require('fs');fs.copyFileSync('src/psl-data.cjs','dist/psl-data.cjs');fs.copyFileSync('../src/psl.bin','dist/psl.bin');fs.copyFileSync('../README.md','README.md')\"",
|
|
61
|
+
"test": "npm run gen:data && vitest run",
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"prepublishOnly": "npm run build"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/node": "^22",
|
|
67
|
+
"tsup": "^8",
|
|
68
|
+
"typescript": "^5.6",
|
|
69
|
+
"vitest": "^2"
|
|
56
70
|
}
|
|
57
71
|
}
|
package/browser.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// The ".js" specifier is the ESM convention for type re-exports: under
|
|
2
|
-
// node16/nodenext resolution it resolves to the sibling index.d.ts. Writing
|
|
3
|
-
// "./index.d.ts" here would be a TypeScript error (TS2846 / TS5097 — importing
|
|
4
|
-
// a declaration-file extension is not allowed without allowImportingTsExtensions).
|
|
5
|
-
export { DomainInfo, lookup, registrableDomain, isKnownSuffix } from "./index.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Initialise the wasm module. Must be awaited before calling any other
|
|
9
|
-
* function from this package.
|
|
10
|
-
*
|
|
11
|
-
* Without arguments the `.wasm` binary is fetched from a sibling URL
|
|
12
|
-
* (works with most bundlers). You may also pass a `URL`, `Response`,
|
|
13
|
-
* `BufferSource`, or `WebAssembly.Module`.
|
|
14
|
-
*/
|
|
15
|
-
export function init(
|
|
16
|
-
input?: BufferSource | WebAssembly.Module | URL | Response | Promise<Response>,
|
|
17
|
-
): Promise<void>;
|
package/browser.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Browser entry — async init() must be called before other functions.
|
|
2
|
-
import _init, {
|
|
3
|
-
lookup as _lookup,
|
|
4
|
-
registrableDomain,
|
|
5
|
-
isKnownSuffix,
|
|
6
|
-
} from "./structured_public_domains.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Initialise the wasm module. Must be called (and awaited) before
|
|
10
|
-
* `lookup`, `registrableDomain`, or `isKnownSuffix`.
|
|
11
|
-
*
|
|
12
|
-
* Without arguments the wasm binary is fetched from a sibling URL
|
|
13
|
-
* (works with most bundlers). You may also pass a `URL`, `Response`,
|
|
14
|
-
* `BufferSource`, or `WebAssembly.Module`.
|
|
15
|
-
*/
|
|
16
|
-
export async function init(input) {
|
|
17
|
-
// Forward as the current single-object form; `undefined` keeps the default
|
|
18
|
-
// (fetch the sibling .wasm). Passing raw bytes/URL positionally is deprecated
|
|
19
|
-
// by wasm-bindgen, so wrap any caller-provided input.
|
|
20
|
-
await _init(input === undefined ? undefined : { module_or_path: input });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Look up a domain in the Public Suffix List.
|
|
25
|
-
*
|
|
26
|
-
* Returns a plain object with `suffix`, `registrableDomain`, and `known`
|
|
27
|
-
* properties, or `undefined` for invalid input.
|
|
28
|
-
*
|
|
29
|
-
* @param {string} domain
|
|
30
|
-
* @returns {{ suffix: string, registrableDomain: string | undefined, known: boolean } | undefined}
|
|
31
|
-
*/
|
|
32
|
-
export function lookup(domain) {
|
|
33
|
-
const info = _lookup(domain);
|
|
34
|
-
if (info == null) return undefined;
|
|
35
|
-
const result = {
|
|
36
|
-
suffix: info.suffix,
|
|
37
|
-
registrableDomain: info.registrableDomain,
|
|
38
|
-
known: info.known,
|
|
39
|
-
};
|
|
40
|
-
info.free();
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export { registrableDomain, isKnownSuffix };
|
package/index.d.cts
DELETED
package/index.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/** Result of a PSL lookup. */
|
|
2
|
-
export interface DomainInfo {
|
|
3
|
-
/** The public suffix (e.g. `"co.uk"`, `"com"`, `"github.io"`). */
|
|
4
|
-
readonly suffix: string;
|
|
5
|
-
/** The registrable domain (eTLD+1), or `undefined` if the input is itself a suffix. */
|
|
6
|
-
readonly registrableDomain: string | undefined;
|
|
7
|
-
/** Whether the suffix matched an explicit PSL rule (vs the `*` fallback). */
|
|
8
|
-
readonly known: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Look up a domain in the Public Suffix List.
|
|
13
|
-
*
|
|
14
|
-
* Returns `undefined` for empty or invalid input.
|
|
15
|
-
*/
|
|
16
|
-
export function lookup(domain: string): DomainInfo | undefined;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Extract the registrable domain (eTLD+1).
|
|
20
|
-
*
|
|
21
|
-
* Returns `undefined` if the domain is itself a public suffix.
|
|
22
|
-
*/
|
|
23
|
-
export function registrableDomain(domain: string): string | undefined;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Check if a domain's suffix is a known entry in the PSL.
|
|
27
|
-
*/
|
|
28
|
-
export function isKnownSuffix(domain: string): boolean;
|
package/node.cjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// CommonJS entry — the nodejs-target glue loads the wasm synchronously at
|
|
2
|
-
// require() time, so every function is usable immediately with no init() call.
|
|
3
|
-
const {
|
|
4
|
-
lookup: _lookup,
|
|
5
|
-
registrableDomain,
|
|
6
|
-
isKnownSuffix,
|
|
7
|
-
} = require("./structured_public_domains_node.cjs");
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Look up a domain in the Public Suffix List.
|
|
11
|
-
*
|
|
12
|
-
* Returns a plain object with `suffix`, `registrableDomain`, and `known`
|
|
13
|
-
* properties, or `undefined` for invalid input.
|
|
14
|
-
*
|
|
15
|
-
* @param {string} domain
|
|
16
|
-
* @returns {{ suffix: string, registrableDomain: string | undefined, known: boolean } | undefined}
|
|
17
|
-
*/
|
|
18
|
-
function lookup(domain) {
|
|
19
|
-
const info = _lookup(domain);
|
|
20
|
-
if (info == null) return undefined;
|
|
21
|
-
const result = {
|
|
22
|
-
suffix: info.suffix,
|
|
23
|
-
registrableDomain: info.registrableDomain,
|
|
24
|
-
known: info.known,
|
|
25
|
-
};
|
|
26
|
-
info.free();
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = { lookup, registrableDomain, isKnownSuffix };
|
package/node.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// ESM Node entry — reads the wasm file synchronously and initialises it during
|
|
2
|
-
// module evaluation (top-level await), so no init() call is needed. CommonJS
|
|
3
|
-
// consumers use ./node.cjs instead (see package.json "exports").
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
5
|
-
import init, {
|
|
6
|
-
lookup as _lookup,
|
|
7
|
-
registrableDomain,
|
|
8
|
-
isKnownSuffix,
|
|
9
|
-
} from "./structured_public_domains.js";
|
|
10
|
-
|
|
11
|
-
const wasmPath = new URL("./structured_public_domains_bg.wasm", import.meta.url);
|
|
12
|
-
await init({ module_or_path: readFileSync(wasmPath) });
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Look up a domain in the Public Suffix List.
|
|
16
|
-
*
|
|
17
|
-
* Returns a plain object with `suffix`, `registrableDomain`, and `known`
|
|
18
|
-
* properties, or `undefined` for invalid input.
|
|
19
|
-
*
|
|
20
|
-
* @param {string} domain
|
|
21
|
-
* @returns {{ suffix: string, registrableDomain: string | undefined, known: boolean } | undefined}
|
|
22
|
-
*/
|
|
23
|
-
export function lookup(domain) {
|
|
24
|
-
const info = _lookup(domain);
|
|
25
|
-
if (info == null) return undefined;
|
|
26
|
-
const result = {
|
|
27
|
-
suffix: info.suffix,
|
|
28
|
-
registrableDomain: info.registrableDomain,
|
|
29
|
-
known: info.known,
|
|
30
|
-
};
|
|
31
|
-
info.free();
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { registrableDomain, isKnownSuffix };
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Result of a PSL lookup, returned as an opaque JS object.
|
|
6
|
-
*
|
|
7
|
-
* JavaScript consumers receive property accessors; the JS wrapper layer
|
|
8
|
-
* copies these into a plain object and calls the generated JS `.free()`
|
|
9
|
-
* method so callers never deal with manual memory management.
|
|
10
|
-
*/
|
|
11
|
-
export class DomainInfo {
|
|
12
|
-
private constructor();
|
|
13
|
-
free(): void;
|
|
14
|
-
[Symbol.dispose](): void;
|
|
15
|
-
/**
|
|
16
|
-
* Whether the suffix matched an explicit PSL rule (vs the `*` fallback).
|
|
17
|
-
*/
|
|
18
|
-
readonly known: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* The registrable domain (eTLD+1), or `undefined` if the input is a
|
|
21
|
-
* bare suffix.
|
|
22
|
-
*/
|
|
23
|
-
readonly registrableDomain: string | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* The public suffix (e.g. `"co.uk"`).
|
|
26
|
-
*/
|
|
27
|
-
readonly suffix: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Check if a domain's suffix is a known entry in the PSL.
|
|
32
|
-
*/
|
|
33
|
-
export function isKnownSuffix(domain: string): boolean;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Look up a domain in the Public Suffix List.
|
|
37
|
-
*
|
|
38
|
-
* Returns `undefined` for empty or invalid input.
|
|
39
|
-
*/
|
|
40
|
-
export function lookup(domain: string): DomainInfo | undefined;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Extract the registrable domain (eTLD+1).
|
|
44
|
-
*
|
|
45
|
-
* Returns `undefined` if the domain is itself a public suffix.
|
|
46
|
-
*/
|
|
47
|
-
export function registrableDomain(domain: string): string | undefined;
|
|
48
|
-
|
|
49
|
-
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
50
|
-
|
|
51
|
-
export interface InitOutput {
|
|
52
|
-
readonly memory: WebAssembly.Memory;
|
|
53
|
-
readonly __wbg_domaininfo_free: (a: number, b: number) => void;
|
|
54
|
-
readonly domaininfo_known: (a: number) => number;
|
|
55
|
-
readonly domaininfo_registrableDomain: (a: number) => [number, number];
|
|
56
|
-
readonly domaininfo_suffix: (a: number) => [number, number];
|
|
57
|
-
readonly isKnownSuffix: (a: number, b: number) => number;
|
|
58
|
-
readonly lookup: (a: number, b: number) => number;
|
|
59
|
-
readonly registrableDomain: (a: number, b: number) => [number, number];
|
|
60
|
-
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
61
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
62
|
-
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
63
|
-
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
64
|
-
readonly __wbindgen_start: () => void;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
71
|
-
* a precompiled `WebAssembly.Module`.
|
|
72
|
-
*
|
|
73
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
74
|
-
*
|
|
75
|
-
* @returns {InitOutput}
|
|
76
|
-
*/
|
|
77
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
81
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
82
|
-
*
|
|
83
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
84
|
-
*
|
|
85
|
-
* @returns {Promise<InitOutput>}
|
|
86
|
-
*/
|
|
87
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|