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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vanillah

v1.0.8

Published

A h() function in VanillaJS for use with JSX or HTM

Downloads

21

Readme

vanillaH

If you love JSX you don't necessarily need a JS framework like React. You can provide a h() function yourself and use Vanilla JS. Essentially, all vanillaH provides is a h() function that creates DOM nodes using document.createElement, Element.setAttribute, Element.appendChild and document.createTextNode.

An example using JSX is on Codepen.

This is essentially what vanillaH does. I don't know how useful it is to you. Maybe not. ☺️

Getting started

vanillaH is available via NPM:

npm i vanillah

The vanillaH npm package provides a factory function where you pass in a document object (DOM API). It returns a h() function which can be used with JSX.

import vanillaH from 'vanillah';

const h = vanillaH(document);

const snippet = <h1>Hello World</h1>

document.body.appendChild(snippet);

Usage with esbuild

You can provide the jsx factory via esbuild.

Usage on Codepen

On Codepen, you can enable this by choosing "Babel" as preprocessor and adding a directive to use h() as a jsx factory:

/* @jsx h */
import vanillaH from 'https://unpkg.com/vanillah?module';

const h = vanillaH(document);

const stuff = <h1>Hello World</h1>;

document.body.appendChild(stuff);

Yeeting the transpile step

You can also use vanillaH without transpile step:

h('div', {className: 'wrapper'}, 
  h('h1', null, 'Hello World')
);

This may be a bit cumbersome. But there's a library which allows you to use template strings, called htm.

import vanillaH from 'https://unpkg.com/vanillah?module';
import htm from 'https://unpkg.com/htm?module';

const h = vanillaH(document);
const html = htm.bind(h);

const stuff = html`
  <div>
    <div className="headline-wrapper">
      <h1 id="hello-world">Hello World</h1>
      <a href="#hello-world">
        <span aria-hidden="true">#</span>
      </a>
    </div>
    <a href="https://lea.codes" aria-labelledby="hello-world" target="_blank">Hello world</a>
    <p>
      Lorem ipsum dolor sit, amet consectetur adipisicing elit. Aperiam dolorem
      aspernatur saepe asperiores autem, rem architecto eos fugit officia sed.
      Soluta corrupti, facere iure quae accusamus velit consequuntur magni quia!
    </p>
  </div>
`;

document.body.appendChild(stuff);

Usage on the server-side

You can use vanillaH on the server-side by using linkedom.

import { parseHTML } from 'linkedom';
import htm from 'htm';
import vanillaH from 'vanillah';

const {
  window, document
} = parseHTML(`
  <!doctype html>
  <html lang="en">
    <head>
      <title>Hello SSR</title>
      <meta charset="UTF-8">
    </head>
    <body>
    </body>
  </html>
`);

const h = vanillaH(document);
const html = htm.bind(h);

document.body.appendChild(html`<h1>Hello World</h1>`);

console.log(document.toString());