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

xml-light

v1.0.8

Published

Write XML in JavaScript

Readme

xml-light

Simple functions to generate XML/HTML in JavaScript.

Super compact package at less than 40 lines of code.

Virtual Hypertext

Use the Virtual Hypertext _ method.

_(tag: string, attributes: {}, ...children: string[]): string;

Example:

var xml = require('xml-light');
var _ = xml._;

var html =
    _('div', {'class': 'wrapper'},
        _('div', {'class': 'avatar'},
            _('img', {src: '...'}),
            _('span', {},
                'Hello there'
            ),
            _('br')
        )
    );
console.log(html);
//<div class="wrapper"><div class="avatar"><img src="..."/><span>Hello there</span><br/></div></div>

POJO

Create XML from a plain JavaScript Array object, where first element is the name of XML tag, the second is an object of attributes and the rest of the elements of the array are its children nodes.

type VNode = [tag: string, attributes: {}, ...children: VNode[]];
xml(root: VNode, h = _);

Example:

var xml = require('xml-light').xml;

var pojo =
    ['div', {'class': 'wrapper'},
        ['div', {'class': 'avatar'},
            ['img', {src: '...'}],
            ['span', null,
                'Hello there'
            ],
            ['br'],
        ],
    ];
console.log(xml(pojo));
// <div class="wrapper"><div class="avatar"><img src="..."/><span>Hello there</span><br/></div></div>

React

The second argument to the xml function is a virtual hypertext generator function, you can provide React.createElement.bind(React) to it to generate React virtual DOM.

Generate React Virtual DOM representations from POJO lists instead of using React.createElement or .jsx files and compiling them to .js.

var xml = require('xml-light').xml;
var react_dom = xml(
    ['div', {className: 'test'},
        ['span', null,
            'Hello world!'
        ]
    ], React.createElement.bind(React)
);

This is equivalent to:

var react_dom = React.createElement('div', {className: 'test'},
    React.createElement('span', null, 'Hello world!'));

You might consider creating a React Virtual Hypertext method for convenience:

React.h = React.createElement.bind(React);

var react_dom = xml(
    ['div', {className: 'test'},
        ['span', null,
            'Hello world!'
        ]
    ], React.h
);

Or even:

React.xml = function(pojo) {
    return xml(pojo, React.h);
};

So now, instead installing .jsx to .js compiler and writing your components in some weird xml-js mix language:

var CommentBox = React.createClass({
    render: function() {
        return (
            <div className="commentBox">
                Hello, world! I am a CommentBox.
            </div>
        );
    }
});

You can do everything in 100% JavaScript:

var CommentBox = React.createClass({
    render: function() {
        React.xml(
            // BONUS:
            // You can now add plain comments to your React templates,
            // without the required {/* */} syntax (in some places).           
            ['div', {className: 'commentBox'},
                'Hello, world! I am a CommentBox.'
            ]
        );
    }
});

TypeScript definitions for your extension:

declare namespace __React {
    export var h: (...pojo: any[]) => React.ReactElement<any>;
    export var xml: (pojo: any[]) => React.ReactElement<any>;
}