codetrix - v1.5.0
    Preparing search index...

    Function truncate

    • Truncates a string to a specified length, adding a suffix if needed.

      Parameters

      • str: string

        The string to truncate.

      • length: number

        The maximum allowed length.

      • suffix: string = '...'

        The suffix to add (default is '...').

      Returns string

      The truncated string.

      truncate('Hello World', 5); // 'Hello...'