@sensimods/utility-lab
    Preparing search index...

    Function truncate

    • Truncates a string to a specified length and adds an ellipsis. A must-have for UI-focused utility libraries.

      Parameters

      • str: string

        The string to truncate.

      • length: number

        The maximum length of the truncated string (excluding the suffix).

      • suffix: string = "..."

        The string to append to the truncated string (default is "...").

      Returns string

      The truncated string with the suffix if truncation occurred, otherwise returns the original string.

      truncate("This is a long string that needs to be shortened.", 20)
      // "This is a long str..."