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

request-state-wrapper

v1.0.0

Published

A tiny package for managing the state of asynchronous requests.

Downloads

35

Readme

Request State Wrapper

A small, less than 1kb gzipped, utility wrapper for Asynchronous JavaScript events.

It allows you to easily handle fetching, stalled and finished states.

Philosophy

The way we handle loading states in front end applications can be incredibly reptetive and imperative.

We also design loading states that aren't always the optimal user experience for all users. This means users with fast AND slow connections.

Request State Wrapper aims to solve the following problems.

  • Make it easy to detect stalled loading states so we can communicate to users on slower connections that the app is still working / not broken.
  • Make it easy to batch multiple requests together to avoid staggered UI updates.
  • Take the reptetive code required to handle loading states, and compose it into a single, declarative utility function. This helps keep our codebases DRY(Dont Repeat Yourself).

Usage

npm install --save request-state-wrapper
import { createRequest } from 'request-state-wrapper';

const yourAsyncFunction = () => 
    fetch('https://api.github.com/repos/nodejs/node').then(response => response.json());

// Create your request with request-state-wrapper
const request = createRequest({
    request: yourAsyncFunction,
    stalledDelay: 1000,
    onStalled: () => { /* handle stalled state */ },
});

// Run it!
request()
  .then(response => { /* handle request response */ })
  .catch(error => { /* handle request error */ });

Usage recipies

For more detailed implementation recipies see:

API

createRequest takes a single object argument.

const demoRequest = createRequest({ 
    request,
    stalledDelay,
    onStateChange,
    onFetching,
    onStalled,
    onFinished,
 })

Required

  • request - Function that returns a promise or Array of functions that return promises

Optional

  • stalledDelay - Time, in milliseconds, it takes for the request to be considered stalled (defaults to 1000)
  • onStateChange - Handler function that is called whenever the request state changes
  • onFetching - Handler function that is called whenever the request starts fetching
  • onStalled - Handler function that is called whenever the request state becomes stalled
  • onFinished - Handler function that is called whenever the request state finishes

createRequest returns a function that invokes the request. It takes a single argument, an object of options all of which are optional.

demoRequest({
    onStateChange,
    onFetching,
    onStalled,
    onFinished,
 })
  • onStateChange - Handler function that is called whenever the request state changes
  • onFetching - Handler function that is called whenever the request starts fetching
  • onStalled - Handler function that is called whenever the request state becomes stalled
  • onFinished - Handler function that is called whenever the request state finishes

Important:

  • Any options declared at request time will override options declared at creation time
  • onFetching, onStalled, onFinished take precedence over onStateChange