HAST Tree Truncation Utility

JSON →
library 2.0.0 ·javascript
verified May 27, 2026

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.

total hits 15
actors 7 distinct systems
last hit 4d ago AhrefsBot
MetaBot
4
GPTBot
2
Script
1
ClaudeBot
1
Search engines
1

top countries 🇺🇸 United States · 🇨🇦 Canada · 🇳🇴 Norway · 🇩🇪 Germany · 🇫🇷 France