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

@jerp/xml-stream-ts

v0.1.3

Published

A small streaming XML parser for TypeScript.

Readme

@jerp/xml-stream-ts

A small TypeScript XML stream parser for extracting selected elements, text, attributes, and comments from arbitrarily chunked input.

It is designed for event-style parsing: define the tags you care about, stream bytes in, and receive parsed results as the matching root elements close. Unmatched branches are skipped.

Install

npm install @jerp/xml-stream-ts

Usage

import {
  createParser,
  decimal,
  leafParser,
  NamespaceMap,
  rootResolver,
  stringTextContent,
} from '@jerp/xml-stream-ts'

interface Book {
  lang?: string | null
  title?: string | null
  price?: number | null
}

const nsMap = NamespaceMap.create({
  '': 'urn:book',
  xml: 'http://www.w3.org/XML/1998/namespace',
})

const book = rootResolver<Book>()('book', nsMap, {
  attributes: ['xml:lang'] as const,
  onStart(attributes) {
    this.lang = stringTextContent(attributes.lang)
  },
  onEnd() {
    return {
      lang: this.lang,
      title: this.title,
      price: this.price,
    }
  },
})

book.onLeaf('title', leafParser<Book>()({
  onTextContent(textContent) {
    this.title = stringTextContent(textContent)
  },
}))

book.onLeaf('price', leafParser<Book>()({
  onTextContent(textContent) {
    this.price = decimal(textContent)
  },
}))

const parser = createParser<Book>(book, {})
const writer = parser.writable.getWriter()

await writer.write(new TextEncoder().encode('<book xmlns="urn:book" xml:lang="en">'))
await writer.write(new TextEncoder().encode('<title>XML Guide</title><price>19.95</price></book>'))
await writer.close()

for await (const book of parser.readable) {
  console.log(book)
  // { lang: 'en', title: 'XML Guide', price: 19.95 }
}

Typed Resolvers

rootResolver, tagParser, and leafParser are convenience helpers around TagResolver. They keep resolver declarations readable while preserving TypeScript validation for callback this values and attribute names.

Use as const on attributes when you want precise keys in onStart:

const root = rootResolver<Book>()('book', nsMap, {
  attributes: ['xml:lang', 'id'] as const,
  onStart(attributes) {
    attributes.lang // Uint8Array | undefined
    attributes.id // Uint8Array | undefined
  },
})

Namespaced attribute keys use the local name at runtime, so xml:lang is read as attributes.lang.

The parser callbacks receive Uint8Array text. Use the exported value resolvers to decode only when needed:

stringTextContent(bytes) // string | null
decimal(bytes) // number | null

Scope

This library parses XML elements, text, comments, attributes, namespaces, and CDATA. Processing instructions and declarations are skipped. Unmatched element branches are skipped without building a DOM.

Input is accepted as Uint8Array chunks through a WritableStream, and chunks may split anywhere in the document, including inside tag names, attributes, comments, and text.

Development

npm install
npm run build
npm test

Publishing

This package is intended to be published as @jerp/xml-stream-ts using npm Trusted Publishing from GitHub Actions.