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

Functions to introspect the Unicode block property for binaries (Strings) and codepoints.

The primary API is `block/1` which returns the block of a codepoint, or the list of blocks of a string.

The functions `fetch/1`, `get/1` and `count/1` provide introspection of the codepoint ranges belonging to a block. `blocks/0`, `known_blocks/0` and `aliases/0` return the underlying block data.

# `aliases`

Returns a map of aliases for Unicode blocks.

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

### Returns

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

### Examples

    iex> Unicode.Block.aliases() |> Map.get("ascii")
    :basic_latin

# `assigned`

Returns a list of tuples representing the assigned ranges of all Unicode codepoints.

### Returns

* A list of codepoint ranges as 2-tuples.

### Examples

    iex> Unicode.Block.assigned() |> hd()
    {0, 12255}

# `block`

Returns the block 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 block name is returned.

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

### Examples

    iex> Unicode.Block.block(?A)
    :basic_latin

    iex> Unicode.Block.block("abc")
    [:basic_latin]

# `blocks`

Returns the map of Unicode blocks.

### Returns

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

### Examples

    iex> Unicode.Block.blocks() |> Map.get(:basic_latin)
    [{0, 127}]

# `count`

Returns the count of characters in a given block.

Aliases are resolved by this function.

### Arguments

* `block` is any block name or alias, as an atom or string.

### Returns

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

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

### Examples

    iex> Unicode.Block.count(:old_north_arabian)
    32

# `fetch`

Returns the Unicode codepoint ranges for a given block.

Aliases are resolved by this function.

### Arguments

* `block` is any block 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 block is not known.

### Examples

    iex> Unicode.Block.fetch(:basic_latin)
    {:ok, [{0, 127}]}

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

# `get`

Returns the Unicode codepoint ranges for a given block.

Aliases are resolved by this function.

### Arguments

* `block` is any block name or alias, as an atom or string.

### Returns

* A list of codepoint ranges as 2-tuples.

* `nil` if the block is not known.

### Examples

    iex> Unicode.Block.get(:basic_latin)
    [{0, 127}]

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

# `known_blocks`

Returns a list of known Unicode block names.

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

### Returns

* A list of atom block names.

### Examples

    iex> :basic_latin in Unicode.Block.known_blocks()
    true

---

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