IDUtils.Schemes.URN (id_utils v0.1.0)

Copy Markdown View Source

URN (Uniform Resource Name) scheme.

For the purposes of this library, an URN is considered "valid" if its namespace identifier is registered with the IANA as "formal". Registered "informal" namespace identifiers will not match.

See https://www.rfc-editor.org/info/rfc8141/

Summary

Functions

Checks whether a string is a URN.

Returns all URN NIDs registered as "formal" with IANA.

Normalizes a URN.

Functions

match?(string)

Checks whether a string is a URN.

Examples

iex> IDUtils.Schemes.URN.match?("urn:ietf:rfc:2648")
true

iex> IDUtils.Schemes.URN.match?("urn:nbn:at:AT-UBG:3-13")
true

iex> IDUtils.Schemes.URN.match?("urn:unregistered:foo:bar")
false

iex> IDUtils.Schemes.URN.match?("https://nbn-resolving.org/urn:nbn:at:AT-UBG:3-13")
false

namespaces()

@spec namespaces() :: MapSet.t()

Returns all URN NIDs registered as "formal" with IANA.

The dataset is sourced from the IANA Registry of URN Namespaces and covers all formal namespace identifiers registered as of the release date of this version of IDUtils.

normalize(string)

Normalizes a URN.

Examples

iex> IDUtils.Schemes.URN.normalize("URN:NBN:fi-fe19981001")
{:ok, "urn:nbn:fi-fe19981001"}

iex> IDUtils.Schemes.URN.normalize("example.com/URN:NBN:fi-fe19981001")
{:error, :invalid_identifier}