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

ruax

v1.8.14

Published

一个轻量级的Javascript异步数据请求库

Downloads

571

Readme

ruax

npm license

一个基于 fetch API 二次封装的轻量级 web 端异步数据请求库,更适合现代浏览器。

特性

  • 增加超时机制,在请求超过指定时间没有响应时抛出异常
  • 增加可取消机制,请求过程中可以随时取消请求
  • 增加进度监控,可以随时获取请求进度
  • 增加请求拦截和响应拦截,方便全局处理
  • 增加响应类型参数,针对不同响应类型对结果进行处理后传递
  • 增加基础路径配置,可针对每次请求使用公共的基础路径

安装

# npm
npm install ruax
npm install [email protected]   # 安装指定版本

# yarn
yarn add ruax
yarn add [email protected]

# pnpm
pnpm add ruax
pnpm add [email protected]

CDN 使用:

<!-- 引入固定版本 -->
<script src="https://unpkg.com/[email protected]/lib/ruax.umd.js"></script>
<!-- 始终引入最新版本 -->
<script src="https://unpkg.com/ruax/lib/ruax.umd.js"></script>
<!-- ES 模块方式 -->
<script type="module">
  import { Ruax } from 'https://unpkg.com/ruax/lib/ruax.es.js'
</script>

快速上手

import { Ruax } from 'ruax'

const ruax = new Ruax()

// 发送请求
const result = await ruax.create({
  url: '/xxx/xxx',
  method: 'post',
  body: JSON.stringify({
    name: '张三'
  })
})

CDN 引入时获取 Ruax 对象:

const { Ruax } = window.Ruax
// 或
const Ruax = window.Ruax.default

实例配置

通过 Ruax 实例属性设置全局默认值:

| 属性 | 类型 | 默认值 | 说明 | |------|------|--------|------| | baseUrl | string | '' | 请求基础地址 | | method | string | 'GET' | 请求方法 | | headers | HeadersInit | {} | 请求头 | | responseType | RuaxResponseType | 'json' | 响应类型,支持 json text blob arrayBuffer formData | | timeout | number | 3000 | 超时时间(ms) | | mode | RequestMode | 'cors' | 跨域行为 | | cache | RequestCache | 'default' | 缓存策略 | | beforeRequest | (options: RuaxCreateOptions) => RuaxCreateOptions | - | 请求拦截函数 | | beforeResponse | (response: Response, options: RuaxCreateOptions, data?: any) => Promise<any> \| any | - | 响应拦截函数 | | cancelRequest | (abortFun: typeof AbortController.prototype.abort) => void | - | 取消请求函数 | | onProgress | (value: number) => void | - | 进度监听函数(0-100) |

const ruax = new Ruax()
ruax.baseUrl = 'https://www.xxx.com/api'
ruax.timeout = 5000
ruax.beforeRequest = options => {
  options.headers['token'] = 'xxxx'
  return options
}
ruax.beforeResponse = (response, options, data) => {
  return data.data || []
}

API 方法

create(options)

发起一个请求,options 类型为 RuaxCreateOptionsWithInterceptor

create(options: RuaxCreateOptionsWithInterceptor): Promise<any>

post(url, body?)

快速发起一个 POST 请求。

post(url: string, body?: BodyInit): Promise<any>

get(url)

快速发起一个 GET 请求。

get(url: string): Promise<any>

文档

完整文档请参阅:https://www.so-better.cn/docs/ruax/

License

MIT