Function truncateWithEllipsis

  • Truncate a string if its too long, adding an ellipsis if truncation occurs

    Note

    the ellipsis should be shorter than the maxlength for proper results

    Returns

    the truncated string with length <= maxLength

    Example

    truncateWithEllipsis('hello there', 3) === 'he…'
    

    Example

    truncateWithEllipsis('hello there', 30) === 'hello there'
    

    Example

    truncateWithEllipsis('hello there', 7, '...') === 'hell...'
    

    Parameters

    • string: string

      the string to truncate

    • maxLength: number = 50

      the maximum length of the returned string

    • ellipsis: string = '…'

      the ellipsis to add to the string. Defaults to an ellipsis character

    Returns string

Generated using TypeDoc