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

statechart-lib

v1.0.4

Published

A TypeScript library for state chart management.

Readme

README.md for State Chart Library

State Chart Library

The State Chart Library is a TypeScript library designed to manage state machines and transitions between states. It provides a simple and intuitive API for defining states, transitions, and managing the state machine's behavior.

Installation

To install the State Chart Library, use npm:

npm install statechart-lib

Usage

Here’s a quick example of how to use the State Chart Library:

import State from './state';
import Transition from './transition';
import StateMachine from './machine';

// Define states
const idleState = new State({
  entering: () => console.log('Entering idle state')
});
const activeState = new State({
  entering: () => console.log('Entering active state')
});

// Define transitions
const transitionToActive = new Transition(activeState, {
  condition: () => true,
  action: () => console.log('Transitioning to active state')
});

// Create state machine
const stateMachine = new StateMachine([idleState, activeState]);

// Add transition to idle state
idleState.addTransition(activeState, {
  condition: () => true,
  action: () => console.log('Transitioning to active state')
});

// Update state machine
stateMachine.update();

API

Classes

  • State: Represents a state in the state machine.

    • Properties:
      • entering: A function to be called when entering the state.
      • within: A function to be called while within the state.
      • exiting: A function to be called when exiting the state.
      • current: The current state.
      • states: An array of sub-states.
      • transitions: An array of transitions.
    • Methods:
      • addTransition(state: State, options: TransitionOptions): Adds a transition to the state.
      • run(): Executes the state machine logic.
  • Transition: Defines a transition between states.

    • Properties:
      • to: The target state.
      • condition: A function that returns a boolean indicating whether the transition should occur.
      • action: A function to be called when the transition occurs.
  • StateMachine: Manages the state machine.

    • Properties:
      • states: An array of states.
      • current: The current state.
    • Methods:
      • update(): Updates the state machine by running the current state's logic.

Advanced Usage

Nested States

You can define nested states by adding sub-states to a state:

const subState = new State({
  entering: () => console.log('Entering subState')
});
idleState.states.push(subState);

Conditional Transitions

Transitions can have conditions that must be met for the transition to occur:

const conditionalTransition = new Transition(activeState, {
  condition: () => someCondition,
  action: () => console.log('Transitioning based on condition')
});
idleState.addTransition(activeState, {
  condition: () => someCondition,
  action: () => console.log('Transitioning based on condition')
});

Actions on Transitions

You can define actions to be executed when a transition occurs:

const actionTransition = new Transition(activeState, {
  condition: () => true,
  action: () => console.log('Action on transition')
});
idleState.addTransition(activeState, {
  condition: () => true,
  action: () => console.log('Action on transition')
});

Running Tests

To run the tests for the State Chart Library, use the following command:

npm test

Building the Library

  1. Run npm run test to run the tests.
  2. Update the version number in the package.json file.
  3. Commit and push the changes to the repository.
  4. Run git tag -a v1.0.x -m "Version 1.0.x" to tag the release.
  5. Run git push origin v1.0.x to push the tag to the repository.

The package will be automatically published to npm using GitHub Actions.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.