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

sequence-request

v1.0.3

Published

A lightweight TypeScript library for handling request deduplication.

Readme

Request Manager

Publish to npm codecov

Overview

A lightweight TypeScript library for handling request deduplication. Only the latest request's result will be returned, previous requests' results will be ignored. Note that this does not actually cancel the underlying requests - they continue to execute in the background.

Features

  • Request Deduplication: Automatically ignores results from superseded requests when a new one is made
  • Error Handling: Properly handles errors from the latest request while ignoring errors from superseded requests
  • TypeScript Support: Full TypeScript type definitions
  • Lightweight: Minimal overhead with no external dependencies
  • Easy to Use: Simple API that wraps any async function

Installation

npm install seq-request

Usage

Basic Usage

import { RequestManager } from 'seq-request';

const requestManager = new RequestManager();

// Wrap your async function
const wrappedRequest = requestManager.wrap(async (id: string) => {
  const response = await fetch(`/api/data/${id}`);
  return response.json();
});

// Use the wrapped function
const result = await wrappedRequest('123');

Handling Multiple Requests

const requestManager = new RequestManager();
const wrappedRequest = requestManager.wrap(async (id: string) => {
  await new Promise(resolve => setTimeout(resolve, 1000)); // Simulate slow request
  return `Result for ${id}`;
});

// First request (result will be ignored)
const promise1 = wrappedRequest('1');
// Second request (result will be ignored)
const promise2 = wrappedRequest('2');
// Third request (result will be returned)
const promise3 = wrappedRequest('3');

const [result1, result2, result3] = await Promise.all([promise1, promise2, promise3]);
console.log(result1); // null (superseded)
console.log(result2); // null (superseded)
console.log(result3); // "Result for 3" (latest request)

Error Handling

const requestManager = new RequestManager();
const wrappedRequest = requestManager.wrap(async () => {
  throw new Error('Request failed');
});

try {
  await wrappedRequest();
} catch (error) {
  console.error('Latest request failed:', error.message);
}

API Reference

RequestManager

Constructor

new RequestManager()

Creates a new RequestManager instance.

Methods

wrap(requestFn: Function)

Wraps a function to add request deduplication functionality.

Parameters:

  • requestFn - The function to wrap (can be async or sync)

Returns:

  • A wrapped function that ignores results from superseded requests

Behavior:

  • Only the most recent call to the wrapped function will return its result
  • Previous calls will return null (for successful requests) or be ignored (for failed requests)
  • Errors from the latest request are properly thrown
  • Errors from superseded requests are ignored
  • Important: The underlying requests are not actually cancelled - they continue to execute in the background

Examples

Search Input with Debouncing

const requestManager = new RequestManager();
const searchAPI = requestManager.wrap(async (query: string) => {
  const response = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
  return response.json();
});

// User types quickly
searchAPI('a');     // Result ignored
searchAPI('ab');    // Result ignored
searchAPI('abc');   // Only this result is returned

Form Submission

const requestManager = new RequestManager();
const submitForm = requestManager.wrap(async (formData: FormData) => {
  const response = await fetch('/api/submit', {
    method: 'POST',
    body: formData
  });
  return response.json();
});

// Prevent multiple submissions from returning results
const result = await submitForm(formData);

Important Notes

  • No Actual Cancellation: This library does not cancel the underlying requests. They continue to execute in the background, which means:
    • Network requests will still complete
    • Server-side operations will still run
    • Resources may still be consumed
  • Result Filtering: The library only filters which results are returned to your application
  • Use Cases: Best suited for scenarios where you want to ignore stale results, not for resource management

Development

Install Dependencies

pnpm install

Run Tests

npm run test

Build

npm run build

Development Mode

npm run dev

Feature improve

  • [ ] Enable to cancel older request
  • [ ] Add request timeout support
  • [ ] Add request retry mechanism
  • [ ] Add request caching support

License

MIT