def truncate(
    string: str, length: int, align: str = "right", ellipsis: str = "…"
) -> str:
    """
    Truncates an input string to a target length. The optional align argument
    indicates what part of the string should be truncated:
    'left' (the beginning), 'center', or 'right' (the end).
    By default, the 'right' end of the string is truncated.
    The optional ellipsis argument indicates the string to use to indicate
    truncated content; by default the ellipsis character … (\u2026) is used.
    """
    string = str(string)
    nchars = int(length) - len(ellipsis)
    if nchars <= 0:
        return ellipsis
    elif align == "left":
        return ellipsis + string[-nchars:]
    elif align == "center":
        return string[: nchars - nchars // 2] + ellipsis + string[-(nchars // 2) :]
    else:
        return string[:nchars] + ellipsis