# `Unicode.BidiClass`
[🔗](https://github.com/elixir-unicode/unicode/blob/v2.0.0/lib/unicode/property/bidi_class.ex#L1)

Functions to introspect the Unicode bidirectional (bidi) class property for binaries (Strings) and codepoints.

The primary API is `bidi_class/1` which returns the bidi class of a codepoint, or the list of bidi classes of a string.

The functions `fetch/1`, `get/1` and `count/1` provide introspection of the codepoint ranges belonging to a bidi class. `bidi_classes/0`, `known_bidi_classes/0` and `aliases/0` return the underlying bidi class data.

# `aliases`

Returns a map of aliases for Unicode bidi classes.

An alias is an alternative name for referring to a bidi class. Aliases are resolved by the `fetch/1` and `get/1` functions.

### Returns

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

### Examples

    iex> Unicode.BidiClass.aliases() |> Map.get("arabicletter")
    :al

# `bidi_class`

Returns the bidi class name(s) for 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 bidi class name is returned.

* For a binary, a list of the distinct bidi class names of the codepoints in the binary is returned.

### Examples

    iex> Unicode.BidiClass.bidi_class(?A)
    :l

    iex> Unicode.BidiClass.bidi_class(0x05D0)
    :r

    iex> Unicode.BidiClass.bidi_class(0x0627)
    :al

    iex> Unicode.BidiClass.bidi_class("abc")
    [:l]

# `bidi_classes`

Returns the map of Unicode bidi classes.

### Returns

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

### Examples

    iex> Unicode.BidiClass.bidi_classes() |> Map.get(:lre)
    [{8234, 8234}]

# `count`

Returns the count of characters in a given bidi class.

Aliases are resolved by this function.

### Arguments

* `bidi_class` is any bidi class name or alias, as an atom or string.

### Returns

* A non-negative integer count of the codepoints in the bidi class.

* `:error` if the bidi class is not known.

### Examples

    iex> Unicode.BidiClass.count(:al)
    1478

# `fetch`

Returns the Unicode codepoint ranges for a given bidi class.

Aliases are resolved by this function.

### Arguments

* `bidi_class` is any bidi class name or alias, as an atom or string.

### Returns

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

* `:error` if the bidi class is not known.

### Examples

    iex> Unicode.BidiClass.fetch(:lre)
    {:ok, [{8234, 8234}]}

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

# `get`

Returns the Unicode codepoint ranges for a given bidi class.

Aliases are resolved by this function.

### Arguments

* `bidi_class` is any bidi class name or alias, as an atom or string.

### Returns

* A list of codepoint ranges as 2-tuples.

* `nil` if the bidi class is not known.

### Examples

    iex> Unicode.BidiClass.get(:lre)
    [{8234, 8234}]

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

# `known_bidi_classes`

Returns a list of known Unicode bidi class names.

This function does not return the names of any class aliases.

### Returns

* A list of atom bidi class names.

### Examples

    iex> :l in Unicode.BidiClass.known_bidi_classes()
    true

---

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