Expose DOM node type guards through Cheerio
Cheerio exports DOM node types such as AnyNode and Element, but not the matching runtime type guards.
When inspecting nodes from .contents(), consumers currently have to import ElementType or guards directly from domelementtype / domhandler. That couples application code to Cheerio's internal DOM versions. For example, Cheerio 1.2 uses domelementtype 2, while installing version 3 gives TypeScript two distinct enum types and type-aware lint rejects comparisons between them.
Would you be open to re-exporting the existing domhandler guards from cheerio/utils (or another public entry point)?
import { isText } from "cheerio/utils";
$.root().contents().each((_index, node) => {
if (isText(node)) console.log(node.data);
});Useful exports would be isText, isTag, isComment, isDirective, isDocument, isCDATA, and hasChildren.
This would keep the guards aligned with Cheerio's node types and remove the need for consumers to depend on the DOM stack directly.
I'm happy to contribute the implementation, tests, and docs if this API direction makes sense.
Source: cheeriojs/cheerio