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

@vhall/utils-fetch

v1.0.2

Published

微吼请求模块,兼容V2、V3、V4

Readme

Fetch

Fetch请求库封装

概要:

根据现有逻辑,重构fetch模块

  1. npm统一维护,抽离所有子应用;
  2. 逻辑梳理,结构调整、内置拦截器;
  3. 完整url请求校验;
  4. 内置响应拦截除401跳转登录地址之外,其余情况Promise对象结果返回;

实例化后提供的 函数钩子

  • start 请求唯一入口,返回请求Promise对象
  • setRequestBefore 经过fetch处理后请求前的回调函数,回调参数为请求参数config(自定义拦截器后失效)
  • setApiConfig 设置请求配置 [url, method]
  • setNoNeedPrompt 设置code非200,不需要message提示接口msg字段的url数组(全匹配校验)

vh-fetch提供与axios保持一致的用法及api

  • 实例化时的初始化config配置
  • 默认设置,如defaults.timeout、defaults.baseURL等
  • request
  • get
  • post
  • delete
  • head
  • put
  • patch
  • all并发请求
  • interceptors.request.use() 设置请求拦截器
  • interceptors.response.use() 设置响应拦截器
  • interceptors.request.eject() 取消请求拦截器
  • interceptors.response.eject() 取消响应拦截器

使用

npm 安装

npm i vh-fetch

引入使用:

import Fetch from 'vh-fetch'
const fetch = new Fetch([config])

设置api配置

const MAP = {
    test: ['URL', 'POST']
}
fetch.setApiConfig(MAP)

设置需要拦截过滤的api地址

const noNeedPrompt = [
     '/console/cut/get-vod-info',
]
fetch.setNoNeedPrompt(noNeedPrompt)

请求入口:

fetch.start(api, data, headers)

完整案例:

附:远期优化方案

  • 前后端接口相互调整,响应拦截中msg提示条件的优化,目前前端维护成本较高、提取后新人了解比较难。