Domainatrex

Domainatrex is a TLD parsing library for Elixir, using the Public Suffix list.

Build Status Inline docs Coverage Status Deps Status hex.pm version hex.pm downloads License

Read the docs

Installation

Add the following to your mix.exs

defp deps do
[{:domainatrex, "~> 3.0.1"}]

Usage

Domainatrex should be able to handle all valid hostnames, it uses the Public Suffix List and is heavily inspired by the fantastic Domainatrix library for Ruby

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"}}

Configuration

For maximum performance, Domainatrex reads the list of all known top-level domains at compile time. Likewise, by default, the package will attempt to fetch the latest list of TLDs from the web before falling back to a local (potentially out of date) copy. You can configure this behavior in your config.exs as follows:

Here's a complete example of how you might customize this behavior in your confix.exs:

config :domainatrex,
# Explicitly allow compile-time HTTP request to fetch the latest list of TLDs (default)
fetch_latest: true,
# Download the public suffix list from the official source (not necessarily tested with Domainatrex!)
public_suffix_list_url: 'https://publicsuffix.org/list/public_suffix_list.dat',
fallback_local_copy: "priv/my_app_custom_suffix_list.dat"

Changelog

3.0.1

3.0.0

2.4.0

2.3.0

2.2.0

2.1.4

2.1.3

2.1.2

2.1.1

2.1.0

2.0.0

1.0.1