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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@soil/dom

v0.8.1

Published

Declaratively create type-safe HTML and SVG elements.

Downloads

12

Readme

@soil/dom

Declaratively create type-safe HTML and SVG elements. One way to think of it might be as "HTML-in-JS".

Documentation

h (namespace)

Creating HTML using strings is not type-safe. Creating them from code is too verbose. The h namespace gives access to shortcut functions to create any HTML element, as well as to type aliases to refer the types returned by those functions.

import {h} from '@soil/dom'

const button: h.Button = h.button({onclick: () => alert('Clicked')}, ['Click me'])

const paragraph: h.P = h.p({}, [
    'Text with ',
    h.a({href: '...'}, ['link'])
])

const input: h.Input = h.input({placeholder: 'Input...'})

const customElement: HTMLElement = h.x('custom-element')

They are provided under a namespace to avoid polluting the scope with plenty of functions and types (a, A, b, B, ...); to prevent problems with reserved words such as var and switch, which would be required for elements such as <var> and <switch>; and to avoid long import statements. As a nice side effect the auto-completion experience is better too.

s (namespace)

Analogous to h for SVG elements.

import {s} from '@soil/dom'

s.svg({width: {baseVal: {value: 100}}, height: {baseVal: {value: 100}}}, [
    s.circle({
        cx: {baseVal: {value: 50}},
        cy: {baseVal: {value: 50}},
        r: {baseVal: {value: 40}},
        style: {
            stroke: 'green',
            strokeWidth: '4',
            fill: 'yellow'
        }
    })
])

Unfortunately, creating type-safe SVG programmatically results in verbose code, and the difference between attributes and properties is bigger than in the HTML case. The code above produces the same circle than the following HTML:

<svg width="100" height="100">
    <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>

On the other hand, we have access to the whole SVG API, richer than its attribute-based counterpart, and there will be no differences between creating elements and modifying them, e.g. you would otherwise need <circle stroke="green" /> for creation but circle.style.stroke = 'red' for modification.

Installation

The package is available at npm's registry, so it can be installed via npm or Yarn:

npm i -S @soil/dom
# AKA npm install --save @soil/dom
yarn add @soil/dom

License

This project is licensed under the GNU Affero General Public License.