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

@web_xiaobai/request

v0.0.1

Published

多项目通用的 axios 封装:可注入 `getToken` / `refreshToken`、401 排队刷新、重复请求取消、失败重试、URL 与前缀拼接等(合并自 VAxios 实用能力,无业务路径依赖)。

Readme

@web_xiaobai/request

多项目通用的 axios 封装:可注入 getToken / refreshToken、401 排队刷新、重复请求取消、失败重试、URL 与前缀拼接等(合并自 VAxios 实用能力,无业务路径依赖)。

安装

pnpm add @web_xiaobai/request axios

基础用法

import { createRequest, SKIP_AUTH_REFRESH, ContentTypeEnum } from "@web_xiaobai/request"
import to from "await-to-js"

const request = createRequest({
  baseURL: import.meta.env.VITE_API_BASE,
  authenticationScheme: "Bearer",
  withCredentials: true,
  headers: { "Content-Type": ContentTypeEnum.Json },
  getToken: () => localStorage.getItem("access_token"),
  refreshToken: async client => {
    const { data } = await client.post(
      "/auth/refresh",
      { refreshToken: localStorage.getItem("refresh_token") },
      SKIP_AUTH_REFRESH
    )
    localStorage.setItem("access_token", data.accessToken)
    return { accessToken: data.accessToken }
  },
  onUnauthorized: () => router.push("/login"),
  onForbidden: () => message.error("暂无权限"),
  skipRefreshUrls: ["/auth/refresh"],
  requestOptions: {
    joinTime: true,
    formatDate: true,
    ignoreCancelToken: false,
    retry: { count: 0, delay: 1000 }
  },
  // 按后端约定解包 { code, data, msg }
  transformRequestHook: res => {
    const body = res.data as { code: number; data: unknown; msg?: string }
    if (body.code === 200) return body.data
    throw new Error(body.msg ?? "请求失败")
  }
})

const [err, data] = await to(request.get({ url: "/api/user" }))

从 VAxios 合并的能力

| 能力 | 说明 | |------|------| | beforeRequestHook | apiUrl / urlPrefix、GET 时间戳、params→data | | ignoreCancelToken | false 时同 URL 新请求会 abort 上一个(AbortController) | | retry | 非 401/403 失败按次数延迟重试 | | transformRequestHook | 成功响应数据转换 | | get/post/put/delete/patch/upload | 便捷方法 | | request.cancelAll() | 取消所有 pending | | request.getAxios() | 拿原始 AxiosInstance |

脚本

pnpm lib:request