@tremendous/help
    Preparing search index...

    Function truncate

    • Truncates a string to a specified length.

      This function takes a string and a maximum length as input and returns a truncated string. If the string is shorter than the specified length, it returns the original string.

      Parameters

      • str: string

        The string to truncate.

      • length: number

        The maximum length of the truncated string.

      Returns string

      The truncated string.

      truncate("Hello, world!", 5); // "Hello..."
      truncate("Hello, world!", 13); // "Hello, world!"
      truncate("Hello, world!", 20); // "Hello, world!"