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

aifsmjs

v0.5.9

Published

Small, strict FSM library for deterministic, replayable state machines in any TypeScript/JS app — multi-step forms, checkout funnels, auth flows, tutorials, scene flow. Pure step() lifecycle, opt-in effects, inspect, replay, and a fast-check property-base

Readme

aifsmjs

Small deterministic FSM library for replayable TypeScript/JavaScript state machines. Definitions are plain data; guards/actions/effects are injected at runtime.

Status: 0.5.9 - stable 1.0-track core. Core FSM, guards, effects, inspect, replay, PBT helpers, scheduler, and sub-machines are live.

Install

pnpm add aifsmjs
import { assign, createRuntime, setup } from "aifsmjs";

Quick Start

type Ctx = { ticks: number };
type Evt = { type: "NEXT" };

const trafficLight = setup<Ctx, Evt>().defineMachine({
  id: "trafficLight",
  initial: "red",
  context: { ticks: 0 },
  states: {
    red: { on: { NEXT: { target: "green", actions: ["bump"] } } },
    green: { on: { NEXT: { target: "yellow", actions: ["bump"] } } },
    yellow: { on: { NEXT: { target: "red", actions: ["bump"] } } },
  },
});

const runtime = createRuntime(trafficLight, {
  actions: {
    bump: assign(({ context }) => ({ ticks: context.ticks + 1 })),
  },
});

runtime.send({ type: "NEXT" });
console.log(runtime.getSnapshot().value); // "green"

Prefer setup<Ctx, Evt>().defineMachine() for state inference. Use bare defineMachine<Ctx, Evt, States>() only when you need explicit generic control.

Public Surface

| Import | Purpose | | --- | --- | | aifsmjs | setup, defineMachine, createRuntime, createMachine, step, assign, snapshots, runtime/errors/types. | | aifsmjs/guards | and, or, not, stateIn. Guards must be synchronous. | | aifsmjs/effects | enqueue.effect() descriptors and runEffects(). | | aifsmjs/inspect | Read-only middleware helpers: logger, persist, recorder. | | aifsmjs/replay | Pure event-log replay. | | aifsmjs/pbt | fast-check property helpers. | | aifsmjs/timer | after() and createScheduler(). |

Lifecycle Rules

  • step(def, snapshot, event, impl) is pure and returns { snapshot, effects, changed }.
  • createRuntime() owns mutable runtime state, dispatches effects after commit, and emits transition/error/dispose events.
  • Guards and reducers are sync. Thenable guards throw AsyncGuardError.
  • Effects are fire-and-forget descriptors. Async rejection is routed to the runtime "error" channel.
  • reset() rewinds the snapshot and notifies listeners, but does not run entry actions.
  • dispose() is idempotent; post-dispose send()/reset() throw RuntimeDisposedError.

Sharp Edges

  • Middleware and synchronous effect throws happen after snapshot commit. A throw can leave the committed snapshot visible without later notification.
  • Sub-machine replacement can roll back on init failure, but dispose failure has already torn down the old child.
  • subRuntime() can return a disposed child handle if external code disposed it; it is recreated only after the parent exits and re-enters the sub state.
  • setup().defineMachine() uses NoInfer so states infer from keyof states; keep regression tests for exact optional property configurations.
  • Do not perform async I/O inside guards or actions. Send events from effects instead.

AI Context

License

MIT