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

hmpl-dom

v0.0.2

Published

A module for using HMPL syntax directly in HTML, without the need for compilation on the JavaScript side

Readme

hmpl-dom

npm-version

hmpl-dom is a library for integrating HMPL templates directly into the DOM. It allows you to use templates written with hmpl-js right in your HTML documents using the <template> tag, and automatically mounts them into the DOM.

Requires hmpl-js version 3.0.0 or higher.

Installation

npm install hmpl-dom

Usage

Add a template to your HTML file using the <template> tag and the data-hmpl or hmpl attribute:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Example</title>
  </head>
  <body>
    <main>
      <template data-hmpl data-config-id="my-component-config">
        <div>
          {{#request src="/api/my-component.html"}}
            {{#indicator trigger="pending"}}
              Loading...
            {{/indicator}}
          {{/request}}
        </div>
      </template>
    </main>
    <script src="https://unpkg.com/json5/dist/index.min.js"></script>
    <script src="https://unpkg.com/dompurify/dist/purify.min.js"></script>
    <script src="https://unpkg.com/hmpl-js/dist/hmpl.min.js"></script>
    <script src="https://unpkg.com/hmpl-dom/dist/hmpl-dom.min.js"></script>
  </body>
</html>

This HTML example demonstrates how to use the hmpl-dom library to mount HMPL templates directly in your page:

  • The <template data-hmpl data-config-id="my-component-config"> tag defines a template that will not be rendered immediately. It contains HMPL syntax for dynamic content loading.
  • Inside the template, the {{#request src="/api/my-component.html"}} ... {{/request}} block will fetch content from the server. While the request is pending, the {{#indicator trigger="pending"}} Loading... {{/indicator}} block will show a loading message.
  • The scripts at the bottom load all required dependencies from CDN: json5, dompurify, hmpl-js, and hmpl-dom.
  • When the page loads, hmpl-dom will automatically find all <template data-hmpl ...> elements, compile them using HMPL, and replace the template with the rendered result in the DOM.

This approach allows you to declaratively define dynamic, server-driven components in your HTML, and have them automatically rendered and updated by the HMPL engine.

Configs

Each config object for init can contain:

  • id: (string) — Unique identifier for the template, must match the data-config-id in HTML.
  • value: (object)
    • compile: (object) — Compile options for HMPL (e.g., { memo: true }).
    • templateFunction: (object) — Data or parameters to be passed to the template function.

Example:

init([
  {
    id: "1",
    value: {
      compile: { memo: true },
      templateFunction: { credentials: "include" }
    }
  }
]);

Important Notes

  • Each <template> must contain exactly one root element.
  • The data-config-id attribute is not required and cannot be empty.
  • For every configId, a corresponding option must be defined in the init call.

Example

<template data-hmpl data-config-id="clicker-config">
  <div>
    <button data-action="increment" id="btn">Click!</button>
    <div>
      Clicks: {{#request src="/api/clicks" after="click:#btn"}}{{/request}}
    </div>
  </div>
</template>
import { init } from "hmpl-dom";

init([
  {
    id: "clicker-config",
    value: {
      compile: { memo: true },
      templateFunction: ({ request: { event } }) => ({
        body: JSON.stringify({
          action: event.target.getAttribute("data-action")
        })
      })
    }
  }
]);

Changelog

See the GitHub releases page for changes.

Contributing

We have a Contributing Guide that describes the main steps for contributing to the project.

Thank you to all the people who have already contributed to HMPL, or related projects!

License

This project is licensed under the MIT License.