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 🙏

© 2024 – Pkg Stats / Ryan Hefner

st-state

v1.0.0

Published

Nano library for client-side state management and persistency

Downloads

2

Readme

Nano library for client-side state management and persistency

Gitter

This is an exremely tiny, yet powerful library for global state management. st-state can also save and load state from/to sessionStorage and localStorage.

  • ✅ Abstracts the HTML5 local/sessionStorage API
  • ✅ Tiny: 187 bytes (best, brotli) - 313 bytes (worst, umd, gz)
  • ✅ Zero dependencies
  • ✅ First class TypeScript support
  • ✅ 100% Unit Test coverage
  • ✅ TestCafé smoke tests

This is how using st-state looks like:

import { tsx, render, Ref } from 'springtype';
import { $ } from 'st-query';
import { store } from 'st-state';

const RANDOM_NUMBERS = 'randomNumbers';

const RandomNumbersList = () => {
  return <fragment>
    {state.get(RANDOM_NUMBERS).map((randomNumber) => <p>{randomNumber}</p>)}
  </fragment>
}

const App = () => {

  const randomNumberListRef: Ref = {};

  // remember randomNumbers generated before
  const defaultRandomNumbers = store.load(RANDOM_NUMBERS, []);

  // current randomNumbers state, possibly initialized by remembered ones
  const randomNumbers: Array<number> = store.get(RANDOM_NUMBERS, defaultRandomNumbers);

  const onGenerateRandomNumber = () => {

    // updating the state locally
    randomNumbers.push(Math.random());

    // setting the state gobally
    store.set(RANDOM_NUMBERS, randomNumbers);

    // also persisting the state for re-visits
    store.save(RANDOM_NUMBERS);

    // re-render the UI
    $(randomNumberListRef.current).html(<RandomNumbersList />);
  }

  return (
    <fragment>
      <h3>Random numbers:</h3>

      <div ref={randomNumberListRef}>
        <RandomNumbersList />
      </div>

      <button onClick={onGenerateRandomNumber}>
        Generate random number
      </button>
    </fragment>
  );
};
render(<App />);

The following contract is made between the webapp and st-state:

export interface State {
  [key: string]: any;
}

export interface API {
  state: State;
  get(key: string, defaultValue?: any): any;
  set(key: string, value: any): API;
  load(key: string, defaultValue?: any): any;
  save(key: string): API;
  loadForSession(key: string, defaultValue?: any): any;
  saveForSession(key: string): API;
}

Thank you so much for supporting us financially! 🙏🏻😎🥳👍

st-state is brought to you by:

Please help out to make this project even better and see your name added to the list of our CONTRIBUTORS.md :tada: