# @github/mini-throttle 中文文档

规范地址：https://npmcn.com/package/%40github/mini-throttle/

版本：2\.1\.1
npm 元数据更新时间：2026-10-15T16:20:53.514Z
中文译文更新时间：2026-11-16T10:49:10.438Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40github/mini-throttle
原文对照：https://npmcn.com/package/%40github/mini-throttle/?lang=original
项目主页：https://github.com/github/mini-throttle#readme
源码仓库：https://github.com/github/mini-throttle

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：15.1 kB，16 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2019-05-22T09:00:26.585Z
- 最新版本发布：2023-08-08T20:19:42.661Z
- 近 30 天下载量：329532（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：10（近 12 个月 0 个）

## 中文简介

这是提供 `throttle` 财务报告和审定财务报表 `debounce` 函数,包括流式和类型脚本声明,以及最小的代码脚印(小于60行,小于350个字节的缩写+gzipped)

## 安装

```sh
npm install @github/mini-throttle
```

也可以使用：`pnpm add @github/mini-throttle`、`yarn add @github/mini-throttle`、`bun add @github/mini-throttle`

## README

# 小型喉管

这是提供 `throttle` 财务报告和审定财务报表 `debounce` 函数,两者兼具 流程和类型脚本声明,以及最小的代码脚印(小于60个) 线条,小于 350 字节已修改+gzipped)

### 节奏 节奏 和一切之间

```js
type ThrottleOptions = {
  start?: boolean, // fire immediately on the first call
  middle?: boolean, // if true, fire as soon as `wait` has passed
  once?: boolean, // cancel after the first successful call
}
function throttle<T>(
  callback: (...args: T[]) => any,
  wait: number,
  opts?: ThrottleOptions
): (...args: T[]) => void

function debounce<T>(
  callback: (...args: T[]) => any,
  wait: number,
  opts?: ThrottleOptions
): (...args: T[]) => void
```

这个软件包有两个功能; `throttle` 财务报告和审定财务报表 `debounce`。 。 。 .

这两个功能都提供了完全相同的签名,因为两者都是 相同的功能 - 只是与不同的 `opts` 默认 :

-   `throttle` 选择默认为 `{ start: true, middle: true, once: false }`。 。 。 .
-   `debounce` 选择默认为 `{ start: false, middle: false, once: false }`。 。 。 .

每个选项在 `callback` 被调用。 最好的办法 用大理石图来说明这一点.

```js
for (let i = 1; i <= 10; ++i) {
  fn(i)
  await delay(50)
}
await delay(100)
```

```
| fn()                                         | 1 2 3 4 5 6 7 8 9 10 |
| throttle(fn, 100)                            | 1 2   4   6   8   10 |
| throttle(fn, 100, {start: false})            |   2   4   6   8   10 |
| throttle(fn, 100, {middle: false})           | 1                 10 |
| throttle(fn, 100, {once: true})              | 1                    |
| throttle(fn, 100, {once: true, start: false})|   2                  |
| debounce(fn, 100)                            |                   10 |
```

### TypeScript 装饰器支持 !

这个包还包括一个可以用来提供 [类型脚本装饰器](https://www.typescriptlang.org/docs/handbook/decorators.html#decorators) 功能说明.

这是一个例子,显示你需要做什么:

```typescript
import {throttle} from '@github/mini-throttle/decorators'
//                                           ^ note: add `/decorators` to the import to get decorators

class MyClass {
  @throttle(100, { start: false }) // <- Just like normal throttle, but you omit the callback argument
  doThings() {
    // `MyClass.prototype.doThings` will be throttled!
  }
}
```

## 常见问题

### @github/mini-throttle 是什么？

这是提供 throttle 财务报告和审定财务报表 debounce 函数,包括流式和类型脚本声明,以及最小的代码脚印\(小于60行,小于350个字节的缩写\+gzipped\)

### 如何安装 @github/mini-throttle？

在项目目录运行 npm install @github/mini-throttle，或使用 pnpm add / yarn add / bun add。

### @github/mini-throttle 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @github/mini-throttle 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @github/mini-throttle 可以商用吗？

@github/mini-throttle 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @github/mini-throttle 的下载量有多少？

根据 npm 官方下载统计，@github/mini-throttle 在 2026/10/17 – 2026/11/15 这 30 天内被下载 329,532 次，日均约 10,984 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @github/mini-throttle 还在维护吗？

最新版本 2\.1\.1 发布于 2023/08/09（3 年前）；至今共发布 10 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/05/22。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

