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 🙏

© 2025 – Pkg Stats / Ryan Hefner

state-pilot

v1.0.1

Published

A library designed to simplify state management in your JavaScript or TypeScript applications.

Readme

Build Status

codecov

state-pilot

State Pilot - a library designed to simplify state management in your JavaScript or TypeScript applications. With State Pilot, you can manage an application's lifecycle state, subscribe to changes in your data stores, and trigger custom named actions.

The aim of this open source project is to create a highly flexible and reliable state management tool that delivers an intuitive interface for integration and ease of use. Contributions are welcome to this project.

dev

build the ts file

npm run build

test the code

npm run test

usage

Adding State Pilot into your application

  import { StatePilot } from 'state-pilot';

Create a new store inside your application.

  // @param string stateStoreName declare a name for your store
  // @param boolean useHistory (optional | defaults to false) will keep record of changes
  // @returns new store
  statePilot.createStore(stateStoreName, useHistory);

Add a new state to a store.

  // @params string stateStoreName store
  // @params object state data 
  // @returns new store state
  statePilot.createStoreState(stateStoreName, state);

Get a stores most recent state.

  // @returns currrent store state
  statePilot.getStoreState();

get a stores state history from a range of past events.

  // @params string stateStoreName
  // @params number startIndex
  // @params number lastIndex
  // @returns store state history from range
  statePilot.getStoreStateHistory(stateStoreName, startIndex, lastIndex);

get a stores entire state history.

  // @params string stateStoreName
  // @returns all store state history
  statePilot.getAllStoreStateHistory(stateStoreName);

import all stores (from a previously exported store).

  // @params object store provide a valid store object from previous session
  // @returns object store
  statePilot.importStore(store);

export all stores.

  // @returns object store
  statePilot.exportStore();

subscribe to a store.

  const unSubUserSettings = statePilot.subscribe('userSettings', data => console.log('user settings store updated', data));
  // triggered event will be caught by the subscribers call back
  statePilot.createStoreState('userSettings', { darkMode: true, lang: 'en-us' });

subscribe to a store and read from action data.

  statePilot.triggerStoreAction.SET_DARK_MODE(true);
  // action data can be found within the actionData of a call back
  const unSubUserSettings = statePilot.subscribe('userSettings', (state) => {
    if(state.storeAction === "SET_DARK_MODE") console.log(state.actionData)
  });

create store action to provide for more descriptive state change triggers.

  // @params string name unique name of the action e.g. "DARK_MODE_TOGGLE"
  // @params string store store to update
  // @params string subStoreKey points to the sub state key you wish to update e.g. store['darkMode']
  // @params Function fn this is the custom function logic applied e.g. function(s) { return !s } will reverse a booleans the state
  // @params boolean isAsync if the call back fn is async or not
  // @returns void
  statePilot.createStoreAction(name, store, subStoreKey, fn, isAsync);

create store actions as an array.

  // @params string name unique name of the action e.g. "DARK_MODE_TOGGLE"
  // @params string store store to update
  // @params string subStoreKey points to the sub state key you wish to update e.g. store['darkMode']
  // @params Function fn this is the custom function logic applied e.g. function(s) { return !s } will reverse a booleans the state
  // @params boolean isAsync if the call back fn is async or not
  // @returns void
  statePilot.createStoreActions(
    [
      {
        name
        store
        subStoreKey
        fn
        isAsync
      }
    ]
  );

unsubscribe from a store subscription variable instance.

  // @description unsubscribe from single subscription
  unSubUserSettings();

unsubscribe from an entire store.

  // @description unsubscribe all subscribers from a store
  statePilot.unsubscribe('userSettings');

example use of library


  import { StatePilot } from 'state-pilot';

  // create new instance of statePilot
  const statePilot = new statePilot();
  
  // create stores
  statePilot.createStore('userSettings', true);
  statePilot.createStore('viewNavigation', true);

  // add a view state
  statePilot.createStoreState('viewNavigation', { path: '/home', name: 'home' });
  
  // add a user settings state
  statePilot.createStoreState('userSettings', { darkMode: true });

  // create a store action
  statePilot.createStoreAction('TOGGLE_DARK_MODE', 'userSettings', 'darkMode', function(s) { return !s });
  
  // add some subscriptions to listen for changes
  const unSubscribeUserSettings = statePilot.unsubscribe('userSettings', data => { /* do something with data */ });
  const unSubscribeVieNavigation = statePilot.unsubscribe('viewNavigation', data => { /* do something with data */ }););

  // invoke state changes to be recieved by subscribers
  statePilot.createStoreState('viewNavigation', { path: '/contact', name: 'contact' });
  
  // invoke state change via triggerStoreAction to be recieved by subscribers
  statePilot.triggerStoreAction.TOGGLE_DARK_MODE(statePilot.getStoreState('userSettings').darkMode);