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

@typepurify/fetch

v0.5.11

Published

A lightweight wrapper around native fetch that automatically purifies API responses.

Readme


npm version License: MIT

🚀 Overview

@typepurify/fetch provides a robust, zero-dependency tFetch wrapper around the native fetch API. It natively integrates with typepurify to automatically deeply clean your API JSON responses while strictly retaining TypeScript types.

📦 Installation

npm install @typepurify/fetch typepurify

🛠 Features & Usage

1. Auto-Purifying Requests

Automatically drops null and undefined properties from your API payloads.

import { tFetch } from '@typepurify/fetch';

interface UserPayload {
  id: number;
  name: string;
  age: number | null;
}

// 1. Fetch data and automatically clean it
const user = await tFetch<UserPayload>('https://api.example.com/user');

// => { id: 1, name: "Alice" }
// 'age' is stripped because it was null!

2. Built-in Interceptors, Retries & Timeouts

tFetch ships with advanced networking features typically requiring bulky libraries like Axios.

import { tFetch } from '@typepurify/fetch';

const data = await tFetch(
  'https://api.example.com/data',
  {},
  {
    timeout: 5000, // Abort after 5s
    onTimeout: (req) => console.warn('Request timed out: ', req.url), // Custom timeout handler
    retries: 3, // Auto-retry on failure
    retryDelay: 1000, // Exponential backoff delay
    interceptors: {
      onRequest: (req) => {
        req.init = { ...req.init, headers: { Authorization: 'Bearer Token' } };
        return req;
      },
      onResponse: (res) => {
        console.log(`Received status: ${res.status}`);
        return res;
      },
    },
  },
);

3. Ultra-Fast cleanParse

Set useCleanParse: true to bypass the intermediate object allocation of JSON.parse for up to 25% faster data fetching on massive payloads.

const largeData = await tFetch(
  'https://api.example.com/heavy',
  {},
  {
    useCleanParse: true,
    stripEmptyArrays: true,
  },
);

4. Query Parameter Construction

Elegantly construct URL query strings from complex nested objects and arrays.

import { buildQueryString } from '@typepurify/fetch';

const query = buildQueryString({ filters: ['active', 'verified'], limit: 10 });
// => "?filters=active,verified&limit=10"

5. HTTP/3 Transport Adapter

Throttle requests using an HTTP/3 QUIC connection pool adapter.

import { Http3TransportAdapter } from '@typepurify/fetch';

const adapter = new Http3TransportAdapter({ maxConcurrentStreams: 50 });
const data = await adapter.fetch('https://api.example.com/data');

3. Response Caching (createCacheFetch)

import { createCacheFetch } from '@typepurify/fetch';

const cachedFetch = createCacheFetch({ ttlMs: 60000 });
const data = await cachedFetch('https://api.example.com/data');

6. Rate Limiter Fetch (createRateLimiterFetch) — v0.5.4

Throttle outgoing HTTP requests to a configurable maximum rate to avoid overwhelming APIs.

import { createRateLimiterFetch } from '@typepurify/fetch';

const rateFetch = createRateLimiterFetch(5); // max 5 requests/sec
await rateFetch('https://api.example.com/items');

🆕 New in v0.5.8

parseFetchPayload(response) — Auto Payload Parser

Automatically detects the content-type header and returns parsed JSON or raw text.

import { parseFetchPayload } from '@typepurify/fetch';

const res = await fetch('https://api.example.com/data');
const data = await parseFetchPayload(res);
// => parsed JSON object if content-type is application/json

createConnectionPoolerFetch(maxConnections) — Connection Pooler

Limits concurrent outbound fetch calls using a semaphore queue.

import { createConnectionPoolerFetch } from '@typepurify/fetch';

const poolFetch = createConnectionPoolerFetch(5); // max 5 concurrent
const data = await poolFetch('https://api.example.com/data');

📋 Changelog

v0.5.4 — Latest

New Features:

  • createRateLimiterFetch(maxPerSec) — Wraps native fetch with a token-bucket rate limiter preventing burst overload to downstream APIs.

Bug Fixes:

  • Added console.error logging inside RequestQueue.processQueue() catch block for socket hangup errors — previously swallowed silently, now surfaced for easier debugging.
  • Abort controller connection errors no longer cause queue deadlock.

v0.5.3

  • Added createCacheFetch for lightweight in-memory response caching with custom TTL.

v0.5.2

  • Added Http3TransportAdapter for HTTP/3 QUIC connection management.
  • Fixed socket hangup / connection abort errors in RequestQueue to prevent queue deadlock.

v0.5.1

  • Added buildQueryString for elegant query parameter construction.

📄 License

MIT © Vallarasu Kanthasamy

0.5.8 Updates

Includes new features.