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

@hatimsue/xmlgenerator

v2.0.0

Published

A lightweight JavaScript library to generate XML using a declarative syntax.

Readme

npm Status

xmlgenerator

A lightweight JavaScript library for building XML documents using a clean, declarative syntax.

Installation

npm install @hatimsue/xmlgenerator

Overview

This is a complete example showcasing the core features of the xmlgenerator library:

import {XMLGenerator} from '@hatimsue/xmlgenerator'

const _ = new XMLGenerator().builder

// Array of authors to demonstrate loops using spread + map
const authors = ['J.K. Rowling', 'J.R.R. Tolkien', 'George R.R. Martin']

// Start building the XML document
const xml = _.Library
  .$xmlns('http://example.org/library')              // Declare default namespace
  .$xmlns.bk('http://example.org/book')              // Declare prefixed namespace "bk"
  .location('UK')                                     // Add attribute "location"
  (
    _.$comment('This is a library XML document'),     // Insert an XML comment

    _.bk.Books.genre('fantasy')(                      // Create <bk:Books genre="fantasy">
      ...authors.map(author =>                        // Spread multiple <bk:Book> elements
        _.bk.Book.lang('en')(                          // <bk:Book lang="en">
          _.bk.Author(author),                         // Add <bk:Author>Author Name</bk:Author>
          _.bk.Name(`A book by ${author}`)             // Add <bk:Name>Title</bk:Name>
        )
      )
    ),

    _.bk.ExtraInfo(                                   // Another element with CDATA section
      _.$cdata('Some unparsed <CDATA> content goes here & should not be escaped.')
    )
  )

// Pretty-print the final XML
console.log(xml.$toPrettyXML())

Examples

import {XMLGenerator} from '@hatimsue/xmlgenerator'

const _ = new XMLGenerator().builder

const xmlDocument = _.Books(
  _.Book(
    _.Author('J.K. Rowling'),
    _.Name('Harry Potter and the Philosopher\'s Stone')
  )
)

console.log(xmlDocument.$toPrettyXML())
/**
 * <Books>
 *   <Book>
 *     <Author>J.K. Rowling</Author>
 *     <Name>Harry Potter and the Philosopher's Stone</Name>
 *   </Book>
 * </Books>
 */
import {XMLGenerator} from '@hatimsue/xmlgenerator'

const _ = new XMLGenerator().builder

const xmlDocument = 
_.Books.category('fiction').country('UK')(
  _.Book.lang('en')(
    _.Author('J.K. Rowling'),
    _.Name('Harry Potter and the Philosopher\'s Stone')
  )
)

console.log(xmlDocument.$toPrettyXML())
/**
 * <Books category="fiction" country="UK">
 *   <Book lang="en">
 *     <Author>J.K. Rowling</Author>
 *     <Name>Harry Potter and the Philosopher's Stone</Name>
 *   </Book>
 * </Books>
 */

import {XMLGenerator} from '@hatimsue/xmlgenerator'

const _ = new XMLGenerator().builder

const xmlDocument = 
_.Books
  .$xmlns('http://example.org/books') // default namespace
  .$xmlns.bk('http://example.org/book') // prefix namespace
  .$xmlns.ss('http://example.org/ss')  // prefix namespace
  .category('fiction')
  .country('UK')(
    _.bk.Book.lang('en')(
      _.bk.Author('J.K. Rowling'),
      _.bk.Name('Harry Potter and the Philosopher\'s Stone')
    )
)

console.log(xmlDocument.$toPrettyXML())
/**
 * <Books xmlns="http://example.org/books" xmlns:bk="http://example.org/book" category="fiction" country="UK">
 *   <bk:Book lang="en">
 *     <bk:Author>J.K. Rowling</bk:Author>
 *     <bk:Name>Harry Potter and the Philosopher's Stone</bk:Name>
 *   </bk:Book>
 * </Books>
 */

Reference

| Concept | Description | Syntax / Example | Expected XML Output | |--------------------------------|---------------------------------------------------------------------------------|---------------------------------------------------|--------------------------------------------| | Create a tag | Use a method named after the tag to create it. Must be called with (). | _.Book() | <Book/> | | Add content | Pass strings or nested tags as arguments inside the parentheses. | _.Book('Title') | <Book>Title</Book> | | Add attribute | Chain attribute methods before calling the tag with (). | _.Book.lang('en')() | <Book lang="en"/> | | Chain attributes | Chain multiple attribute methods before final (). | _.Book.lang('en').year('2001')() | <Book lang="en" year="2001"/> | | Add default namespace | Call _$xmlns(url) on the element before (). | _.Books._$xmlns('http://example.org')() | <Books xmlns="http://example.org"/> | | Add namespaced prefix | Use _$xmlns.prefix(url) to declare namespaced prefixes. | _.Books._$xmlns.lib('http://example.org/lib')() | <Books xmlns:lib="http://example.org/lib"/> | | Use namespaced tags | Use prefix as property (e.g., _.lib.TagName()) after declaring it. | _.lib.Book() | <lib:Book/> | | Add comment | Insert with _.$comment('text') as a child element. | _.$comment('Note here') | <!-- Note here --> | | Add CDATA section | Use _.$cdata('value') to wrap raw XML content safely. | _.$cdata('<tag>') | <![CDATA[<tag>]]> | | Use a loop/dynamic content | Use spread syntax with .map() or other loops that return tag arrays. | ...['a','b'].map(n => _.Name(n)) | <Name>a</Name>\n<Name>b</Name> | | Single line output | Use $toXML() to generate compact XML string. | element.$toXML() | <Book><Author>J.K.</Author></Book> | | Multiline XML output | Use $toPrettyXML() to output indented XML for readability. | element.$toPrettyXML() | Formatted multi-line XML | | Root element | Start your XML tree from a top-level tag like _.Library(...). | const xml = _.Library(...) | <Library>...</Library> | | Output XML | Log or return the result from $toXML() or $toPrettyXML(). | console.log(xml.$toPrettyXML()) | Console output of the XML |