dom-serializer
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
domelementtype | 2.3.0 | 2.84 kB | BSD-2-Clause | prod | |
domhandler | 5.0.3 | 12.29 kB | BSD-2-Clause | prod | |
entities | 4.5.0 | 75.55 kB | BSD-2-Clause | prod |
Dom-serializer is an invaluable tool for rendering domhandler DOM nodes, or an array of these nodes, to a string. Similar to the notion of outerHTML
of the passed node(s), dom-serializer assists in effectively converting DOM nodes to a string representation. Whether you're working with Node or an array of Nodes, dom-serializer provides an easy, manageable approach to this task.
Utilizing dom-serializer is straightforward and can be done in just a few lines of code. Firstly, you should import the package into your JavaScript file like so:
import render from "dom-serializer";
For those using require
syntax, the import would look like:
const render = require("dom-serializer").default;
In both instances, render
is a function that takes a DOM node or an array of DOM nodes and yields a string. It can be invoked with the node(s) you wish to serialize and an optional parameters object for manipulating the serialization:
let result = render(node, options);
In the above snippet, node
is the DOM node or an array of DOM nodes to be rendered, and options
is a configuration object altering the serialization behavior.
Documentation for the dom-serializer can be found right on its GitHub page here. The documentation encompasses a detailed API section that explains how to use the render function that the package exports. In addition, it provides an easy-to-read table of different options you can pass to the render function to change the serialization behavior, complete with defaults and examples of usage.