6397bbffd359c0b1daa3128a5d11f23722bba280f1f3a9bb9c22c3cf31ca7875f662174cc6e79d34c84a7b519821281298b50fc8a15cfb0ccbf24e7d9c861f 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // TypeScript Version: 2.4
  2. /**
  3. * Result returned when a given domain name was not parsable (not exported)
  4. */
  5. export type ErrorResult<T extends keyof errorCodes> = {
  6. input: string;
  7. error: {
  8. code: T;
  9. message: errorCodes[T];
  10. };
  11. }
  12. /**
  13. * Error codes and descriptions for domain name parsing errors
  14. */
  15. export const enum errorCodes {
  16. DOMAIN_TOO_SHORT = 'Domain name too short',
  17. DOMAIN_TOO_LONG = 'Domain name too long. It should be no more than 255 chars.',
  18. LABEL_STARTS_WITH_DASH = 'Domain name label can not start with a dash.',
  19. LABEL_ENDS_WITH_DASH = 'Domain name label can not end with a dash.',
  20. LABEL_TOO_LONG = 'Domain name label should be at most 63 chars long.',
  21. LABEL_TOO_SHORT = 'Domain name label should be at least 1 character long.',
  22. LABEL_INVALID_CHARS = 'Domain name label can only contain alphanumeric characters or dashes.'
  23. }
  24. // Export the browser global variable name additionally to the CJS/AMD exports below
  25. export as namespace psl;
  26. export type ParsedDomain = {
  27. input: string;
  28. tld: string | null;
  29. sld: string | null;
  30. domain: string | null;
  31. subdomain: string | null;
  32. listed: boolean;
  33. }
  34. /**
  35. * Parse a domain name and return its components
  36. */
  37. export function parse(input: string): ParsedDomain | ErrorResult<keyof errorCodes>;
  38. /**
  39. * Get the base domain for full domain name
  40. */
  41. export function get(domain: string): string | null;
  42. /**
  43. * Check whether the given domain belongs to a known public suffix
  44. */
  45. export function isValid(domain: string): boolean;