@structured-world/structured-public-domains 0.0.6
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/browser.d.ts +17 -0
- package/browser.js +44 -0
- package/index.d.cts +3 -0
- package/index.d.ts +28 -0
- package/node.cjs +30 -0
- package/node.js +35 -0
- package/package.json +57 -0
- package/structured_public_domains.d.ts +87 -0
- package/structured_public_domains.js +309 -0
- package/structured_public_domains_bg.wasm +0 -0
- package/structured_public_domains_node.cjs +219 -0
- package/structured_public_domains_node.d.cts +47 -0
package/browser.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
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
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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 };
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@structured-world/structured-public-domains",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "Compact Public Suffix List (PSL). ~108KB binary trie, ~2.4M lookups/sec, checked daily against publicsuffix.org.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/structured-world/structured-public-domains"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"psl",
|
|
12
|
+
"public-suffix",
|
|
13
|
+
"domain",
|
|
14
|
+
"tld",
|
|
15
|
+
"validation",
|
|
16
|
+
"wasm",
|
|
17
|
+
"webassembly"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./node.cjs",
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"node": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./index.d.ts",
|
|
27
|
+
"default": "./node.js"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./index.d.cts",
|
|
31
|
+
"default": "./node.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"default": {
|
|
35
|
+
"types": "./browser.d.ts",
|
|
36
|
+
"default": "./browser.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./browser": {
|
|
40
|
+
"types": "./browser.d.ts",
|
|
41
|
+
"default": "./browser.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"*.js",
|
|
46
|
+
"*.cjs",
|
|
47
|
+
"*.d.ts",
|
|
48
|
+
"*.d.cts",
|
|
49
|
+
"*.wasm"
|
|
50
|
+
],
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=18"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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>;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/* @ts-self-types="./structured_public_domains.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result of a PSL lookup, returned as an opaque JS object.
|
|
5
|
+
*
|
|
6
|
+
* JavaScript consumers receive property accessors; the JS wrapper layer
|
|
7
|
+
* copies these into a plain object and calls the generated JS `.free()`
|
|
8
|
+
* method so callers never deal with manual memory management.
|
|
9
|
+
*/
|
|
10
|
+
export class DomainInfo {
|
|
11
|
+
static __wrap(ptr) {
|
|
12
|
+
ptr = ptr >>> 0;
|
|
13
|
+
const obj = Object.create(DomainInfo.prototype);
|
|
14
|
+
obj.__wbg_ptr = ptr;
|
|
15
|
+
DomainInfoFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
16
|
+
return obj;
|
|
17
|
+
}
|
|
18
|
+
__destroy_into_raw() {
|
|
19
|
+
const ptr = this.__wbg_ptr;
|
|
20
|
+
this.__wbg_ptr = 0;
|
|
21
|
+
DomainInfoFinalization.unregister(this);
|
|
22
|
+
return ptr;
|
|
23
|
+
}
|
|
24
|
+
free() {
|
|
25
|
+
const ptr = this.__destroy_into_raw();
|
|
26
|
+
wasm.__wbg_domaininfo_free(ptr, 0);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether the suffix matched an explicit PSL rule (vs the `*` fallback).
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
get known() {
|
|
33
|
+
const ret = wasm.domaininfo_known(this.__wbg_ptr);
|
|
34
|
+
return ret !== 0;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The registrable domain (eTLD+1), or `undefined` if the input is a
|
|
38
|
+
* bare suffix.
|
|
39
|
+
* @returns {string | undefined}
|
|
40
|
+
*/
|
|
41
|
+
get registrableDomain() {
|
|
42
|
+
const ret = wasm.domaininfo_registrableDomain(this.__wbg_ptr);
|
|
43
|
+
let v1;
|
|
44
|
+
if (ret[0] !== 0) {
|
|
45
|
+
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
46
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
47
|
+
}
|
|
48
|
+
return v1;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The public suffix (e.g. `"co.uk"`).
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
get suffix() {
|
|
55
|
+
let deferred1_0;
|
|
56
|
+
let deferred1_1;
|
|
57
|
+
try {
|
|
58
|
+
const ret = wasm.domaininfo_suffix(this.__wbg_ptr);
|
|
59
|
+
deferred1_0 = ret[0];
|
|
60
|
+
deferred1_1 = ret[1];
|
|
61
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
62
|
+
} finally {
|
|
63
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (Symbol.dispose) DomainInfo.prototype[Symbol.dispose] = DomainInfo.prototype.free;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Check if a domain's suffix is a known entry in the PSL.
|
|
71
|
+
* @param {string} domain
|
|
72
|
+
* @returns {boolean}
|
|
73
|
+
*/
|
|
74
|
+
export function isKnownSuffix(domain) {
|
|
75
|
+
const ptr0 = passStringToWasm0(domain, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
76
|
+
const len0 = WASM_VECTOR_LEN;
|
|
77
|
+
const ret = wasm.isKnownSuffix(ptr0, len0);
|
|
78
|
+
return ret !== 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Look up a domain in the Public Suffix List.
|
|
83
|
+
*
|
|
84
|
+
* Returns `undefined` for empty or invalid input.
|
|
85
|
+
* @param {string} domain
|
|
86
|
+
* @returns {DomainInfo | undefined}
|
|
87
|
+
*/
|
|
88
|
+
export function lookup(domain) {
|
|
89
|
+
const ptr0 = passStringToWasm0(domain, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
90
|
+
const len0 = WASM_VECTOR_LEN;
|
|
91
|
+
const ret = wasm.lookup(ptr0, len0);
|
|
92
|
+
return ret === 0 ? undefined : DomainInfo.__wrap(ret);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Extract the registrable domain (eTLD+1).
|
|
97
|
+
*
|
|
98
|
+
* Returns `undefined` if the domain is itself a public suffix.
|
|
99
|
+
* @param {string} domain
|
|
100
|
+
* @returns {string | undefined}
|
|
101
|
+
*/
|
|
102
|
+
export function registrableDomain(domain) {
|
|
103
|
+
const ptr0 = passStringToWasm0(domain, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
104
|
+
const len0 = WASM_VECTOR_LEN;
|
|
105
|
+
const ret = wasm.registrableDomain(ptr0, len0);
|
|
106
|
+
let v2;
|
|
107
|
+
if (ret[0] !== 0) {
|
|
108
|
+
v2 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
109
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
110
|
+
}
|
|
111
|
+
return v2;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function __wbg_get_imports() {
|
|
115
|
+
const import0 = {
|
|
116
|
+
__proto__: null,
|
|
117
|
+
__wbg___wbindgen_throw_81fc77679af83bc6: function(arg0, arg1) {
|
|
118
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
119
|
+
},
|
|
120
|
+
__wbindgen_init_externref_table: function() {
|
|
121
|
+
const table = wasm.__wbindgen_externrefs;
|
|
122
|
+
const offset = table.grow(4);
|
|
123
|
+
table.set(0, undefined);
|
|
124
|
+
table.set(offset + 0, undefined);
|
|
125
|
+
table.set(offset + 1, null);
|
|
126
|
+
table.set(offset + 2, true);
|
|
127
|
+
table.set(offset + 3, false);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
__proto__: null,
|
|
132
|
+
"./structured_public_domains_bg.js": import0,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const DomainInfoFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
137
|
+
? { register: () => {}, unregister: () => {} }
|
|
138
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_domaininfo_free(ptr >>> 0, 1));
|
|
139
|
+
|
|
140
|
+
function getStringFromWasm0(ptr, len) {
|
|
141
|
+
ptr = ptr >>> 0;
|
|
142
|
+
return decodeText(ptr, len);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let cachedUint8ArrayMemory0 = null;
|
|
146
|
+
function getUint8ArrayMemory0() {
|
|
147
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
148
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
149
|
+
}
|
|
150
|
+
return cachedUint8ArrayMemory0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
154
|
+
if (realloc === undefined) {
|
|
155
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
156
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
157
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
158
|
+
WASM_VECTOR_LEN = buf.length;
|
|
159
|
+
return ptr;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let len = arg.length;
|
|
163
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
164
|
+
|
|
165
|
+
const mem = getUint8ArrayMemory0();
|
|
166
|
+
|
|
167
|
+
let offset = 0;
|
|
168
|
+
|
|
169
|
+
for (; offset < len; offset++) {
|
|
170
|
+
const code = arg.charCodeAt(offset);
|
|
171
|
+
if (code > 0x7F) break;
|
|
172
|
+
mem[ptr + offset] = code;
|
|
173
|
+
}
|
|
174
|
+
if (offset !== len) {
|
|
175
|
+
if (offset !== 0) {
|
|
176
|
+
arg = arg.slice(offset);
|
|
177
|
+
}
|
|
178
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
179
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
180
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
181
|
+
|
|
182
|
+
offset += ret.written;
|
|
183
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
WASM_VECTOR_LEN = offset;
|
|
187
|
+
return ptr;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
191
|
+
cachedTextDecoder.decode();
|
|
192
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
193
|
+
let numBytesDecoded = 0;
|
|
194
|
+
function decodeText(ptr, len) {
|
|
195
|
+
numBytesDecoded += len;
|
|
196
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
197
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
198
|
+
cachedTextDecoder.decode();
|
|
199
|
+
numBytesDecoded = len;
|
|
200
|
+
}
|
|
201
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const cachedTextEncoder = new TextEncoder();
|
|
205
|
+
|
|
206
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
207
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
208
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
209
|
+
view.set(buf);
|
|
210
|
+
return {
|
|
211
|
+
read: arg.length,
|
|
212
|
+
written: buf.length
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let WASM_VECTOR_LEN = 0;
|
|
218
|
+
|
|
219
|
+
let wasmModule, wasm;
|
|
220
|
+
function __wbg_finalize_init(instance, module) {
|
|
221
|
+
wasm = instance.exports;
|
|
222
|
+
wasmModule = module;
|
|
223
|
+
cachedUint8ArrayMemory0 = null;
|
|
224
|
+
wasm.__wbindgen_start();
|
|
225
|
+
return wasm;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function __wbg_load(module, imports) {
|
|
229
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
230
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
231
|
+
try {
|
|
232
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
233
|
+
} catch (e) {
|
|
234
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
235
|
+
|
|
236
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
237
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
238
|
+
|
|
239
|
+
} else { throw e; }
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const bytes = await module.arrayBuffer();
|
|
244
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
245
|
+
} else {
|
|
246
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
247
|
+
|
|
248
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
249
|
+
return { instance, module };
|
|
250
|
+
} else {
|
|
251
|
+
return instance;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function expectedResponseType(type) {
|
|
256
|
+
switch (type) {
|
|
257
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function initSync(module) {
|
|
264
|
+
if (wasm !== undefined) return wasm;
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
if (module !== undefined) {
|
|
268
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
269
|
+
({module} = module)
|
|
270
|
+
} else {
|
|
271
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const imports = __wbg_get_imports();
|
|
276
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
277
|
+
module = new WebAssembly.Module(module);
|
|
278
|
+
}
|
|
279
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
280
|
+
return __wbg_finalize_init(instance, module);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function __wbg_init(module_or_path) {
|
|
284
|
+
if (wasm !== undefined) return wasm;
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
if (module_or_path !== undefined) {
|
|
288
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
289
|
+
({module_or_path} = module_or_path)
|
|
290
|
+
} else {
|
|
291
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (module_or_path === undefined) {
|
|
296
|
+
module_or_path = new URL('structured_public_domains_bg.wasm', import.meta.url);
|
|
297
|
+
}
|
|
298
|
+
const imports = __wbg_get_imports();
|
|
299
|
+
|
|
300
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
301
|
+
module_or_path = fetch(module_or_path);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
305
|
+
|
|
306
|
+
return __wbg_finalize_init(instance, module);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/* @ts-self-types="./structured_public_domains.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result of a PSL lookup, returned as an opaque JS object.
|
|
5
|
+
*
|
|
6
|
+
* JavaScript consumers receive property accessors; the JS wrapper layer
|
|
7
|
+
* copies these into a plain object and calls the generated JS `.free()`
|
|
8
|
+
* method so callers never deal with manual memory management.
|
|
9
|
+
*/
|
|
10
|
+
class DomainInfo {
|
|
11
|
+
static __wrap(ptr) {
|
|
12
|
+
ptr = ptr >>> 0;
|
|
13
|
+
const obj = Object.create(DomainInfo.prototype);
|
|
14
|
+
obj.__wbg_ptr = ptr;
|
|
15
|
+
DomainInfoFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
16
|
+
return obj;
|
|
17
|
+
}
|
|
18
|
+
__destroy_into_raw() {
|
|
19
|
+
const ptr = this.__wbg_ptr;
|
|
20
|
+
this.__wbg_ptr = 0;
|
|
21
|
+
DomainInfoFinalization.unregister(this);
|
|
22
|
+
return ptr;
|
|
23
|
+
}
|
|
24
|
+
free() {
|
|
25
|
+
const ptr = this.__destroy_into_raw();
|
|
26
|
+
wasm.__wbg_domaininfo_free(ptr, 0);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether the suffix matched an explicit PSL rule (vs the `*` fallback).
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
get known() {
|
|
33
|
+
const ret = wasm.domaininfo_known(this.__wbg_ptr);
|
|
34
|
+
return ret !== 0;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The registrable domain (eTLD+1), or `undefined` if the input is a
|
|
38
|
+
* bare suffix.
|
|
39
|
+
* @returns {string | undefined}
|
|
40
|
+
*/
|
|
41
|
+
get registrableDomain() {
|
|
42
|
+
const ret = wasm.domaininfo_registrableDomain(this.__wbg_ptr);
|
|
43
|
+
let v1;
|
|
44
|
+
if (ret[0] !== 0) {
|
|
45
|
+
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
46
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
47
|
+
}
|
|
48
|
+
return v1;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The public suffix (e.g. `"co.uk"`).
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
get suffix() {
|
|
55
|
+
let deferred1_0;
|
|
56
|
+
let deferred1_1;
|
|
57
|
+
try {
|
|
58
|
+
const ret = wasm.domaininfo_suffix(this.__wbg_ptr);
|
|
59
|
+
deferred1_0 = ret[0];
|
|
60
|
+
deferred1_1 = ret[1];
|
|
61
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
62
|
+
} finally {
|
|
63
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (Symbol.dispose) DomainInfo.prototype[Symbol.dispose] = DomainInfo.prototype.free;
|
|
68
|
+
exports.DomainInfo = DomainInfo;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Check if a domain's suffix is a known entry in the PSL.
|
|
72
|
+
* @param {string} domain
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
*/
|
|
75
|
+
function isKnownSuffix(domain) {
|
|
76
|
+
const ptr0 = passStringToWasm0(domain, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
77
|
+
const len0 = WASM_VECTOR_LEN;
|
|
78
|
+
const ret = wasm.isKnownSuffix(ptr0, len0);
|
|
79
|
+
return ret !== 0;
|
|
80
|
+
}
|
|
81
|
+
exports.isKnownSuffix = isKnownSuffix;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Look up a domain in the Public Suffix List.
|
|
85
|
+
*
|
|
86
|
+
* Returns `undefined` for empty or invalid input.
|
|
87
|
+
* @param {string} domain
|
|
88
|
+
* @returns {DomainInfo | undefined}
|
|
89
|
+
*/
|
|
90
|
+
function lookup(domain) {
|
|
91
|
+
const ptr0 = passStringToWasm0(domain, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
92
|
+
const len0 = WASM_VECTOR_LEN;
|
|
93
|
+
const ret = wasm.lookup(ptr0, len0);
|
|
94
|
+
return ret === 0 ? undefined : DomainInfo.__wrap(ret);
|
|
95
|
+
}
|
|
96
|
+
exports.lookup = lookup;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Extract the registrable domain (eTLD+1).
|
|
100
|
+
*
|
|
101
|
+
* Returns `undefined` if the domain is itself a public suffix.
|
|
102
|
+
* @param {string} domain
|
|
103
|
+
* @returns {string | undefined}
|
|
104
|
+
*/
|
|
105
|
+
function registrableDomain(domain) {
|
|
106
|
+
const ptr0 = passStringToWasm0(domain, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
107
|
+
const len0 = WASM_VECTOR_LEN;
|
|
108
|
+
const ret = wasm.registrableDomain(ptr0, len0);
|
|
109
|
+
let v2;
|
|
110
|
+
if (ret[0] !== 0) {
|
|
111
|
+
v2 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
112
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
113
|
+
}
|
|
114
|
+
return v2;
|
|
115
|
+
}
|
|
116
|
+
exports.registrableDomain = registrableDomain;
|
|
117
|
+
|
|
118
|
+
function __wbg_get_imports() {
|
|
119
|
+
const import0 = {
|
|
120
|
+
__proto__: null,
|
|
121
|
+
__wbg___wbindgen_throw_81fc77679af83bc6: function(arg0, arg1) {
|
|
122
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
123
|
+
},
|
|
124
|
+
__wbindgen_init_externref_table: function() {
|
|
125
|
+
const table = wasm.__wbindgen_externrefs;
|
|
126
|
+
const offset = table.grow(4);
|
|
127
|
+
table.set(0, undefined);
|
|
128
|
+
table.set(offset + 0, undefined);
|
|
129
|
+
table.set(offset + 1, null);
|
|
130
|
+
table.set(offset + 2, true);
|
|
131
|
+
table.set(offset + 3, false);
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
__proto__: null,
|
|
136
|
+
"./structured_public_domains_bg.js": import0,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const DomainInfoFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
141
|
+
? { register: () => {}, unregister: () => {} }
|
|
142
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_domaininfo_free(ptr >>> 0, 1));
|
|
143
|
+
|
|
144
|
+
function getStringFromWasm0(ptr, len) {
|
|
145
|
+
ptr = ptr >>> 0;
|
|
146
|
+
return decodeText(ptr, len);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let cachedUint8ArrayMemory0 = null;
|
|
150
|
+
function getUint8ArrayMemory0() {
|
|
151
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
152
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
153
|
+
}
|
|
154
|
+
return cachedUint8ArrayMemory0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
158
|
+
if (realloc === undefined) {
|
|
159
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
160
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
161
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
162
|
+
WASM_VECTOR_LEN = buf.length;
|
|
163
|
+
return ptr;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let len = arg.length;
|
|
167
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
168
|
+
|
|
169
|
+
const mem = getUint8ArrayMemory0();
|
|
170
|
+
|
|
171
|
+
let offset = 0;
|
|
172
|
+
|
|
173
|
+
for (; offset < len; offset++) {
|
|
174
|
+
const code = arg.charCodeAt(offset);
|
|
175
|
+
if (code > 0x7F) break;
|
|
176
|
+
mem[ptr + offset] = code;
|
|
177
|
+
}
|
|
178
|
+
if (offset !== len) {
|
|
179
|
+
if (offset !== 0) {
|
|
180
|
+
arg = arg.slice(offset);
|
|
181
|
+
}
|
|
182
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
183
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
184
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
185
|
+
|
|
186
|
+
offset += ret.written;
|
|
187
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
WASM_VECTOR_LEN = offset;
|
|
191
|
+
return ptr;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
195
|
+
cachedTextDecoder.decode();
|
|
196
|
+
function decodeText(ptr, len) {
|
|
197
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const cachedTextEncoder = new TextEncoder();
|
|
201
|
+
|
|
202
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
203
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
204
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
205
|
+
view.set(buf);
|
|
206
|
+
return {
|
|
207
|
+
read: arg.length,
|
|
208
|
+
written: buf.length
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let WASM_VECTOR_LEN = 0;
|
|
214
|
+
|
|
215
|
+
const wasmPath = `${__dirname}/structured_public_domains_bg.wasm`;
|
|
216
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
217
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
218
|
+
let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
|
|
219
|
+
wasm.__wbindgen_start();
|
|
@@ -0,0 +1,47 @@
|
|
|
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;
|