{"id":13451874,"url":"https://github.com/github/mini-throttle","last_synced_at":"2025-05-14T19:03:06.096Z","repository":{"id":37549864,"uuid":"187205323","full_name":"github/mini-throttle","owner":"github","description":"A small JavaScript throttle \u0026 debounce implementation.","archived":false,"fork":false,"pushed_at":"2025-02-20T18:15:23.000Z","size":377,"stargazers_count":214,"open_issues_count":1,"forks_count":15,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-06T08:09:31.641Z","etag":null,"topics":["debounce","throttle","utility"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/github.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-17T11:32:54.000Z","updated_at":"2025-02-20T18:15:19.000Z","dependencies_parsed_at":"2025-01-31T05:10:27.262Z","dependency_job_id":"765e5c6b-a60f-4549-a1f5-138228fff90f","html_url":"https://github.com/github/mini-throttle","commit_stats":{"total_commits":44,"total_committers":9,"mean_commits":4.888888888888889,"dds":"0.43181818181818177","last_synced_commit":"7fb6f52c98c735fe44f6096c8bddd051976d3ae0"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fmini-throttle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fmini-throttle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fmini-throttle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Fmini-throttle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github","download_url":"https://codeload.github.com/github/mini-throttle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248710404,"owners_count":21149185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debounce","throttle","utility"],"created_at":"2024-07-31T07:01:05.415Z","updated_at":"2025-04-13T11:45:35.151Z","avatar_url":"https://github.com/github.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","JavaScript"],"sub_categories":[],"readme":"# mini-throttle\n\nThis is a package which provides `throttle` and `debounce` functions, with both\nflow and TypeScript declarations, and a minimal code footprint (less than 60\nlines, less than 350 bytes minified+gzipped)\n\n\n### throttling, debouncing, and everything inbetween\n\n```js\ntype ThrottleOptions = {\n  start?: boolean, // fire immediately on the first call\n  middle?: boolean, // if true, fire as soon as `wait` has passed\n  once?: boolean, // cancel after the first successful call\n}\nfunction throttle\u003cT\u003e(\n  callback: (...args: T[]) =\u003e any,\n  wait: number,\n  opts?: ThrottleOptions\n): (...args: T[]) =\u003e void\n\nfunction debounce\u003cT\u003e(\n  callback: (...args: T[]) =\u003e any,\n  wait: number,\n  opts?: ThrottleOptions\n): (...args: T[]) =\u003e void\n```\n\nThis package comes with two functions; `throttle` and `debounce`.\n\nBoth of these functions offer the exact same signature, because they're both\nthe same function - just with different `opts` defaults:\n\n - `throttle` opts default to `{ start: true, middle: true, once: false }`.\n - `debounce` opts default to `{ start: false, middle: false, once: false }`.\n\nEach of the options changes when `callback` gets called. The best way to\nillustrate this is with a marble diagram.\n\n```js\nfor (let i = 1; i \u003c= 10; ++i) {\n  fn(i)\n  await delay(50)\n}\nawait delay(100)\n```\n```\n| fn()                                         | 1 2 3 4 5 6 7 8 9 10 |\n| throttle(fn, 100)                            | 1 2   4   6   8   10 |\n| throttle(fn, 100, {start: false})            |   2   4   6   8   10 |\n| throttle(fn, 100, {middle: false})           | 1                 10 |\n| throttle(fn, 100, {once: true})              | 1                    |\n| throttle(fn, 100, {once: true, start: false})|   2                  |\n| debounce(fn, 100)                            |                   10 |\n```\n\n### TypeScript Decorators Support!\n\nThis package also includes a decorator module which can be used to provide [TypeScript Decorator](https://www.typescriptlang.org/docs/handbook/decorators.html#decorators) annotations to functions.\n\nHere's an example, showing what you need to do:\n\n```typescript\nimport {throttle} from '@github/mini-throttle/decorators'\n//                                           ^ note: add `/decorators` to the import to get decorators\n\nclass MyClass {\n  @throttle(100, { start: false }) // \u003c- Just like normal throttle, but you omit the callback argument\n  doThings() {\n    // `MyClass.prototype.doThings` will be throttled!\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fmini-throttle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub%2Fmini-throttle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Fmini-throttle/lists"}