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-wrangler

v1.0.2

Published

State management, made easy.

Readme

State Wrangler

State Wrangler is a light-weight state management tool meant to work with React state libraries, like Redux or React's own Context API.

Installation

npm i state-wrangler --save or yarn add state-wrangler

Using in your reducer

import with: import StateManager from 'state-wrangler'; and in your reducer, declare the following, with your initial state object as the only argument: const state = new StateManager(initialState);

import StateManager from 'state-wrangler';
import constants from './appConstants';
import _ from 'lodash';

const initial = {
  [constants.STATE_KEY_NOTIFICATIONS]: [],
};

const reducer = (initialState = initial, action = {}) => {
  const { payload } = action;
  const state = new StateManager(initialState);

  switch(action.type) {
    case constants.SAMPLE_ACTION:
      return state.update(constants.STATE_KEY_SAMPLE_SELECTOR, payload);

    case constants.ADD_NOTIFICATION:
      return state.add(constants.STATE_KEY_NOTIFICATIONS, payload);

    case constants.REMOVE_NOTIFICATION:
      const index = payload;
      return state.remove(constants.STATE_KEY_NOTIFICATIONS, index);

    case constants.SAMPLE_API_CALL:
      return state.update(constants.STATE_KEY_SAMPLE_API_RESPONSE, payload);

    default:
      return initialState;
  }
};

export default reducer;

About StateManager()

State updates are handled in an immutable manner, see StateManager() in src/package/stateManager.jsStateManager(), is made to be user friendly. It is intelligent enough to know if the state key being modified is a basic type, such as a string or number, or more complex, like an Array or Object. Meaning you won't have to call methods such as state.getIn(), state.setIn() etc. to update something like an array.

Modifying state: basic or complex key values in state

state.get(STATE_KEY_TO_GET): Returns the value from the target key in state. state.add(STATE_KEY_TO_ADD, payload): Adds a completely new key to state with payload. state.update(STATE_KEY_TO_UPDATE, payload): Replaces existing state key with payload. state.remove(STATE_KEY_TO_REMOVE): Removes state key, completely.

Modifying state: arrays

state.get(STATE_KEY_TO_GET, index): Returns the value of the index from the targeted state key array. state.add(STATE_KEY_TO_ADD, payload, index): Adds new item to state key array with payload. state.update(STATE_KEY_TO_UPDATE, payload, index): Updates specific index of state key array with payload. state.remove(STATE_KEY_TO_REMOVE, index): Removes specific index from state key array.

Modifying state: objects

state.get(STATE_KEY_TO_GET, "keyName"): Returns the value of the key from the targeted state key object. state.add(STATE_KEY_TO_ADD, payload, "keyName"): Adds new key to state key object with payload as value. state.update(STATE_KEY_TO_UPDATE, payload, "keyName"): Updates specific key of state key object with payload as value. state.remove(STATE_KEY_TO_REMOVE, "keyName"): Removes specific key from state key object.

Modifying multiple state values

There are times where you may need to alter multiple state values at once, this can be done with state.merge(), using an array as the only argument that contains object with the following keys: { method, key, payload }.

  • method: update, remove, or add are the only valid values — get is has no application in a merge operation.
  • key: the key name, as a string, of the state key you are targeting.
  • payload: the new value of the key defined above — please note the remove method does not require a payload.

Additional Note: Due to the complexity of the merge operation, drilling in to nested objects or arrays to target specific nested keys or indices is not supported. It is recommended to handle this ahead of time, either from your server response, or in your application before the payload hits the reducer for merging with other payloads.

state.merge([
  { method: 'add', key: STATE_KEY_TO_ADD, payload },
  { method: 'update', key: STATE_KEY_TO_UPDATE, payload },
  { method: 'remove', key: STATE_KEY_TO_REMOVE },
]);