Skip to content

Statecharts.sh Documentation

Welcome to the statecharts.sh documentation.

Statecharts.sh is a TypeScript-first library for building statecharts — an extension of finite state machines with hierarchy, concurrency, and communication.

Terminal window
npm install statecharts.sh
import { chart } from "statecharts.sh";
const trafficLight = chart({
context: {},
initial: "red",
states: {
red: { on: { TIMER: "green" } },
green: { on: { TIMER: "yellow" } },
yellow: { on: { TIMER: "red" } },
},
});
const instance = trafficLight.start();
instance.send("TIMER"); // → green