import re


def normalize(text: str) -> str:
    """
    Replace all whitespaces in the text with a single space.

    For example "  foo   bar " is converted to "foo bar".
    """
    return re.sub(r"\s+", " ", text).strip()