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 πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

zeed-dom

v0.17.7

Published

🌱 Lightweight offline DOM

Readme

🌱 zeed-dom

A modern, lightweight, TypeScript virtual DOM for Node.js, browser, and static content generation.


  • ⚑️ Fast: Efficient HTML parsing and serialization
  • 🧩 JSX Compatible: Works seamlessly with JSX/TSX
  • πŸ” CSS Selectors: Query with a subset of CSS selectors
  • πŸ›  Easy Manipulation: Chainable API, .handle() helper, and more
  • πŸ“ HTML, XML, Markdown, Plaintext: Serialize to multiple formats
  • 🧹 Pretty Print: Tidy up HTML with tidyDOM
  • 🦾 TypeScript: Full typings, modern codebase
  • πŸ”’ Safe HTML: Output sanitized HTML for user content

Note: This project does not aim for full browser DOM completeness, but covers most practical use cases for static content, SSR, and offline DOM manipulation.


πŸš€ Get Started

npm i zeed-dom

πŸ”— Related Projects

  • zeed – Foundation library
  • zerva – Event-driven server

Used by TipTap in its html-package.


✨ Features

  • Virtual DOM tree with VNode, VElement, VDocument, etc.
  • HTML parsing and serialization
  • XML output support
  • CSS selector engine (subset)
  • JSX/TSX support (see below)
  • Safe HTML serialization (serializeSafeHTML)
  • Markdown and plaintext serialization
  • Manipulation helpers: .handle(), .replaceWith(), .remove(), etc.
  • Works in Node.js, browser, and serverless
  • Pretty print HTML (tidyDOM)
  • TypeScript-first API

πŸ›  Usage Examples

Manipulation

Drop in HTML, query, and change it. Returns HTML again. Great for post-processing:

import { handleHTML } from 'zeed-dom'

const newHTML = handleHTML(html, (document) => {
  const img = document.querySelector('.img-wrapper img')
  if (img)
    img.setAttribute('title', img.getAttribute('src'))
})

Serialization

Take any HTML node or document and serialize it to another format:

  • serializePlaintext(node): Readable and searchable plain text
  • serializeMarkdown(node): Simple Markdown
  • serializeSafeHTML(node) or safeHTML(htmlString): Allow only basic tags and attributes

Virtual DOM Example (no JSX)

import { h, xml } from 'zeed-dom'

const dom = h(
  'ol',
  { class: 'projects' },
  [
    h('li', null, 'zeed ', h('img', { src: 'logo.png' })),
    h('li', null, 'zeed-dom'),
  ]
)

console.log(dom.render())
// <ol class="projects"><li>zeed <img src="logo.png"></li><li>zeed-dom</li></ol>

console.log(dom.render(xml))
// <ol class="projects"><li>zeed <img src="logo.png" /></li><li>zeed-dom</li></ol>

JSX Example

import { h } from 'zeed-dom'

let dom = (
  <ol className="projects">
    <li>zeed</li>
    <li>zeed-dom</li>
  </ol>
)

dom.handle('li', (e) => {
  if (!e.textContent.endsWith('-dom')) {
    e.remove()
  } else {
    e.innerHTML = '<b>zeed-dom</b> - great DOM helper for static content'
  }
})

console.log(dom.render())
// <ol class="projects"><li><b>zeed-dom</b> - great DOM helper for static content</li></ol>

HTML Parsing & Tidy

import { tidyDOM, vdom } from 'zeed-dom'

const dom = vdom('<div>Hello World</div>')
tidyDOM(dom)
console.log(dom.render())
// Output is pretty printed like:
// <div>
//   Hello World
// </div>

βš›οΈ JSX Setup

JSX is supported out of the box. For TypeScript, add to your tsconfig.json:

{
  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "h"
  }
}

Add this to your shims.d.ts:

// https://www.typescriptlang.org/docs/handbook/jsx.html#intrinsic-elements
declare namespace JSX {
  interface IntrinsicElements {
    [elemName: string]: any
  }
}

For ESBuild:

{
  jsxFactory: 'h'
}

Or as a CLI option: --jsx-factory=h

For browser DOM:

const { hFactory } = require('zeed-dom')
export const h = hFactory({ document })

πŸ§ͺ API Highlights

  • vdom(htmlString): Parse HTML to virtual DOM
  • tidyDOM(node): Pretty print/format DOM
  • serializeSafeHTML(node): Output safe HTML
  • serializeMarkdown(node): Output Markdown
  • serializePlaintext(node): Output plain text
  • handleHTML(html, fn): Manipulate HTML with a callback
  • VElement, VNode, VDocument, etc.: Core classes
  • .handle(selector, fn): Manipulate elements by selector
  • .querySelector, .querySelectorAll: CSS selector queries
  • .replaceWith(), .remove(), .setAttribute(), etc.: DOM-like methods

🚦 Performance

The parser is fast, as shown in htmlparser-benchmark


πŸ“ Misc

  • Use double underscore in JSX for namespaces: <xhtml__link /> β†’ <xhtml:link />
  • Use CDATA helper for raw data: <div>{CDATA(yourRawData)}</div>
  • style attributes can be objects: <span style={{backgroundColor: 'red'}} /> β†’ <span style="background-color: red" />
  • Works in Node.js, browser, and serverless
  • TypeScript-first, but works with plain JS too