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

stateful-pages

v0.1.4

Published

Lightweight state manager

Readme

Stateful Pages

npm version

A simple and lightweight library for state management.

How to use

Put the Stateful Pages script tag at the bottom of the body, but before your JavaScript code.

<html lang="en">

<body>

<!-- Body -->

<script src="path/to/stateful/pages"></script>
<script src="path/to/your/code"></script>
</body>

</html>

To use Stateful Pages, wrap your code inside a <stateful> tag.

<stateful>
    <h1>Stateful Pages!</h1>
</stateful>

Each <stateful> tag works independently, so there can be multiple tags per page, but you can also just put the entire page within one tag.

State

This is where the work is done. Everything works based on the values within the state. To set values in the state, use setState() from the stateful tag.

const stateful = document.getElementById("stateful-root");
const { setState } = stateful;

setState({
    foo: "bar",
});

Getting values within the state is done using the state object from the tag.

const stateful = document.getElementById("stateful-root");
const { state, setState } = stateful;

setState({
    foo: "bar",
});

console.log(state.foo); // "bar"

Values

To use a value in the page, use the <value> tag.

<stateful id="stateful-root">
    <p>The value is
        <value name="foo"></value>
    </p>
</stateful>

<script>
    const stateful = document.getElementById("stateful-root");
    const { state, setState } = stateful;

    setState({
        foo: "bar",
    });
</script>

This will render out to

<p>The value is bar</p>

Updating values

This will produce a button with a counter

<stateful id="stateful-root">
    <button id="button">Click me!</button>
    Presses:
    <value name="presses"></value>
</stateful>

<script>
    const stateful = document.getElementById("stateful-root");
    const { state, setState } = stateful;

    setState({
        presses: 0,
    });

    document.getElementById("button").onclick = () => {
        setState({
            presses: state.presses + 1,
        });
    };
</script>

Every time the button is pressed, the counter will increment.

Conditionals

Conditionals can be created using the <if> tag. Nested within the <if> tag can be one <then> tag, zero or more <elif> tags, and zero or one <else> tag.

<stateful id="stateful-root">
    <h1>
        <if condition="raining">
            <then>It is raining</then>
            <else>It is not raining</else>
        </if>
    </h1>
</stateful>

<script>
    const stateful = document.getElementById("stateful-root");
    const { state, setState } = stateful;

    setState({
        raining: true,
    });
</script>

This will render to

<h1>It is raining</h1>

Notice how the <h1> tag is wrapping the entire conditional. You can also put the <h1> tag within the conditional, and it would produce the same result.

When statements

The <when> tag functions similarly to switch statements in many programming languages.

<stateful id="stateful-root">
    
    <label for="when-select">When Value:</label>
    <select id="when-select">
        <option>0</option>
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
    </select>
    
    <when value="number">
        <case value="!0">
            <p>Zero</p>
        </case>
        <case value="!1">
            <p>One</p>
        </case>
        <case value="!2">
            <p>Two</p>
        </case>
        <case value="!3">
            <p>Three</p>
        </case>
        <else>
            <p>Other</p>
        </else>
    </when>
    
</stateful>

<script>
    const stateful = document.getElementById("stateful-root");
    const { state, setState } = stateful;

    setState({
        number: 0,
    });

    document.getElementById("when-select").onchange = e => {
        setState({
            whenValue: e.target.value,
        });
    }
    
</script>

This would initially render to

<label for="when-select">When Value:</label>
<select id="when-select">
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
</select>
<p>Zero</p>

and then would update whenever the selection changes.