Tld (TLD v0.3.0) View Source
Top-Level Domain module for BEAM.
Lets you get the current list of TLDs, as well as find the TLD in a domain name.
Link to this section Summary
Functions
Get list of all Top-Level Domains.
If input string contains a domain name, get its TLD.
Simple check if string is a valid TLD.
Link to this section Functions
Get list of all Top-Level Domains.
Examples
iex> list = Tld.get_list()
iex> Enum.member?(list, "NET")
true
iex> Enum.member?(list, "TEST")
false
If input string contains a domain name, get its TLD.
Returns {:ok, "COM"} if found (COM being replaced with the actual TLD found), {:err, :not_found} if TLD was not found in string, and {:err, :invalid_input} if not given a string.
Examples
iex> Tld.get_tld_from_domain_name("contoso.com")
{:ok, "COM"}
iex> Tld.get_tld_from_domain_name("FACE.BORG.TEST")
{:err, :not_found}
iex> Tld.get_tld_from_domain_name("CORRUPT.GOV")
{:ok, "GOV"}
iex> Tld.get_tld_from_domain_name('NOTASTRING.NET')
{:err, :invalid_input}
iex> Tld.get_tld_from_domain_name(42)
{:err, :invalid_input}
iex> Tld.get_tld_from_domain_name(nil)
{:err, :invalid_input}
Simple check if string is a valid TLD.
Returns true if given a valid TLD ("COM", "dk", etc.)
Examples
iex> Tld.is_tld?("COM")
true
iex> Tld.is_tld?("dk")
true
iex> Tld.is_tld?("amazing.ch")
false
iex> Tld.is_tld?(" NET")
false
iex> Tld.is_tld?("ORG ")
false
iex> Tld.is_tld?("")
false
iex> Tld.is_tld?(42)
false
iex> Tld.is_tld?(nil)
false