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

gs-web-hooks

v1.0.0

Published

一个轻量级库,为 Web 应用中的 `XMLHttpRequest` 和 `fetch` API 提供响应拦截器。它允许您在应用处理 HTTP 响应之前拦截和修改它们。

Downloads

61

Readme

gs-web-hooks

一个轻量级库,为 Web 应用中的 XMLHttpRequestfetch API 提供响应拦截器。它允许您在应用处理 HTTP 响应之前拦截和修改它们。

English

安装

yarn add gs-web-hooks

对于 XMLHttpRequest

import { addXhrInterceptor, removeXhrInterceptor } from 'gs-web-hooks';

// 添加拦截器
addXhrInterceptor({
  id: 'test-interceptor',
  modifyResponse: true,
  before: (url, method, body) => {
    // 返回 true 以拦截响应
    return true;
  },
  after: (text, beforeReturnValue, context) => {
    // 修改响应
    const data = JSON.parse(text);
    data.modified = true;
    return JSON.stringify(data);
  }
});

// 移除拦截器
removeXhrInterceptor('test-interceptor');

对于 fetch

import { addFetchInterceptor, removeFetchInterceptor } from 'gs-web-hooks';

// 添加拦截器
addFetchInterceptor({
  id: 'test-interceptor',
  modifyResponse: true,
  before: (url, method, body) => {
    // 返回 true 以拦截响应
    return true;
  },
  after: (text, beforeReturnValue, context) => {
    // 修改响应
    const data = JSON.parse(text);
    data.modified = true;
    return JSON.stringify(data);
  }
});

// 移除拦截器
removeFetchInterceptor('test-interceptor');

拦截器选项

  • id (必填): 拦截器的唯一标识符
  • modifyResponse (可选): 是否修改响应。默认为 true
  • weights (可选): 拦截器的权重。权重较高的拦截器先执行。默认为 0
  • before (必填): 在处理响应之前调用的函数。返回除 undefined 以外的值以拦截响应。参数:(url, method, body)
  • after (必填): 在收到响应后调用的函数。返回值以修改响应。参数:(text, beforeReturnValue, context)
  • onInterceptorError (可选): 当拦截器中发生错误时调用的函数
  • onStatusError (可选): 当发生状态错误时调用的函数(例如 404, 500)

API

// 为 XMLHttpRequest 添加拦截器
function addXhrInterceptor(interceptor: IInterceptor<XMLHttpRequest>): IRequiredInterceptor<XMLHttpRequest>[] {}

// 通过 ID 移除 XMLHttpRequest 的拦截器
function removeXhrInterceptor(id: string): void {}

// 为 fetch API 添加拦截器
function addFetchInterceptor(interceptor: IInterceptor<Response>): IRequiredInterceptor<Response>[] {}

// 通过 ID 移除 fetch API 的拦截器
function removeFetchInterceptor(id: string): void {}