psl

Types

Represents the parsed components of a domain

Definitions

top_level_domain or TLD is the last part of a domain name before the paths. For example, in https://packages.gleam.run, “run” is the TLD.

second_level_domain or SLD is the part of a domain name before the TLD, separated by a “.”. For example, in https://packages.gleam.run, “gleam” is the SLD.

transit_routing_domain or TRD is the first part of a domain name and may have more than one part. For example, in https://packages.gleam.run, “packages” is the TRD and in https://cool.packages.gleam.run “cool.packages” is the TRD.

We return “subdomain_parts” that splits the TRD on “.”.

pub type DomainParts {
  DomainParts(
    top_level_domain: String,
    second_level_domain: String,
    transit_routing_domain: String,
    subdomain_parts: List(String),
  )
}

Constructors

  • DomainParts(
      top_level_domain: String,
      second_level_domain: String,
      transit_routing_domain: String,
      subdomain_parts: List(String),
    )

Errors that can occur during parsing

pub type ParseError {
  InvalidUri
  NoHost
  InvalidDomain
  UnknownSuffix
}

Constructors

  • InvalidUri
  • NoHost
  • InvalidDomain
  • UnknownSuffix

The suffix list data structure

pub opaque type SuffixList

Values

pub fn add_rule(
  sl: SuffixList,
  rule: String,
  is_public: Bool,
) -> SuffixList

Add a single rule to the suffix list. This is useful if a suffix is not yet in the list provided by publicsuffix.org.

Rules are formatted as follows:

  • Normal domaains do not start with a special character.
  • Exceptions start with a “!”.
  • Wildcards start with a “*”.
pub fn load_suffix_list(
  include_private: Bool,
  path: option.Option(String),
) -> SuffixList

Load the public suffix list from the a data file and choose to include private domains or not. Pass a file path to include your own list or leave path empty to load the one included in the package.

pub fn parse(
  uri_string: String,
  list: SuffixList,
) -> Result(DomainParts, ParseError)

Parse a URI and extract domain parts

let list = load_suffix_list(True, None)
let result1 = parse("https://example.com", list)
let result2 = parse("https://test.co.uk", list)
Search Document