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

@bhaireshm/zstate

v0.0.1

Published

A state management library using XState

Readme

zstate

The CRUDMachine is a versatile tool for managing data with Create, Read, Update, and Delete operations. It also supports undo and redo functionalities if versioning is enabled. Below is a step-by-step guide on how to use the CRUDMachine, including examples and customization options.

Step-by-Step Procedure

  1. Import the CRUDMachine:

    First, import the CRUDMachine and necessary types from the module.

    import { CRUDMachine } from "@bhaireshm/zstate";
    import type { CRUDOptions } from "@bhaireshm/zstate";
  2. Define Your Data Structure:

    Define the structure of the data you want to manage. For example, if you are managing a list of users:

    interface User {
      id: string;
      name: string;
      email: string;
    }
  3. Set Up CRUD Options:

    Create an options object to configure your CRUDMachine. You can specify initial data, enable versioning, and define custom transitions.

    const options: CRUDOptions<User[]> = {
      initialData: [],
      enableVersioning: true,
      maxVersions: 10,
      transitions: {
        customAction: (context, event) => {
          // Custom transition logic
          return {};
        },
      },
    };
  4. Initialize the CRUDMachine:

    Instantiate the CRUDMachine with the options defined.

    const userCRUD = new CRUDMachine(options);
  5. Perform CRUD Operations:

    Use the methods provided by the CRUDMachine to manipulate your data.

    • Create:

      userCRUD.create([{ id: "1", name: "John Doe", email: "[email protected]" }]);
    • Read:

      const user = userCRUD.read("0"); // Read the first user
    • Update:

      userCRUD.update([{ id: "1", name: "John Smith", email: "[email protected]" }]);
    • Delete:

      userCRUD.delete("0"); // Delete the first user
  6. Undo and Redo:

    If versioning is enabled, you can undo and redo changes.

    userCRUD.undo(); // Undo the last operation
    userCRUD.redo(); // Redo the last undone operation
  7. Subscribe to State Changes:

    You can subscribe to state changes to react to data updates.

    const unsubscribe = userCRUD.subscribe((state) => {
      console.log("State updated:", state);
    });
    
    // Call unsubscribe() when you no longer need to listen to updates
  8. Access Version History:

    Retrieve the version history if versioning is enabled.

    const history = userCRUD.getVersionHistory();
    console.log("Version History:", history);

Customization Options

  • Custom Transitions:

    You can define custom transitions in the transitions option to handle specific events.

  • Versioning:

    Enable versioning to keep track of changes and allow undo/redo operations.

  • Max Versions:

    Limit the number of versions stored to manage memory usage.

By following these steps, you can effectively use the CRUDMachine to manage your application's data with flexibility and control.