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

fetch-for-redux

v2.0.0

Published

fetches ajax responses suitable for dispatching in a redux action

Readme

What is it?

A wrapper around fetch which changes the behavior in the following ways:

Difference #1

Instead of an instance of Response, fetch-for-redux resolves with a POJO representation of a response suitable for dispatching as part of an action. Here's an example response from the github api.

{
  "status": 200,
  "headers": {
    //_other_headers_not_shown
    "content-type": "application/json; charset=utf-8"
  },
  "body": {
    "login": "gavacho",
    "id": 106077,
    "avatar_url": "https://avatars.githubusercontent.com/u/106077?v=3",
    "gravatar_id": "",
    "url": "https://api.github.com/users/gavacho",
    "html_url": "https://github.com/gavacho",
    "followers_url": "https://api.github.com/users/gavacho/followers",
    "following_url": "https://api.github.com/users/gavacho/following{/other_user}",
    "gists_url": "https://api.github.com/users/gavacho/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/gavacho/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/gavacho/subscriptions",
    "organizations_url": "https://api.github.com/users/gavacho/orgs",
    "repos_url": "https://api.github.com/users/gavacho/repos",
    "events_url": "https://api.github.com/users/gavacho/events{/privacy}",
    "received_events_url": "https://api.github.com/users/gavacho/received_events",
    "type": "User",
    "site_admin": false,
    "name": "Ken Browning",
    "company": "HauteLook",
    "blog": null,
    "location": "Los Angeles",
    "email": null,
    "hireable": null,
    "bio": null,
    "public_repos": 30,
    "public_gists": 9,
    "followers": 15,
    "following": 6,
    "created_at": "2009-07-17T18:03:11Z",
    "updated_at": "2016-05-16T22:41:21Z"
  }
}

The response object has three properties: status, headers & body.

The status property will always be a javascript Number.

The headers property will always be a javascript Object with lowercased header names as keys and an array of Strings as values.

The body property will be a String unless the response's Content-Type header indicates a JSON response.

Difference #2

A response is always resolved, even when fetch would have rejected (e.g. when the network has dropped).

{
  "status": 0,
  "headers": {},
  "body": "request to https://api.github.com/users/gavacho failed, reason: getaddrinfo ENOTFOUND api.github.com api.github.com:443"
}

Motivation

I wanted to keep decision logic (about how to handle ajax responses) in reducers because reducers are very easy to test. I also wanted testing with fixture responses to be very simple.

// example action creator

export default fetchWidgets() {
  // assumes usage of redux-thunk
  return (dispatch) => {
    dispatch({
      type: 'WIDGETS_REQUEST_SENT',
    });

    fetchForRedux(widgetsUrl).then(response => dispatch({
      type: 'WIDGETS_RESPONSE_RECEIVED',
      payload: { response },
    }));
  };
};


// example reducer

const initialState = {
  isFetching: false,
  widgets: [],
  errorMessage: null,
};

export default function someReducer(state = initialState, action = {}) {
  switch(action.type) {
    case 'WIDGETS_REQUEST_SENT':
      return {
        ...state,
        isFetching: true,
      };

    case 'WIDGETS_RESPONSE_RECEIVED':
      // Here we can inspect the status code to
      // know what kind of response we received.
      if (action.payload.response.status === 200) {
        return {
          ...state,
          isFetching: false,
          widgets: action.payload.response.body.widgets,
          errorMessage: null,
        };
      }

      return {
        ...state,
        isFetching: false,
        errorMessage: 'Oops!  Something didn\'t work...  Wanna try again?',
      };

    default:
      return state;
  }
}

CHANGELOG

v2.0.0

Breaking Changes
  • The fetch spec was updated to specify how headers with the same name/key should be combined into a single header value. This library will now return responses with single values for headers instead of an array of values.