Function shortenString

  • Shortens a string by removing characters from the middle and replacing them with an ellipse.

    Parameters

    • value: string

      The string to shorten

    • Optional startCount: number

      The number of characters to keep at the start of the string

    • Optional endCount: number

      The number of characters to keep at the end of the string

    • Optional ellipse: string

      The string to use as the ellipse (default: '...')

    Returns string

    The shortened string

    Example

    shortenString('0x7a7a7229292286592739473748234343434532345', 4, 4) // '0x7a...2345'
    shortenString('0x7a7a7229292286592739473748234343434532345', 4, 4, '***') // '0x7a***2345'
    shortenString('0x7a7a7229292286592739473748234343434532345', 6, 4, '...') // '0x7a7a...2345'