HAST Tree Truncation Utility
JSON →hast-util-truncate is a focused utility within the unified (unist/hast/mdast) ecosystem, designed to truncate a HAST (HTML Abstract Syntax Tree) to a specified number of characters while meticulously preserving its underlying structure. The package, currently stable at version 2.0.0, follows the syntax-tree's measured release cadence, with major versions often introducing changes related to Node.js environment requirements or shifts in JavaScript module standards. Its key differentiator lies in operating directly on the AST, enabling intelligent truncation that respects HTML semantics and avoids breaking tags, unlike naive string-based approaches. It offers configurable options for the truncation size, the ellipsis character, and a `maxCharacterStrip` mechanism to ensure word breaks occur gracefully, preventing awkward partial words at the truncation point. This makes it ideal for generating accurate excerpts, summaries, or SEO descriptions from rich HTML content for applications like blogs, content management systems, or search result snippets.
Traffic · last 30 days ↑200% vs prev 7d
top countries 🇺🇸 United States · 🇨🇦 Canada · 🇳🇴 Norway · 🇩🇪 Germany · 🇫🇷 France