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

@fetchx/fetcher-core

v0.1.11

Published

Fetcher core without actual network transport.

Readme

@fetchx/fetcher-core

Fetcher 核心实现,不带 transport,这样可以在多端环境下使用,支持:

  1. Web
  2. Node
  3. 小程序 Taro

FAQ

拦截器最佳实践

拦截器的核心调用是 fetcher.interceptRequest|Response(interceptor),但一个拦截器的最佳方式是让使用者无忧使用,即使用拦截器的开发者, 不应知道这个拦截器用在何处。因此,一个拦截器最佳的输出方式是一个接收 Fetcher 实例的方法。

同时,一个拦截器可以有默认选项,所以建议写成 createInterceptor(options): FetcherIntercept__,并且把参数暴露给 intercept 方法。

以下,我们以添加日志(Log)为例,附上相关代码(注意这里为了说明方便,都写在了一起):

import {
  Fetcher,
  FetcherConfig,
  FetcherIntercept__
} from '@fetchx/fetcher-core';

export interface IFetcherConfigLog {
  logTitle?: string;
}

export interface IFetcherConfigAugmentedLog extends FetcherConfig, IFetcherConfigLog {}

export interface IInterceptLogOptions {
  // ...
}

function createInterceptorResponseFulfilled(options: IInterceptLogOptions): FetcherIntercept__ {}

export default function interceptLog(fetcher: Fetcher, options?: IInterceptLogOptions, priority?: number): () => void {
  return fetcher.interceptResponse(createInterceptorResponseFulfilled(options), undefined, priority);
}

export type {
  IFetcherConfigLog as FetcherConfigLog,
  IInterceptLogOptions as InterceptLogOptions
};

最佳实践:

  1. 尽量仅依赖 @fetchx/fetcher-core
  2. 仅输出 intercept 方法,接收 fetcher: Fetcher 为第一参数,可以额外添加别的参数
  3. 拦截器方法使用工厂方法创建,这样可以允许传配置
  4. 若对 FetcherConfig 有类型扩展,则输出 FetcherConfigXx(这里 Xx 代表拦截器的名字,仅含扩展部分)

为什么在 Response 的 headers 里获取不到某 header?

自定义 Header 需要显式地暴露,后端需要添加 Access-Control-Expose-Headers。