{"id":28946698,"url":"https://github.com/dmitriz/rate-limiter","last_synced_at":"2025-08-02T03:38:54.729Z","repository":{"id":296492177,"uuid":"993570188","full_name":"dmitriz/rate-limiter","owner":"dmitriz","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-03T15:03:18.000Z","size":19,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-23T08:50:05.396Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmitriz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-05-31T03:32:37.000Z","updated_at":"2025-06-03T15:03:19.000Z","dependencies_parsed_at":"2025-05-31T15:15:34.155Z","dependency_job_id":"f4787b70-3e17-4cd3-ba43-673fae070f98","html_url":"https://github.com/dmitriz/rate-limiter","commit_stats":null,"previous_names":["dmitriz/rate-limiter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dmitriz/rate-limiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmitriz%2Frate-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmitriz%2Frate-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmitriz%2Frate-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmitriz%2Frate-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmitriz","download_url":"https://codeload.github.com/dmitriz/rate-limiter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmitriz%2Frate-limiter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268331457,"owners_count":24233252,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-06-23T08:42:11.983Z","updated_at":"2025-08-02T03:38:54.711Z","avatar_url":"https://github.com/dmitriz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minimal Rate Limiter\n\nThis package lets you easily limit how often a function can be called.\nIt is useful for things like sending emails, calling APIs, or any action you want to avoid running too often.\n\n## How does it work?\n\nYou \"wrap\" your function with a limiter.\nThe limiter keeps track of how many times your function was called in the last minute.\nIf you call it too many times, extra calls are automatically queued and will run as soon as allowed—no calls are lost or blocked.\n\n## Example\n\nSee [`example_email.js`](./example_email.js):\n\n```js\nconst { rate_limit_wrap } = require('./index');\n\nfunction send_email() {\n  console.log('Email sent!');\n}\n\n// Only allow 3 emails per 60,000ms (1 minute)\nconst limited_send_email = rate_limit_wrap(send_email, { max_per_window: 3, window_length: 60000 });\n\n(async () =\u003e {\n  for (let i = 1; i \u003c= 5; i++) {\n    await limited_send_email();\n    console.log(`Email ${i} sent.`);\n  }\n})();\n```\n\n## Why limit function calls?\n\n- Prevent spamming users (e.g., too many emails)\n- Stay within API rate limits\n- Avoid overloading your own system\n\n## How does it work inside?\n\n- Every time you call the wrapped function, the limiter checks how many times it was called in the last 60 seconds.\n- If you haven't reached the limit, your function runs immediately.\n- If you have, your call is added to a queue and will run as soon as allowed—no calls are lost or blocked.\n\n## Learn more\n\n- [Wikipedia: Rate limiting](https://en.wikipedia.org/wiki/Rate_limiting)\n- [Wikipedia: Token bucket (background)](https://en.wikipedia.org/wiki/Token_bucket)\n\n## API\n\n### `rate_limit_wrap(fn, { max_per_window, window_length })`\n\n- `fn`: The function you want to limit.\n- `max_per_window`: Maximum number of calls allowed within the time window.\n- `window_length`: Length of the time window in milliseconds (e.g., 60000 for 1 minute).\n\nReturns a new function.\nCall this new function instead of your original one.\n\n---\n\nThis is a minimal, dependency-free implementation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmitriz%2Frate-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmitriz%2Frate-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmitriz%2Frate-limiter/lists"}