npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dom-serializer

v3.1.1

Published

render domhandler DOM nodes to a string

Readme

dom-serializer Node.js CI

Renders a domhandler DOM node or an array of domhandler DOM nodes to a string.

import render from "dom-serializer";

// OR

const render = require("dom-serializer").default;

API

render

render(node: Node | Node[], options?: Options): string

Renders a DOM node or an array of DOM nodes to a string.

Can be thought of as the equivalent of the outerHTML of the passed node(s).

Parameters:

| Name | Type | Default value | Description | | :-------- | :--------------------------------- | :------------ | :----------------------------- | | node | Node | Node[] | - | Node to be rendered. | | options | DomSerializerOptions | {} | Changes serialization behavior |

Returns: string

Options

encodeEntities

Optional encodeEntities: boolean | "utf8"

Encode characters reserved in HTML or XML in text and attribute values.

If xmlMode is true or the value is not 'utf8', characters outside of the ASCII range will be encoded as well.

Security: Setting this to false disables encoding of <, >, and & in text and attribute values. This is intended for the round-trip case where the DOM was parsed with decodeEntities: false, so markup characters only exist as entity references. If the DOM contains raw markup characters (e.g., from a default-decoded parse, or from programmatic manipulation), they will be emitted literally — do not use this option with untrusted input unless you have validated the DOM yourself.

default decodeEntities


decodeEntities

Optional decodeEntities: boolean

Default for encodeEntities. Named to match the parser option of the same name so a single options object can be threaded through parse and serialize. Despite the name, on the serializer this option controls encoding — setting it to false carries the same security caveat as encodeEntities: false.

default true


emptyAttrs

Optional emptyAttrs: boolean

Print an empty attribute's value.

default xmlMode

example With emptyAttrs: false: <input checked>

example With emptyAttrs: true: <input checked="">


selfClosingTags

Optional selfClosingTags: boolean

Print self-closing tags for tags without contents. If xmlMode is set, this will apply to all tags. Otherwise, only tags that are defined as self-closing in the HTML specification will be printed as such.

default xmlMode

example With selfClosingTags: false: <foo></foo><br></br>

example With xmlMode: true and selfClosingTags: true: <foo/><br/>

example With xmlMode: false and selfClosingTags: true: <foo></foo><br />


xmlMode

Optional xmlMode: boolean | "foreign"

Treat the input as an XML document; enables the emptyAttrs and selfClosingTags options.

If the value is "foreign", it will try to correct mixed-case attribute names.

default false


Ecosystem

| Name | Description | | ------------------------------------------------------------- | ------------------------------------------------------- | | htmlparser2 | Fast & forgiving HTML/XML parser | | domhandler | Handler for htmlparser2 that turns documents into a DOM | | domutils | Utilities for working with domhandler's DOM | | css-select | CSS selector engine, compatible with domhandler's DOM | | cheerio | The jQuery API for domhandler's DOM | | dom-serializer | Serializer for domhandler's DOM |


LICENSE: MIT