import re


def clean_whitespace(text: str) -> str:
    """
    Replace all contiguous whitespace with single space character,
    strip leading and trailing whitespace.
    """
    text = str(text or '')
    stripped = text.strip()
    sub = re.sub(r'\s+', ' ', stripped, )
    return sub