"""Canonical postcode sanitisation for the domain layer. The legacy postcode_splitter normalises postcodes inline with ``df["postcode"].str.upper().str.replace(" ", "")``. This module promotes that operation to a pure, reusable function so the same canonical form is applied wherever a postcode crosses a domain boundary -- including :class:`domain.addresses.user_address.UserAddress` construction and future migrations. """ from __future__ import annotations def sanitise_postcode(s: str) -> str: """Return the canonical form of a postcode. The canonical form is uppercase with all whitespace removed. This matches the legacy splitter's ``str.upper().str.replace(" ", "")`` for the overwhelmingly common case of space-separated postcodes (e.g. ``"sw1a 1aa"`` becomes ``"SW1A1AA"``) while also tolerating tabs/newlines that can creep in from CSV ingestion. """ return "".join(s.split()).upper()