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

stimulus-if

v0.4.0

Published

Stimulus controller for declarative dynamic form flows

Readme

Stimulus If

Stimulus controller for declarative dynamic form flows: show an element only while a condition on a form field holds.

Install

npm install stimulus-if

Register it under the identifier if:

import { Application } from "@hotwired/stimulus"
import IfController from "stimulus-if"

const application = Application.start()
application.register("if", IfController)

Usage

Put a condition on any element inside a form:

<form>
  <input type="checkbox" name="shipping" value="1">

  <div data-if="shipping is checked">
    <input type="text" name="address">
  </div>
</form>

The <div> and its inputs appear when the checkbox is checked, and are hidden and disabled otherwise — so concealed fields are left out of the submission. The condition is re-evaluated on every change event in the form.

data-if is shorthand (via stimulus-shorthand) for the full Stimulus declaration:

<div data-controller="if" data-if-condition-value="shipping is checked">

Conditions

A condition is three space-separated parts: <field> <operation> <value>. The field name and operation cannot contain spaces; the value can.

| Operation | Meaning | Example | | --- | --- | --- | | == | field value equals the value | data-if='role == "admin"' | | != | field value does not equal the value | data-if='role != "admin"' | | in | field value is in the list | data-if='role in ["admin","owner"]' | | is | DOM property on the field is true | data-if="shipping is checked" | | not | DOM property on the field is not true | data-if="shipping not checked" |

Values for == and in are parsed as JSON, so strings need quotes — which is why these examples wrap the attribute in single quotes.

Values for is and not are property names read off the field element, such as checked, disabled, or readOnly.

Fields in another form

By default the field is looked up in the nearest ancestor <form>. Prefix the field name with a form name to look it up elsewhere:

<form name="order">
  <select name="role">…</select>
</form>

<div data-if='order.role == "admin"'>…</div>

Supported fields

Text inputs, selects, radio groups, single checkboxes, and checkbox groups are all supported, including the hidden-input-plus-checkbox pairs that Rails' check_box helper emits — an unchecked box falls back to the hidden input's value rather than reading as empty.

For a group of checkboxes sharing one name, is/not ask whether any box in the group is checked, in matches when any checked box is in the list, and the group's value is its checked values joined by commas:

<input type="checkbox" name="tags" value="a">
<input type="checkbox" name="tags" value="b">

<div data-if="tags is checked">…</div>
<div data-if='tags in ["b","c"]'>…</div>
<div data-if='tags == "a,b"'>…</div>

Development

npm install
npm test

License

ISC