UNPKG

1.52 kBTypeScriptView Raw
1// TypeScript Version: 2.4
2
3/**
4 * Result returned when a given domain name was not parsable (not exported)
5 */
6export type ErrorResult<T extends keyof errorCodes> = {
7 input: string;
8 error: {
9 code: T;
10 message: errorCodes[T];
11 };
12}
13
14/**
15 * Error codes and descriptions for domain name parsing errors
16 */
17export 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// Export the browser global variable name additionally to the CJS/AMD exports below
28export as namespace psl;
29
30export 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 * Parse a domain name and return its components
41 */
42export function parse(input: string): ParsedDomain | ErrorResult<keyof errorCodes>;
43
44/**
45 * Get the base domain for full domain name
46 */
47export function get(domain: string): string | null;
48
49/**
50 * Check whether the given domain belongs to a known public suffix
51 */
52export function isValid(domain: string): boolean;