1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export type ErrorResult<T extends keyof errorCodes> = {
|
7 | input: string;
|
8 | error: {
|
9 | code: T;
|
10 | message: errorCodes[T];
|
11 | };
|
12 | }
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | export const enum errorCodes {
|
18 | DOMAIN_TOO_SHORT = 'Domain name too short',
|
19 | DOMAIN_TOO_LONG = 'Domain name too long. It should be no more than 255 chars.',
|
20 | LABEL_STARTS_WITH_DASH = 'Domain name label can not start with a dash.',
|
21 | LABEL_ENDS_WITH_DASH = 'Domain name label can not end with a dash.',
|
22 | LABEL_TOO_LONG = 'Domain name label should be at most 63 chars long.',
|
23 | LABEL_TOO_SHORT = 'Domain name label should be at least 1 character long.',
|
24 | LABEL_INVALID_CHARS = 'Domain name label can only contain alphanumeric characters or dashes.'
|
25 | }
|
26 |
|
27 |
|
28 | export as namespace psl;
|
29 |
|
30 | export type ParsedDomain = {
|
31 | input: string;
|
32 | tld: string | null;
|
33 | sld: string | null;
|
34 | domain: string | null;
|
35 | subdomain: string | null;
|
36 | listed: boolean;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export function parse(input: string): ParsedDomain | ErrorResult<keyof errorCodes>;
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | export function get(domain: string): string | null;
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | export function isValid(domain: string): boolean;
|