This package, `hast-util-to-dom`, serves as a utility for converting a `hast` (HTML Abstract Syntax Tree) into a browser-native DOM tree or a simulated DOM environment like `jsdom`. The current stable version is 4.0.1. The project generally follows Node.js maintenance cycles for compatibility, dropping support for unmaintained Node.js versions with major releases. It has a steady release cadence, with version 4.0.0 released recently to update dependencies and enforce modern JavaScript environments. Key differentiators include its tight integration within the unified ecosystem, providing a direct transformation path for HTML ASTs to DOM nodes. It supports client-side rendering directly into the browser's DOM, and also works in server-side contexts with DOM implementations like `jsdom`. It complements `hast-util-from-dom`, which performs the inverse operation, turning DOM trees into hast. Furthermore, `hast-util-to-dom` is utilized internally by `rehype-dom-stringify` for DOM-based HTML serialization. It is important to note that the library transitioned to being ESM-only since version 3.0.0 and requires Node.js 16 or newer as of version 4.0.0, which are significant compatibility considerations for integrators.
npm install hast-util-to-domVerified import paths — ran on the pinned version, not inferred.
Demonstrates converting a `hast` tree to a DOM tree using `toDom` with `jsdom` for a Node.js environment. It also shows how to use the `afterTransform` option.
Upgrade your Node.js runtime to version 16 or higher, or pin your `hast-util-to-dom` dependency to `<4.0.0`.
Migrate your import statements to use ES Modules (`import ... from 'hast-util-to-dom'`). Configure your project for ESM if necessary (e.g., `"type": "module"` in `package.json`).
Ensure all imports strictly use the public API paths (e.g., `import { toDom } from 'hast-util-to-dom'`).Ensure your input `hast` trees represent valid HTML structures. If you need to handle non-HTML doctypes, you may need to use an older version or a different utility.
Implement robust input sanitization and validation before creating `hast` trees from untrusted data. Use trusted `hast` processing libraries like `rehype-sanitize`.
Change your import statement from `const toDom = require('hast-util-to-dom')` to `import { toDom } from 'hast-util-to-dom'`. Ensure your project is configured for ES Modules.Verify that you are using the correct named import: `import { toDom } from 'hast-util-to-dom'`.No dependency data recorded yet.