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

@webreflection/element

v0.2.4

Published

A minimalistic DOM element creation library.

Downloads

11

Readme

@webreflection/element

Social Media Photo by James Owen on Unsplash

A minimalistic DOM element creation library.

Usage and Description

The default export is a function that accepts a tag and an optional options or setup literal, plus zero, one or more childNodes to append: (tag:string|Node, options:object?, ...(Node|string)[])

The tag

  • if it's an Element already it uses options to enrich the element as described
  • if it's a string and it does not start with <, it creates a new Element with such name
    • if it starts with svg: (followed by its name) or the tag value is svg itself, it creates an SVGElement
    • in every other case it creates an HTMLElement or, of course, a CustomElement with such name or, if options.is exists, a custom element builtin extend
  • if it's a string and it starts with < it uses the element found after document.querySelector. If no element is found, it returns null out of the box.

The options

Each option key / value pair is handled to enrich the created or retrieved element in a library friendly way.

The key

  • if key in element is false:
    • aria and data are used to attach aria- prefixed attributes (with the role exception) or the element dataset
    • class, html and text are transformed into className, innerHTML and textContent to directly set these properties with less, yet semantic, typing
    • @type is treated as listener intent. If its value is an array, it is possible to add the third parameter to element.addEventListener(key.slice(1), ...value), otherwise the listener will be added without options
    • ?name is treated as boolean attribute intent and, like it is for @type, the key will see the first char removed
  • if key in element is true:
    • classList adds all classes via element.classList.add(...value)
    • style content is directly set via element.style.cssText = value or via element.setAttribute('style', value) in case of SVG element
    • everything else, including on... handlers, is attached directly via element[key] = value

The value

If key in element is false, the behavior is inferred by the value:

  • a boolean value that is not known in the element will be handled via element.toggleAttribute(key, value)
  • a function or an object with a handleEvent are handled via element.addEventListener(key, value)
  • an object without handleEvent will be serialized as JSON to safely land as element.setAttribute(key, JSON.stringify(value))
  • null and undefined are simply ignored
  • everything else is simply added as element.setAttribute(key, value)

Please read the example to have more complete example of how all these features play together.


Example - Live Demo

// https://cdn.jsdelivr.net/npm/@webreflection/element/index.min.js for best compression
import element from 'https://esm.run/@webreflection/element';

// direct node reference or `< css-selector`  to enrich, ie:
// element(document.body, ...) or ...
element(
  '< body',
  {
    // override body.style.cssText = ...
    style: 'text-align: center',
    // classList.add('some', 'container')
    classList: ['some', 'container'],
    // a custom listener as object.handleEvent pattern
    ['custom:event']: {
      count: 0,
      handleEvent({ type, currentTarget }) {
        console.log(++this.count, type, currentTarget);
      },
    },
    // listener with an extra { once: true } option
    ['@click']: [
      ({ type, currentTarget }) => {
        console.log(type, currentTarget);
        currentTarget.dispatchEvent(new Event('custom:event'))
      },
      { once: true },
    ],
  },
  // body children / childNodes
  element('h1', {
    // clallName
    class: 'name',
    // textContent
    text: '@webreflection/element',
    style: 'color: purple',
    // role="heading" aria-level="1"
    aria: {
      role: 'heading',
      level: 1,
    },
    // dataset.test = 'ok'
    data: {
      test: 'ok',
    },
    // serialized as `json` attribute
    json: {a: 1, b: 2},
    // direct listener
    onclick: ({ type, currentTarget }) => {
      console.log(type, currentTarget);
    },
  }),
  element(
    'svg',
    {
      width: 100,
      height: 100,
    },
    // svg children / childNodes
    element('svg:circle', {
      cx: 50,
      cy: 50,
      r: 50,
      fill: 'violet',
    })
  ),
  element('p', {
    // innerHTML
    html: 'made with ❤️ for the <strong>Web</strong>',
  })
);