UMD Web Utilities Library
    Preparing search index...

    Function truncate

    • Truncates a string to a specified length and adds an ellipsis if truncated

      Parameters

      • str: string

        The string to truncate

      • maxLength: number

        Maximum length of the string (including ellipsis)

      • ellipsis: string = '...'

        The ellipsis string to append (default: '...')

      Returns string

      The truncated string

      truncate('Hello World', 8); // 'Hello...'
      truncate('Hello World', 20); // 'Hello World'
      truncate('Hello World', 8, '…'); // 'Hello …'