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

zoll

v0.1.1

Published

A lightweight custom-element-like hook for use with existing frameworks

Downloads

4

Readme

zoll

A lightweight custom-element-like hook for use with existing frameworks.

zoll strives to be spec compatible where possible. For the implementation details please refer to custom elements spec

Installation

# NPM
npm install zoll

# Bower
bower install zoll

You can also include it directly on the webpage

<script type="text/javascript" src="./dist/zoll.min.js"></script>

Usage

Creating a custom element with lifecycle callbacks

Let's assume we want to create a custom element . The end goal is to use them directly on the page like this

<profile-picture url="./image.png"> </profile-picture>

To do this, we need to define the element

// since `custom-element-hook` doesn't actually alter any prototypes it's 
// necessary to specify utility functions as free-standing and pass the node  
// to them
function updateBg(node, url) {
    node.style.cssText = `background: url(${zoll.getAttribute(node, 'url')}); width: 200px; height: 200px;`;
}

// Defining the element in the custom element registry
zoll.define('profile-picture', {
    observedAttributes: ['url'],
    connectedCallback: function() {
        if (this.hasAttribute('url')) {
            updateBg(this, this.getAttribute('url'));
        }
    },
    disconnectedCallback: function() {
        console.log('disconnected');
    },
    attributeChangedCallback: function(attrName, oldValue, newValue) {
        if (attrName === 'url') {
            updateBg(this, newValue);
        }
    }
});

// creating and adding it to the DOM
const pic = zoll.create('profile-picture', {
    url: 'image.png'
});
zoll.appendChild(document.body, pic);
zoll.setAttribute(pic, 'url', 'image2.png');

zoll.remove(pic);
//output - disconnected

Creating custom element using extends

Lets create a custom button element <custom-button> by extending it from default <button>.

<custom-button>Click Me!</custom-button>
zoll.define('custom-button', {
    extends: 'button',
    connectedCallback: function() {
        this.onclick = function(){
            console.log('Button Clicked');
        };
    },
    disconnectedCallback: function() {
        console.log('Button Removed');
    }
});

const btn = zoll.create('button', {
    is : 'custom-button',
    value: 'Click Me'
});
zoll.appendChild(document.body, btn);

Upgrade

This allows progressive enhancement of the content in the custom element.

index.html

<!DOCTYPE html>
<html lang="en">
<script type="text/javascript" src="dist/zoll.min.js"></script>
<body>
    <profile-picture url="image.png"></profile-picture>

    <script src= "main.js"></script>
</body>

main.js

zoll.define('profile-picture', {
    // same as first example
});
// upgrade all the elements
zoll.connect(document.body);

once the main.js loads, it will define the <profile-picture> element and the existing <profile-picture> element will be upgraded, applying the custom element's definition (which will set the background image in our case).

Note: The upgrade only apply to the elements in the document tree.

API

The library exposes a Zoll class where the below methods are defined.

define(tagName, options)

Defines a new custom element with the specified tag name and options.

Options
  • extends extending a built in element or other custom Element.
  • observedAttributes array of attributes that triggers the attributeChangedCallback on modifications.
  • attributeChangedCallback(attrName, oldValue, newValue) gets called for all the observedAttributes of an element.
  • connectedCallback gets called when the element is inserted in to the document.
  • disconnectedCallback gets called when the element is removed from the document.

create(tagName, attributes)

Simple wrapper around document.createElement, that can also set attributes in a batch without notifying the possible observers.


connect(root)

Simulates the connect process for custom elements in the given subtree calling defined lifecycle callbacks.


forceConnectNode(element)

Allows to manually notify when the element is inserted in document.


forceConnectChildren(element)

Allows to manually notify when the element's children is inserted in document.


forceDisconnectNode(element)

Allows to manually notify when the element is removed in document.


forceDisconnectChildren(element)

Allows to manually notify when the element's children is inserted in document.


forceNotifyAttributeChange(descriptor, el, attributeName, oldValue, attributeValue)

Allows to manually notify an element about the attribute change.

This is useful for some libraries that manipulate DOM under you, like React.


getDescriptor(node)

Retrives the element from the CustomElementRegistry if defined.


setAttribute(node, attributeName, attributeValue)

A proxy for native setAttribute that takes care of the observed attribute notifications.


removeAttribute(node, attributeName)

A proxy for native removeAttribute that takes care of the observed attribute notifications.


hasAttribute(node, attributeName)

A proxy for native hasAttribute.


getAttribute(node, attributeName)

A proxy for native getAttribute.


appendChild(parent, child)

A proxy for native appendChild that will notify about nodes connected to the document.


insertBefore(parent, child, reference)

A proxy for native insertBefore that will notify about nodes connected to the document.


remove(element)

Removes the node from it's parent if one exists.