public_suffix v0.5.0 PublicSuffix

Implements the publicsuffix algorithm described at https://publicsuffix.org/list/. Comments throughout this module are direct quotes from https://publicsuffix.org/list/, showing how individual lines of code relate to the specification.

Summary

Functions

Checks whether the provided domain matches an explicit rule in the publicsuffix.org rules

Parses the provided domain and returns the prevailing rule based on the publicsuffix.org rules. If no rules match, the prevailing rule is “*”, unless the provided domain has a leading dot, in which case the input is invalid and the function returns nil

Extracts the public suffix from the provided domain based on the publicsuffix.org rules

Extracts the registrable part of the provided domain. The registrable part is the public suffix plus one additional domain part. For example, given a public suffix of co.uk, example.co.uk would be the registrable domain part. If the domain does not contain a registrable part (for example, if the domain is itself a public suffix), this function will return nil

Types

options :: [{:ignore_private, boolean}]

Functions

matches_explicit_rule?(domain, options \\ [])

Specs

matches_explicit_rule?(String.t | nil, options) :: boolean

Checks whether the provided domain matches an explicit rule in the publicsuffix.org rules.

Examples

iex> matches_explicit_rule?("foo.bar.com")
true
iex> matches_explicit_rule?("com")
true
iex> matches_explicit_rule?("foobar.example")
false

You can use the ignore_private keyword to exclude private (non-ICANN) domains.

prevailing_rule(domain, options \\ [])

Specs

prevailing_rule(String.t, options) :: nil | String.t

Parses the provided domain and returns the prevailing rule based on the publicsuffix.org rules. If no rules match, the prevailing rule is “*”, unless the provided domain has a leading dot, in which case the input is invalid and the function returns nil.

Examples

iex> prevailing_rule("foo.bar.com")
"com"
iex> prevailing_rule("co.uk")
"co.uk"
iex> prevailing_rule("foo.ck")
"*.ck"
iex> prevailing_rule("foobar.example")
"*"

You can use the ignore_private keyword to exclude private (non-ICANN) domains.

iex> prevailing_rule("foo.github.io", ignore_private: false)
"github.io"
iex> prevailing_rule("foo.github.io", ignore_private: true)
"io"
iex> prevailing_rule("foo.github.io")
"github.io"
public_suffix(domain, options \\ [])

Specs

public_suffix(String.t, options) :: nil | String.t

Extracts the public suffix from the provided domain based on the publicsuffix.org rules.

Examples

iex> public_suffix("foo.bar.com")
"com"

You can use the ignore_private keyword to exclude private (non-ICANN) domains.

iex> public_suffix("foo.github.io", ignore_private: false)
"github.io"
iex> public_suffix("foo.github.io", ignore_private: true)
"io"
iex> public_suffix("foo.github.io")
"github.io"
registrable_domain(domain, options \\ [])

Specs

registrable_domain(String.t, options) ::
  nil |
  String.t

Extracts the registrable part of the provided domain. The registrable part is the public suffix plus one additional domain part. For example, given a public suffix of co.uk, example.co.uk would be the registrable domain part. If the domain does not contain a registrable part (for example, if the domain is itself a public suffix), this function will return nil.

Examples

iex> registrable_domain("foo.bar.com")
"bar.com"
iex> registrable_domain("com")
nil

You can use the ignore_private keyword to exclude private (non-ICANN) domains.

iex> registrable_domain("foo.github.io", ignore_private: false)
"foo.github.io"
iex> registrable_domain("foo.github.io", ignore_private: true)
"github.io"
iex> registrable_domain("foo.github.io")
"foo.github.io"