# `Sqids`
[🔗](https://github.com/sqids/sqids-elixir/blob/0.2.2/lib/sqids.ex#L1)

Sqids API

> ℹ️ Check out the [docs entry page](readme.html) on how to make
> `Sqids` easier to use by not passing the context on every encode/decode
> call, through either:
> * creation of context at compile time under a module attribute,
> * or the `use Sqids` macro to generate functions that retrieve context transparently.

# `enumerable`
*since 0.1.0* 

```elixir
@type enumerable(t) :: Enumerable.t(t)
```

Wrapper type for Elixir 1.13 or older

# `opts`
*since 0.1.0* 

```elixir
@type opts() :: [
  alphabet: String.t(),
  min_length: non_neg_integer(),
  blocklist: enumerable(String.t())
]
```

Opts for `new/1`

# `t`
*since 0.1.0* 

```elixir
@opaque t()
```

Context for Sqids

# `child_spec`
*since 0.1.0* 

```elixir
@callback child_spec() :: Supervisor.child_spec()
```

Returns Supervisor child spec for callback module.

# `decode!`
*since 0.1.0* 

```elixir
@spec decode!(sqids, id) :: numbers
when sqids: t(), id: String.t(), numbers: [non_neg_integer()]
```

Decodes an `id` into zero or more `numbers` according to `sqids`'s alphabet.

Like in the [reference implementation](https://github.com/sqids/sqids-spec),
the presence of unknown characters within `id` will result in an empty list
being returned.

# `encode`
*since 0.1.0* 

```elixir
@spec encode(sqids, numbers) :: {:ok, id} | {:error, term()}
when sqids: t(), numbers: enumerable(non_neg_integer()), id: String.t()
```

Tries to encode zero or more `numbers` into as an `id`, according to
`sqids`'s alphabet, blocklist, and minimum length. Returns an error
otherwise.

# `encode!`
*since 0.1.0* 

```elixir
@spec encode!(sqids, numbers) :: id
when sqids: t(), numbers: enumerable(non_neg_integer()), id: String.t()
```

Encodes zero or more `numbers` into an `id`, according to `sqids`'s alphabet,
blocklist, and minimum length. Raises in case of error.

# `new`
*since 0.1.0* 

```elixir
@spec new(opts()) :: {:ok, t()} | {:error, term()}
```

Creates a context used for both encoding and decoding.

Can receive a list of zero or more `t:opts/0`:
* `alphabet`: a case and order -sensitive string containing the chars of which generated IDs will be made of;
* `min_length`: the minimum length of your generated IDs (padding added if needed);
* `blocklist`: an enumerable collection of strings which shouldn't appear in generated IDs.

Returns error if any of the `t:opts/0` is invalid.

# `new!`
*since 0.1.1* 

```elixir
@spec new!(opts()) :: t()
```

Like `new/0` and `new/1` but raises in case of error.

---

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