@github/mini-throttle

中文文档
2.1.1发布于 2023/08/09MITTypeScriptESM + CJS零依赖近 30 天下载 33万

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

中文使用文档

小型喉管

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

节奏 节奏 和一切之间

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 被调用。 最好的办法 用大理石图来说明这一点.

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 装饰器支持 !

这个包还包括一个可以用来提供 类型脚本装饰器 功能说明.

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

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 共发布 10 个版本,首次发布于 2019/05/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.1latest2023/08/093 年前
2.1.02021/02/235 年前
2.0.12020/03/256 年前
2.0.02020/03/256 年前
1.0.72019/11/067 年前
1.0.52019/08/067 年前

关于 @github/mini-throttle 的常见问题

@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 和提交记录判断。