from __future__ import annotations

import re
from typing import Any

_PARTITION_TOKEN_RE = re.compile(r"[^a-z0-9._-]+")

__all__ = ["normalise_token", "partition_slug"]


def normalise_token(value: Any, default: str = "default") -> str:
    token = str(value).strip() if value is not None else ""
    return token or default


def partition_slug(value: Any, default: str = "default") -> str:
    token = normalise_token(value, default=default).lower()
    token = _PARTITION_TOKEN_RE.sub("-", token)
    token = token.strip("-._")
    return token or default
