import re


def sanitize_name(name: str) -> str:
    """
    Mangles *name* to fit within a job or job definition name.

    * Replaces any invalid character with a hyphen ``-``
    * Truncates to 128 characters in length
    """
    return re.sub(r"[^A-Za-z0-9_-]", "-", name)[0:128]