{"id":17625145,"url":"https://github.com/martinstark/throttle-ts","last_synced_at":"2025-04-13T18:40:51.647Z","repository":{"id":45403773,"uuid":"317598983","full_name":"martinstark/throttle-ts","owner":"martinstark","description":"Correctly typed, generic, typescript throttle function","archived":false,"fork":false,"pushed_at":"2025-03-24T23:29:28.000Z","size":872,"stargazers_count":9,"open_issues_count":11,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-27T09:21:55.203Z","etag":null,"topics":["throttle","typescript"],"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/martinstark.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-01T16:19:11.000Z","updated_at":"2024-11-20T20:13:37.000Z","dependencies_parsed_at":"2023-02-15T22:01:10.115Z","dependency_job_id":"c0ed5cba-8979-4923-950c-b36f13d900e7","html_url":"https://github.com/martinstark/throttle-ts","commit_stats":{"total_commits":191,"total_committers":4,"mean_commits":47.75,"dds":"0.40314136125654454","last_synced_commit":"225032a661288a30779f81635de03b8f759445a7"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinstark%2Fthrottle-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinstark%2Fthrottle-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinstark%2Fthrottle-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinstark%2Fthrottle-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinstark","download_url":"https://codeload.github.com/martinstark/throttle-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248764344,"owners_count":21158068,"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":["throttle","typescript"],"created_at":"2024-10-22T22:08:16.283Z","updated_at":"2025-04-13T18:40:51.629Z","avatar_url":"https://github.com/martinstark.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# throttle-ts\n\nCorrectly typed, generic, tiny ([419B](https://bundlephobia.com/package/throttle-ts@1.4.0)), typescript throttle function.\n\n```typescript\nconst fn = (str: string, num: number) =\u003e `hello ${str} ${num}`;\n\nconst [throttled, cancel, reset] = throttle(fn, 500);\n\nthrottled(\"world\", 1);\n```\n\nYields the return value of the throttled function, or undefined when throttled/cancelled.\n\nThe throttled function keeps the type signature of the original function, plus `undefined`.\n\n![image](https://github.com/user-attachments/assets/d806ab04-1a7b-42a7-907e-44168a3b0988)\n\nReturns a `cancel` function which enables cleanup of the timeout, and blocks future calls to the throttled function. Useful when unmounting (react) ui components.\n\nReturns a `reset` function which enables clearing the timeout, letting you call the method again before the delay has expired.\n\n### Usage\n\n```bash\nnpm i throttle-ts\n```\n\n```javascript\nimport { throttle } from \"throttle-ts\";\n```\n\n```javascript\nconst fn = () =\u003e \"executed\";\n\nconst [throttledFn] = throttle(fn, 200);\n\nthrottledFn(); // \"executed\"\nthrottledFn(); // undefined\nthrottledFn(); // undefined\nsetTimeout(throttledFn, 500); // \"executed\"\n```\n\n### Using Cancel\n\n```javascript\nconst fn = () =\u003e \"executed\";\n\nconst [throttledFn, cancel] = throttle(fn, 200);\n\nthrottledFn(); // \"executed\"\nsetTimeout(throttledFn, 500); // undefined\ncancel(); // blocks all future calls to the throttled function\n```\n\n### Using Reset\n\n```javascript\nconst fn = () =\u003e \"executed\";\n\nconst [throttledFn, _, reset] = throttle(fn, 200);\n\nthrottledFn(); // \"executed\"\nthrottledFn(); // undefined\nreset(); // reset delay timeout\nthrottledFn(); // \"executed\"\nthrottledFn(); // undefined\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinstark%2Fthrottle-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinstark%2Fthrottle-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinstark%2Fthrottle-ts/lists"}