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

@xlong/request

v1.0.2

Published

wangxiaolong utils

Readme

@xlong/request

用于请求的封装

安装

npm install @xlong/request 
yarn add @xlong/request 
pnpm add @xlong/request 

使用方法

  • 基本用法
import request, { compile, data, get, initConfig, post, toast } from '@xlong/request'
// 初始化位置
initConfig({
  baseURL,
  IS_DEBUG: true,
})

//  get/post 请求
const result: AxiosResponse = await get<Data>(path, params)
const result2: AxiosResponse = await post<Data>(path, bodys)
  • 添加拦截器
import request, { compile, data, get, initConfig, post, toast } from '@xlong/request'

const interceptorOne = ({ request }: any) => {
  request.use(
    async (config: InternalAxiosRequestConfig) => {
      return config
    },
    async (error: AxiosResponse) => Promise.reject(error),
  )
}
const interceptorTwo = ({ response }: any) => {
  response.use(
    (response: AxiosResponse) => {
      return response
    },
    async (response: any) => {
      return Promise.reject(response)
    },
  )
}

initConfig({
  baseURL,
  IS_DEBUG: true,
  // 数据处理
  dataInterceptor: true, // 默认 true
  // 自定义拦截器
  interceptors: [interceptorOne, interceptorTwo],
  // 登陆拦截器,自动判断 token 
  loginInterceptorConfig: {
    PAGE_LOGIN, // 跳转到登陆页面
    ERROR_LOGIN_CODE, // 接口登陆失效 code
    NETWORK_ERROR_TIP, // '请求失败...'
    STORAGE_LOGIN_KEY, // 'STORAGE_LOGIN_KEY'
  },
})
  • 添加登陆过滤
import request, { compile, data, get, initConfig, post, toast } from '@xlong/request'

initConfig({
  baseURL,
  IS_DEBUG: true,
  // 登陆拦截器,自动判断 token 
  loginInterceptorConfig: {
    PAGE_LOGIN, // 跳转到登陆页面
    ERROR_LOGIN_CODE, // 接口登陆失效 code
    NETWORK_ERROR_TIP, // '请求失败...'
    STORAGE_LOGIN_KEY, // 'STORAGE_LOGIN_KEY'
  },
})

// 跳过 API_LOGIN 接口登陆检查
addApiSkipInterceptor(API_LOGIN)

// 移除(跳过 API_LOGIN 接口登陆检查)
removeApiSkipInterceptor(API_LOGIN)



  • 数据处理和toast提示
import request, { compile, data, get, initConfig, post, toast } from "@xlong/request";

initConfig({
  baseURL,
  IS_DEBUG: true,
  message: (dataMessage) => message.toast(dataMessage)
});
// data 返回 response.data
// toast  message.toast(dataMessage)
const result: any = await post(API_LOGIN)
  .then(data, toast)
  .catch((err) => err);


方法

  • initConfig: (config: Config, callback?: ((axiosInstance: AxiosInstance) => void) | undefined) => void
  • data: <D = unknown>(data: ReturnData) => Promise
  • compile: (path: string, params?: D | undefined) => string;
  • toast: (data: ReturnData) => Promise;
  • post: <T, D = unknown>(url: string, data?: D | undefined, config?: AxiosRequestConfig) => Promise;
  • get: <T, D = unknown>(url: string, params?: D | undefined, config?: AxiosRequestConfig) => Promise;

类型

import Axios, { CreateAxiosDefaults } from 'axios';

export interface ReturnData<D> {
  code: number;
  msg: string;
  data: D;
}

export interface LoginInterceptorConfig {
  STORAGE_LOGIN_KEY?: string;
  PAGE_LOGIN: string;
  NETWORK_ERROR_TIP?: string;
  ERROR_LOGIN_CODE?: number;
}

export interface Config extends CreateAxiosDefaults {
  IS_DEBUG?: boolean;
  message?: (dataMessage: string) => unknown;
  interceptors?: Interceptor | Interceptor[];
  dataInterceptor?: boolean;
  loginInterceptorConfig?: LoginInterceptorConfig;
}

export type Params<F> = F extends (params: infer R) => unknown ? R : unknown;
export type Interceptor = (params: typeof Axios.interceptors) => void;