### Add Domainatrex dependency to mix.exs Source: https://hexdocs.pm/domainatrex/index.html Add the Domainatrex dependency to your mix.exs file to install the package. ```elixir defp deps do [ {:domainatrex, "~> 3.2"}, ] ``` -------------------------------- ### parse/1 examples Source: https://hexdocs.pm/domainatrex/Domainatrex.html Shows how to use Domainatrex.parse/1 to split host names into subdomain, domain, and TLD. The function returns {:ok, map} for valid hosts and {:error, reason} otherwise. Domain labels are case-insensitive. ```elixir 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"}} ``` -------------------------------- ### Configure Domainatrex in config.exs Source: https://hexdocs.pm/domainatrex/index.html Complete example of customizing Domainatrex behavior in config.exs. It explicitly enables fetching the latest TLD list, sets a custom fallback file, adds a custom suffix, and includes private domains. ```elixir 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 public_suffix_list_url: ~c"https://publicsuffix.org/list/public_suffix_list.dat", fallback_local_copy: "priv/my_app_custom_suffix_list.dat", # Add custom suffix for com.be custom_suffixes: ["com.be"], # Include private domains (default) include_private: true ``` -------------------------------- ### tld?/1 examples Source: https://hexdocs.pm/domainatrex/Domainatrex.html Shows how to use Domainatrex.tld?/1 to check if a string is a public suffix (TLD) in the loaded list. Returns true for valid public suffixes and false otherwise. ```elixir iex> Domainatrex.tld?("com") true iex> Domainatrex.tld?("id.au") true iex> Domainatrex.tld?("someone.com") false ``` -------------------------------- ### Parse host names and check TLDs with Domainatrex Source: https://hexdocs.pm/domainatrex/index.html Shows how to parse host names and check if a string is a top-level domain using Domainatrex. The parse function returns a map with domain, subdomain, and tld fields. The tld? function returns true only for exact TLD matches. ```elixir 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.tld?("com") true iex> Domainatrex.tld?("someone.com") false ``` -------------------------------- ### Domainatrex Functions Source: https://hexdocs.pm/domainatrex/Domainatrex.html Functions for parsing host names and checking public suffixes. ```APIDOC ## Domainatrex.parse(url) ### Description 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. ### Method Function ### Endpoint `Domainatrex.parse/1` ### Parameters - **url** (string) - Required - The host name to parse (e.g., `example.co.uk`). ### Request Example ```elixir Domainatrex.parse("someone.com") ``` ### Response #### Success Response - **domain** (string) - The registrable domain. - **subdomain** (string) - The subdomain (may be empty). - **tld** (string) - The top-level domain (public suffix). #### Response Example ```elixir {:ok, %{domain: "someone", subdomain: "", tld: "com"}} ``` ### Error Handling Returns `{:error, reason}` when the host does not contain a registrable domain. ``` ```APIDOC ## Domainatrex.tld?(tld) ### Description Returns `true` when the given string is a public suffix (TLD) in the loaded public suffix list. ### Method Function ### Endpoint `Domainatrex.tld?/1` ### Parameters - **tld** (string) - Required - The string to check as a public suffix. ### Request Example ```elixir Domainatrex.tld?("com") ``` ### Response #### Success Response - **boolean** (boolean) - `true` if the string is a public suffix, `false` otherwise. #### Response Example ```elixir true ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.