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

custom-attributes-polyfill

v0.0.1

Published

A polyfill for Custom Attributes (`customAttributes.define()` and `Attr` subclasses)

Readme

Custom Attributes Polyfill

This polyfills Custom Attributes. While this proposal's specification and web platform tests are pending, this polyfill aims to implement what will be specified.

The polyfill will reach 1.0 when the specification has been written and merged. Until then expect breaking changes.

This polyfill works by overriding Attr, allowing sub classing, and introducing the CustomAttributeRegistry object. Attrs registered with customAttributes.define() will be upgraded in place with the same lifecycle callbacks as custom elements.

Installation

With npm

import "custom-attributes-polyfill";

This will automatically apply the polyfill if required.

To apply the polyfill manually, import the isSupported and apply functions from ./custom-attributes.js, which is mapped to /fn:

import { isSupported, apply } from "custom-attributes-polyfill/fn";
if (!isSupported()) apply();

An isPolyfilled function is also available:

import {
  isSupported,
  isPolyfilled,
  apply,
} from "custom-attributes-polyfill/fn";
if (!isSupported() && !isPolyfilled()) apply();

Without a package manager, use the unpkg script:

<script
  type="module"
  async
  src="https://unpkg.com/custom-attributes-polyfill@latest/custom-attributes.min.js"
></script>

Usage

class PersistValue extends Attr {
  connectedCallback() {
    const stored = localStorage.getItem(this.value);
    if (stored !== null) this.ownerElement.value = stored;
    this.ownerElement.addEventListener("input", this);
  }

  disconnectedCallback() {
    this.ownerElement.removeEventListener("input", this);
  }

  attributeChangedCallback(oldValue, newValue) {
    if (oldValue !== null) localStorage.removeItem(oldValue);
  }

  handleEvent() {
    localStorage.setItem(this.value, this.ownerElement.value);
  }
}

customAttributes.define("persist-value", PersistValue);
<input name="email" persist-value="email-draft" />

el.getAttributeNode("persist-value") and el.attributes["persist-value"] return the PersistValue instance.

Polyfilled surface

  • window.customAttributes which is a CustomAttributeRegistry
  • CustomAttributeRegistry methods define, get, getName, whenDefined, upgrade, initialize.
  • The Attr constructor: new MyAttr() for defined classes, new Attr() throws.
  • document.createAttribute() constructs defined attributes synchronously.
  • customAttributeRegistry on Element, Document and ShadowRoot, and the customAttributeRegistry option on createElement(), createElementNS(), importNode(), attachShadow(), setHTML() and setHTMLUnsafe().
  • connectedCallback, disconnectedCallback, connectedMoveCallback, adoptedCallback and attributeChangedCallback(oldValue, newValue).

Limitations

The polyfill observes the DOM with a MutationObserver, so it cannot match the specification exactly:

  • Reactions run at the next microtask checkpoint rather than synchronously at the end of the DOM operation. define(), upgrade(), initialize() and createAttribute() are synchronous.
  • An element removed and re-inserted within the same task keeps its custom attributes connected; no disconnectedCallback/connectedCallback pair fires. moveBefore() fires connectedMoveCallback synchronously.
  • Only document, shadow roots, and documents passed to initialize() are observed. Attributes upgraded elsewhere (for example inside an <iframe>) do not receive callbacks until they are adopted into an observed document.
  • An element's registry is fixed the first time the polyfill needs it rather than at creation. createElement(), importNode(), attachShadow(), setHTMLUnsafe() and initialize() pin it immediately; cloneNode() does not copy it.
  • Attributes that fail to construct keep the prototype super() gave them, as native custom elements do, but never receive callbacks.