PublicSufx (public_sufx v0.5.0)

View Source

Implements the publicsuffix algorithm described at https://publicsuffix.org/list/.

Summary

Functions

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.

Returns true if the supplied domain is a public suffix based on the publicsuffix.org rules, false otherwise.

Functions

prevailing_rule(domain)

@spec prevailing_rule(String.t()) :: 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")
"*"
iex> prevailing_rule("foo.github.io")
"github.io"

public_suffix(domain)

@spec public_suffix(String.t()) :: 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"
iex> public_suffix("foo.github.io")
"github.io"

public_suffix?(domain)

@spec public_suffix?(String.t()) :: boolean()

Returns true if the supplied domain is a public suffix based on the publicsuffix.org rules, false otherwise.

Examples

iex> public_suffix?("foo.bar.com")
false
iex> public_suffix?("com")
true
iex> public_suffix?("foo.github.io")
false
iex> public_suffix?("github.io")
true