hast-util-to-string
hast utility to get the plain-text value of a node
This package has a good security score with no known vulnerabilities.
Community Reviews
Simple, well-typed utility that does exactly what you need
The documentation is clear and complete despite being concise. Examples cover the common cases, and the behavior is predictable enough that you rarely need to reference docs after first use. Error handling is straightforward - it won't crash on malformed input, just returns what it can extract. Integration with rehype plugins is seamless since it uses standard hast types.
In daily use, it's one of those utilities you import, use once, and forget about because it just works. Whether you're building markdown processors, content extractors, or SEO tools that need plain text from HTML ASTs, this handles the grunt work reliably. The small API surface means there's nothing to learn beyond the single function call.
Best for: Extracting plain text content from hast/HTML AST nodes in unified/rehype processing pipelines.
Avoid if: You need fine-grained control over text extraction behavior or custom handling of specific HTML elements.
Simple, reliable text extraction with zero learning curve
The documentation is minimal but that's because there's genuinely not much to explain. The README has enough examples to understand the whole API in 30 seconds. Error messages are straightforward when you pass invalid input. It integrates seamlessly with the unified/remark/rehype ecosystem, which is clearly its intended use case.
Debugging is straightforward because the package is pure utility with no hidden state. When something seems wrong, it's usually your hast tree structure, not this package. The TypeScript types are solid and helpful. For such a focused utility, it's hard to imagine how it could be better.
Best for: Extracting plain text from HTML AST nodes in unified/rehype processing pipelines or any hast manipulation workflow.
Avoid if: You need fine-grained control over text extraction behavior or custom handling of specific HTML elements.
Dead simple utility that does one thing perfectly
The learning curve is essentially zero—if you're already working with hast trees, you literally import and call it. The documentation is clear and includes practical examples showing edge cases like handling whitespace. Error messages are straightforward JavaScript errors when you pass invalid input, which makes sense given the simplicity.
What I appreciate most is how it handles the nitty-gritty details correctly: script/style tags are ignored, whitespace is normalized properly, and it recursively processes nested structures without me having to think about it. When debugging AST transformations, this is invaluable for quickly checking what text content you're actually working with. It's one of those packages that becomes invisible in your workflow because it never causes problems.
Best for: Projects using the unified/remark/rehype ecosystem that need simple plain-text extraction from HTML ASTs.
Avoid if: You need complex text extraction with custom formatting rules or aren't already working with hast nodes.
Sign in to write a review
Sign In