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

@clownlee/cores

v1.0.13

Published

公共核心库,提供统一的 HTTP 请求能力和自动 token 刷新功能

Readme

@clownlee/request

Axios 公共通用库,提供统一的 HTTP 请求能力和自动 token 刷新功能。

功能特性

  • ✅ TypeScript 支持
  • ✅ baseUrl、headers 等配置封装
  • ✅ 请求拦截器和响应拦截器
  • ✅ 支持所有 HTTP 方法(get、post、put、patch、delete 等)
  • ✅ 手动终止请求功能
  • ✅ 自动添加 Bearer token
  • ✅ 401 时自动刷新 token(通过 refreshToken)

安装

npm install @clownlee/request

使用示例

import { init } from '@clownlee/request'
import { useUserStore } from '@/stores/user'

const userStore = useUserStore()

const http = init({
  store: userStore, // pinia 实例
  baseUrl: 'https://api.example.com',
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json'
  },
  refresh: {
    baseUrl: 'https://api.example.com', // 一般情况 = 最外层的 baseUrl
    path: '/api/v1/auth/refresh',
    name: 'Authorization', // 请求头名称
    token: userStore.refreshToken // 通过 pinia localStorage 存储的 refreshToken 值
  }
})

// 使用 HTTP 方法
const data = await http.get('/api/users')
const result = await http.post('/api/users', { name: 'John' })
await http.put('/api/users/1', { name: 'Jane' })
await http.patch('/api/users/1', { name: 'Jane' })
await http.delete('/api/users/1')

API

init(config)

初始化 HTTP 实例。

参数

  • config.store: Pinia store 实例,用于存储和获取 token
  • config.baseUrl: 接口域名
  • config.timeout: 超时时间(毫秒)
  • config.headers: 请求头信息
  • config.refresh: Token 刷新配置
    • refresh.baseUrl: 刷新接口域名
    • refresh.path: 刷新接口路径
    • refresh.name: 请求头名称(默认为 'Authorization')
    • refresh.token: refreshToken 值

返回值

返回 HTTP 实例,包含以下方法:

  • get(url, params?, config?)
  • post(url, data?, config?)
  • put(url, data?, config?)
  • patch(url, data?, config?)
  • delete(url, config?)
  • request(config)
  • createCancelToken(): 创建取消令牌
  • cancelRequest(cancelToken, message?): 手动终止请求