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

htmlcomponent

v0.1.2

Published

A microlib that empowers you to reference a component in HTML

Downloads

6

Readme

htmlcomponent

A microlib that empowers you to reference a component in HTML. It does this by a common way to mark the components and with an interface to pass the dom and some options directly from HTML to JS. The basic function syntax works by default with multiple instances of one component. HTMLComponent Spec without the need to drop browser support. So no more .js--slider-top referencing in your HTML.

Basic Usage

<div data-hc="app/main">just html</div>

<script src="htmlcomponent.min.js"></script>
<script>
	var components = {};
	components["app/main"] = function(dom, opts) {
		dom.innerHTML = "simple component";
	};
	htmlcomponent.setStaticLoader(components);
	htmlcomponent.query(document);
</script>

Result will be:

<div data-hci="app/main">simple component</div>

Usage with Options

<div data-hc="app/mainopts" data-hcd='{"name": "SuperComponent"}'>just html</div>

<script src="htmlcomponent.min.js"></script>
<script>
	var components = {};
	components["app/mainopts"] = function(dom, opts) {
		dom.innerHTML = "my name is "+opts.name;
	};
	htmlcomponent.setStaticLoader(components);
	htmlcomponent.query(document);
</script>

Result will be:

<div data-hci="app/mainopts">my name is SuperComponent</div>

Usage with options as a json script

<div data-hc="app/mainopts">
	<script type="application/json" data-hc>
		{
			"name": "SuperComponent",
			"bigdata": [
				1,
				2,
				3 //you get it
			]
		}
	</script>
	just html
</div>

<script src="htmlcomponent.min.js"></script>
<script>
	var components = {};
	components["app/mainopts"] = function(dom, opts) {
		dom.innerHTML = "my name is "+opts.name;
	};
	htmlcomponent.setStaticLoader(components);
	htmlcomponent.query(document);
</script>

Usage with SystemJS or any other promise based loader

<div data-hc="app/main">
	just html
</div>

<script src="system.js">
<script src="config.js">
<script src="htmlcomponent.min.js"></script>
<script>
	//this is the default behavior so the next line is optional
	htmlcomponent.config.promiseLoader = System.import.bind(System)
	htmlcomponent.query(document);
</script>
//main.js amdstlye
define(function() {
	return function(dom, opts) {
		dom.innerHTML = "my name is "+opts.name;
	}
});

Use in a build/integration environment

It provides a component searcher, that crawls through your template files and writes them to a grunt config variable to be used later on. There is a grunt-task that can generate you a static map of your components. With this basic utilitys you will be able to use SystemJS builder to pack your components in a single static file where the components are protected from uglify and rollup. (yeah, the have the tendency to kick seemingly unused code over board)

Compatiblity

htmlcomponent does nothing else so you can use any library you want.

FAQ

But why not jQuery selecting in the DOM jungle?

Because WebComponents are the way to go. https://www.webcomponents.org/

But this library does only bind a specific DOM Element to a javascript function and pass options...

The answer is: 2kb Yeah, if you want more features from WebComponents https://www.webcomponents.org/