UMD Web Utilities Library
    Preparing search index...

    Function truncateText

    • Truncates HTML text content to a specified length while preserving HTML structure. This is an HTML-aware truncation function that walks the DOM tree and preserves element boundaries while truncating text nodes.

      Parameters

      • text: { maxTextSize: number; text: string }

        The HTML string to truncate

      Returns string

      The truncated HTML string with ellipsis appended if text was truncated

      const html = '<p>This is a <strong>long</strong> text that needs truncation</p>';
      const result = truncateText({ text: html, maxTextSize: 20 });
      // result: '<p>This is a <strong>long</strong> te ...</p>'