Domainatrex (Domainatrex v3.2.0)

View Source

Domainatrex splits a host name into {subdomain, domain, tld} using the Public Suffix List.

Many domain parsing implementations are incorrect if they assume "the TLD is always the last label". For example, id.au is a public suffix, so in blog.someone.id.au the registrable domain is someone and the TLD is id.au. Domainatrex uses the Public Suffix List (including wildcard and exception rules) to make this split correctly.

Use this library when you need:

  • Deterministic, PSL-correct splitting for analytics, cookie scoping, tenant routing, allow/deny rules, or normalization.
  • Support for "private" suffixes (like s3.amazonaws.com) when enabled via configuration.

Domainatrex expects a host name (e.g. example.co.uk), not a full URL. If you have a URL, extract its host first (for example via Elixir's URI.parse/1).

Summary

Functions

Parses a host name into {subdomain, domain, tld} using the public suffix list.

Returns true when the given string is a public suffix (TLD) in the loaded public suffix list.

Functions

parse(url)

Parses a host name into {subdomain, domain, tld} using the public suffix list.

Returns {:ok, %{domain: domain, subdomain: subdomain, tld: tld}} when the host contains a registrable domain, otherwise returns {:error, reason}.

Domain labels are treated case-insensitively.

Examples

iex> Domainatrex.parse("someone.com")
{:ok, %{domain: "someone", subdomain: "", tld: "com"}}

iex> Domainatrex.parse("blog.someone.id.au")
{:ok, %{domain: "someone", subdomain: "blog", tld: "id.au"}}

iex> Domainatrex.parse("zen.s3.amazonaws.com")
{:ok, %{domain: "zen", subdomain: "", tld: "s3.amazonaws.com"}}

tld?(tld)

Returns true when the given string is a public suffix (TLD) in the loaded public suffix list.

Examples

iex> Domainatrex.tld?("com")
true

iex> Domainatrex.tld?("id.au")
true

iex> Domainatrex.tld?("someone.com")
false