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

small-state-machine

v4.2.1

Published

Small and simple state machine

Readme

Small State Machine

State machine with simple syntax and usage.

TypeScript example:

import SmallStateMachine from 'small-state-machine'

enum States {
    Sunshine = 'Sunshine',
    Rain = 'Rain',
}

enum Triggers {
    makeClouds = 'make clouds',
    dispelClouds = 'dispel clouds',
}

const machine = new SmallStateMachine<States, Triggers>( States.Sunshine );

// Define transitions between sunshine and rain,
// and run actions when entering/exiting sunshine
machine.configure( States.Sunshine )
    .onEntry( () => console.log( 'Let there be light!' ) )
    .onExit( () => console.log( 'I will be back!' ) )
    .permit( Triggers.makeClouds, States.Rain );
machine.configure( States.Rain )
    .permit( Triggers.dispelClouds, States.Sunshine );

// Transition back to sunshine after one second
machine.addAutoTransition( States.Rain, States.Sunshine, Triggers.dispelClouds, 1000 );

// Do something when the state changes
machine.onStateChange( ( state ) => console.log( `Now in state ${state}!` ) );

// Trigger a state change
machine.fire( Triggers.makeClouds );

Changelog

  • v4.2.1 (2026-02-03)
    • Added: SmallStateDescription.describe('I am a state') adds a text description to states
    • Changed: Dependencies updated
  • v4.1.0 (2025-12-04)
    • Added: SmallStateMachine.addAutoTransition(from, to, trigger, timeout) and stopAllAutoTransitions() to automatically continue to a new state after a timeout.
  • v4.0.0 (2024-12-05)
    • Added: Log level is now configurable
    • Breaking: SmallStateDescription requires a Logger object. This is only relevant when you extended this class.
  • v3.3.0 (2024-08-24)
    • Added: States can now have multiple onEntry and onExit callbacks
    • Added: Callbacks can have an optional name
  • v3.2.0 (2023-01-06)
    • Added: Initial state is now exposed on StateMachine.initialState
    • Changed: Code documentation improved
  • v3.1.0 (2022-09-27)
    • Added: Expose logger for subclasses extending SmallStateMachine
  • v3.0.0 (2022-07-06)
    • Breaking: onEntry() handlers now see the new (entered) state as current state. Prior to this version, SmallStateMachine.currentState was still set on the old state which hase been exited.
  • v2.2.0
    • Added: Transitions can now have descriptions.
    • Added: SmallStateMachine.transitionMap() returns states with the corresponding transitions, allowing to get information about the state machine configuration.
  • v2.1.0
    • Added: Transition can now have optional guard functions (conditions) which check if the transition should be taken. A state can have multiple transitions with the same trigger when all use guard functions.
    • Fixed: When reset()ting, the onExit of the old state and the onEnter of the initial state are now called.
  • v2.0.0
    • Breaking: Constructor now takes a parameters object as second parameter to provide additional options like logger.
    • Added: The state machine can be configured not to throw if a trigger has not been configured on a state.
    • Added: The reset() command resets the state machine to the initial state. This is useful when using the state machine e.g. in the context of a state chart.
  • v1.4.0
    • Added: Option for using a logger like pino
    • Fixed: The StateMachine.currentState is now the target state in the onStateChange event.
  • v1.3.0
    • Added default export for SmallStateMachine
    • Improved error message on nested fire() calls
  • v1.2.2
    • Added source code documentation.
  • v1.2.0 – 2021-04-13
    • Added SmallStateMachine.onStateChange to listen to state changes
    • Changed: Switch to jest for unit testing, remove non-dev dependencies
  • v1.1.0 – 2021-03-29
    • Changed: whenFired throws if the transition has no target state.
    • Changed: Dependencies updated, moved @types/jasmine to dev dependencies