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

@gebruederheitz/energize

v1.5.2

Published

Reactive DOM operations with plain ES6+

Readme

Energize

Reactive DOM operations with plain ES6+


energize is little more than some syntactic sugar to turn pre-rendered static HTML elements into stateful reactive components.

Our real-word scenario is turning a Webflow site into an interactive application, with stateful elements communicating with an external API. It can connect to any store fulfilling the Svelte store contract; we recommend nanostores.

Installation

npm i @gebruederheitz/energize

Basic Usage

<!-- Pre-existing HTML and CSS -->
<div class="my-component" data-component="my-component"></div>
<div class="my-other-component" data-component="my-other-component"></div>
<div class="my-other-component" data-component="my-other-component"></div>
import { EnhancedElement, energize, energizeAll } from '@gebruederheitz/energize';
import { atom } from 'nanostores';

type State = string;
const store = atom<State>('Hello!');

class MyComponent extends EnhancedElement<HTMLDivElement, State> {
    // "lifecycle" hooks:
    protected onAfterConnect(): void {}
    protected onShown(): void {}
    protected onHidden(): void {}
    protected onDestroyed(): void {}
    protected onInit(): void {
        this.on('click', this.onClick);
    }
    
    // Your entrypoint for state management:
    protected onStoreUpdate(newState): void {
        if (newState) {
            // Utility for manipulating innerText
            this.content(newState);
            // Utility for dispatching CustomEvent instances from the element
            this.emit('state-change', {newState});
        } else {
            // Utility to add a configurable set of classes (default: "hidden")
            // to the element and mark it as hidden using a class property; as
            // well as setting aria-hidden to allow for advanced transition
            // handling and non-standard visual hiding techniques.
            this.hide();
        }
    }
    
    private onClick = (e: MouseEvent) => {
        this.store.set('Ouch!');
    };

    public destroy(): void;

    public clone(): EnhancedElement<ET, S, STATE>;
    public cloneInto<
        C extends EEConstructor<any, any>,
        T extends EnhancedElement<any, any> = InstanceType<C>,
    >(constructor: C, ...additionalArgs: EEConstructorArgs<C>): T;
    
    // Utilities as proxies to standard DOM operations:
    public on(
        eventName: string,
        callback: EventListenerOrEventListenerObject,
        options?: boolean | (EventListenerOptions & AddEventListenerOptions)
    ): () => void;
    protected emit(eventName: string, data: unknown);
    public show(): this;
    public hide(): this;
    public content(innerText: string): this;
    public contentOrHide(innerText: string | null = null): this;
    public getContent(): string;
    public addClass(...classes: string[]): this;
    public removeClass(...classes: string[]): this;
    public appendTo(parent: Element | EnhancedElement<any>): this;
    public insertAfter(element: Element | EnhancedElement<any>): this;
    // Will unsubscribe from any stores if required:
    public destroy(): void;
    public find<T extends HTMLElement>(selector: string): T | null;
    public findAll<T extends HTMLElement>(
        selector: string,
        asArray: boolean = false
    ): T[] | NodeListOf<T>;
    public parent<T extends HTMLElement = HTMLElement>(
        selector: string = null
    ): T;
    public get getAttribute();
    public setAttribute(attributeName: string, attributeValue: string): this;
    public get dataset();
    
    // Internal properties & their management
    public isVisible(): boolean;
    public getData<T extends unknown>(key: string): T;
    public setData(key: string, value: unknown): this;
    protected getClassNames(): Record<string, string> {
        return {
            hidden: 'hidden',
        };
    }
    public getElement(): ET;
    // Manually connect a store
    public connect<Sx extends StoreType<any>>(store: Sx): this;
    
    // Creating EnhancedElement children:
    public findAndWrap<
        T extends HTMLElement,
        Sx extends StoreType<STx> | void = void,
        STx extends any = any,
    >(selector: string): EnhancedElement<T, Sx, STx> | null;
    public findAndWrapAll<
        T extends HTMLElement,
        Sx extends StoreType<any> | void = void,
        STx extends any = any,
    >(selector: string, store: Sx = null): EnhancedElement<T, Sx, STx>[];
    public findAndWrapInto<
        C extends EEConstructor<any, any>,
        T extends EnhancedElement<any, any> = InstanceType<C>,
    >(
        selector: string,
        into: C,
        store: EEStoreType<T> = null,
        ...additionalArgs: EEConstructorArgs<C>
    ): T | null;
    public findAndWrapAllInto<
        C extends EEConstructor<any, any>,
        T extends EnhancedElement<any, any> = InstanceType<C>,
    >(
        selector: string,
        into: C,
        store: EEStoreType<T> = null,
        ...additionalArgs: EEConstructorArgs<C>
    ): T[];
}

energize('[data-component="my-component"]', MyComponent, store);
energizeAll('[data-component="my-other-component"]', MyComponent, store);
setTimeout(() => {
    store.set('Goodbye')
}, 2000)