def truncate(string: str, width: int, ending: str = "...") -> str:
    """Truncate string to be no longer than provided width. When truncated, add
    add `ending` to shortened string as indication of truncation.

    Parameters
    ----------
    string: str
        String to be truncated.
    width: int
        Maximum amount of characters before truncation.
    ending: str, optional
        Indication string of truncation.

    Returns
    -------
    Truncated string.

    """

    if not len(string) > width:
        return string

    length = width - len(ending)
    return string[:length] + ending