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

ujsx

v1.2.2

Published

microJSX (µJSX) - a trivial JSX-to-DOM/HTML processor

Readme

µJSX

µJSX is a trivial JSX-to-DOM/HTML processor. It can be used with TypeScript or JavaScript, in browser, on server or with a custom DOM context (like jsdom).

If given a DOM context, it will produce DOM nodes right away. Otherwise it will return simple objects that can be converted to HTML or DOM later.

You can mix real DOM and µJSX objects too.

Warning

This package contains a declaration that "JSX elements" are also DOM elements.

This may not actually be true when running on server (or if using a different JSX factory in the same project).

Unfortunately I don't know of an easy way to make that distinction while allowing code like document.body.appendChild(<div>Hi!</div>) in browser (which currently compiles and works perfectly well).

Exports

auto

An object containing three functions (ujsx, ujsxToHTML, ujsxToDOM) bound either to browser DOM context or to no DOM context (in which case ujsxToDOM will fail if called).

These bound functions are also exported separately.

ujsx(tag, attributes, ...children)

The main method that can be used as a drop-in JSX factory (see below).

If given a DOM context, it will produce DOM nodes right away. Otherwise it will return simple objects that can be converted to HTML or DOM with two functions defined below.

Note that if there is a DOM context you can also pass DOM nodes as children.

tag can also be a function that accepts and object containing all atributes (with children in an array at children key). Its return value is passed to caller verbatim.

ujsxToHTML(ujsx)

Converts anything that its sibling ujsx() can return to a HTML string.

ujsxToDOM(ujsx | ujsx[])

Given a DOM context converts uJSX objects to DOM a dom element or array thereof.

This function is a no-op for elements created in the browser since they're already DOM nodes.

ujsxFor({ window?, document? })

Create a bundle of functions for a given DOM context (like auto). document is assumed to be window.document if not passed.

window is also used to obtain Node and Element classes which instanceof is used on (therefore mixing DOM elements from different documents won't work).

import { ujsxFor } from 'ujsx';
import { JSDOM } from 'jsdom';
const dom = new JSDOM(...);
const { ujsx, ujsxToDOM } = ujsxFor({ window: dom.window });

isUJSXObject(obj)

Returns true if obj seems compatible with what createUJSXObject() returns (basically duck-typing by checking for tag, attributes and children properties).

createUJSXObject(tag, attributes, ...children)

Explicitly creates an intermediate object even if DOM is present. (this is what ujsx() falls back to if there is no window).

domToUJSX(node)

Convert a DOM node (Element, TextNode, Document or DocumentFragment) to an implementation-agnostic UJSX intermediate object.

Intermediate object

interface UJSXObject {
    // tag name, lowercase
    tag: string;
    // attribute map, lowercase names
    attributes: { [key: string]: any };
    // children (UJSXObject, Element, string, etc)
    children: any[];
}

It's safe to modify this object in any way possible. You can also deep clone it or create it manually as long as all three keys are present and not void.

Intermediate objects are not attached to specific DOM context and can therefore be used to migrate nodes between different DOM trees and implementations.

Usage with TypeScript in .tsx files

{
    "compilerOptions": {
        "jsx": "react",
        "jsxFactory": "ujsx"
    },
    "include": [
        "./**/*.tsx"
    ]
}

Feedback

If you think there's something wrong or something is missing, please contact me :)

License

MIT