# `Planck.Headless.SessionName`
[🔗](https://github.com/alexdesousa/planck/blob/v0.1.0/lib/planck/headless/session_name.ex#L1)

Generates and sanitizes human-readable session names in `<adjective>-<noun>` format.

Names are embedded in SQLite filenames alongside the session id:
`<sessions_dir>/<id>_<name>.db`. Both components are URL-safe and contain
only `[a-z0-9-]` characters, with `_` reserved as the separator.

## Generation

`generate/1` picks a random adjective + noun pair and retries (up to a
configurable limit) if the resulting name already exists on disk.

## Sanitization

`sanitize/1` normalises a user-provided string to the same character class:
lowercase, spaces and underscores become hyphens, and any other character
outside `[a-z0-9-]` is stripped. The result is truncated to 64 characters.
If sanitization produces an empty string, `{:error, :invalid}` is returned.

# `generate`

Generate a unique `<adjective>-<noun>` name not already present in
`sessions_dir`. Retries up to 20 times on collision.

Returns `{:ok, name}` or `{:error, :exhausted}` if all retries collide.

# `sanitize`

```elixir
@spec sanitize(String.t()) :: {:ok, String.t()} | {:error, :invalid}
```

Sanitize a user-provided string to a valid session name.

- Lowercased.
- Spaces and underscores converted to hyphens.
- Characters outside `[a-z0-9-]` stripped.
- Consecutive hyphens collapsed to one.
- Leading and trailing hyphens removed.
- Truncated to 64 characters.

Returns `{:ok, name}` or `{:error, :invalid}` if the result is empty.

---

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