# `Unicode.LinkTerm`
[🔗](https://github.com/elixir-unicode/unicode/blob/v2.2.0/lib/unicode/property/link_term.ex#L1)

Functions to introspect the `Link_Term` property for binaries (Strings) and codepoints.

`Link_Term` drives the link termination algorithm of [UTS #58](https://www.unicode.org/reports/tr58/), which decides where a URL or email address appearing in flowing text ends. The values are:

* `:include` — the character belongs inside the link.

* `:hard` — the character terminates the link immediately. This is the default, so any codepoint not listed in the data terminates a link.

* `:soft` — the character terminates the link only when what follows is a run of soft characters and then a hard character or the end of the text. This is what lets `See example.com.` drop the sentence-final full stop while `example.com/a.b` keeps its inner one.

* `:open` and `:close` — bracket characters, paired through `Unicode.LinkBracket`. A closing bracket is included when it matches the innermost open bracket and terminates the link otherwise.

The primary API is `link_term/1` which returns the value for a codepoint, or the list of values for a string.

# `aliases`

Returns a map of aliases for `Link_Term` values.

`Link_Term` is defined by UTS #58 rather than the UCD, so it has no entry in
`PropertyValueAliases.txt` and the only aliases are the value names themselves.

### Returns

* A map where the alias string is the key and the value name is the value.

### Examples

    iex> Unicode.LinkTerm.aliases() |> Map.get("soft")
    :soft

# `count`

Returns the count of codepoints with a given `Link_Term` value.

### Arguments

* `link_term` is any `Link_Term` value name, as an atom or string.

### Returns

* A non-negative integer count of the codepoints with that value.

* `:error` if the value is not known.

### Examples

    iex> Unicode.LinkTerm.count(:open)
    65

# `fetch`

Returns the Unicode codepoint ranges for a given `Link_Term` value.

### Arguments

* `link_term` is any `Link_Term` value name, as an atom or string.

### Returns

* `{:ok, range_list}` where `range_list` is a list of codepoint ranges as 2-tuples.

* `:error` if the value is not known.

### Examples

    iex> Unicode.LinkTerm.fetch(:open) |> elem(0)
    :ok

    iex> Unicode.LinkTerm.fetch(:invalid)
    :error

# `get`

Returns the Unicode codepoint ranges for a given `Link_Term` value.

### Arguments

* `link_term` is any `Link_Term` value name, as an atom or string.

### Returns

* A list of codepoint ranges as 2-tuples.

* `nil` if the value is not known.

### Examples

    iex> Unicode.LinkTerm.get(:invalid)
    nil

# `known_link_terms`

Returns a list of known `Link_Term` values.

Note that `:hard` is the default value and is therefore not listed in the data, so it does not appear here even though `link_term/1` returns it.

### Returns

* A list of atom value names.

### Examples

    iex> :include in Unicode.LinkTerm.known_link_terms()
    true

# `link_term`

Returns the `Link_Term` value of the given binary or codepoint.

### Arguments

* `string_or_codepoint` is either a binary (String) or a codepoint in the range `0..0x10FFFF`.

### Returns

* For a codepoint, a single value atom. Codepoints not listed in the data return `:hard`, the
  UTS #58 default.

* For a binary, a list of the distinct values of the codepoints in the binary.

### Examples

    iex> Unicode.LinkTerm.link_term(?a)
    :include

    iex> Unicode.LinkTerm.link_term(?.)
    :soft

    iex> Unicode.LinkTerm.link_term(?\s)
    :hard

    iex> Unicode.LinkTerm.link_term(?\()
    :open

# `link_terms`

Returns the map of `Link_Term` values.

### Returns

* A map where the value name is the key and a list of codepoint ranges as 2-tuples is the value.

### Examples

    iex> :soft in Map.keys(Unicode.LinkTerm.link_terms())
    true

---

*Consult [api-reference.md](api-reference.md) for complete listing*
