{"id":14155985,"url":"https://github.com/sindresorhus/debounce","last_synced_at":"2025-04-08T23:08:36.841Z","repository":{"id":10188792,"uuid":"12277886","full_name":"sindresorhus/debounce","owner":"sindresorhus","description":"Delay function calls until a set time elapses after the last invocation","archived":false,"fork":false,"pushed_at":"2024-10-14T16:38:35.000Z","size":47,"stargazers_count":793,"open_issues_count":1,"forks_count":80,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-10-29T15:46:25.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.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":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2013-08-21T18:23:25.000Z","updated_at":"2024-10-28T05:50:13.000Z","dependencies_parsed_at":"2023-11-13T13:42:18.497Z","dependency_job_id":"176f0d08-49d1-462a-a739-4cb39c702e24","html_url":"https://github.com/sindresorhus/debounce","commit_stats":{"total_commits":52,"total_committers":18,"mean_commits":2.888888888888889,"dds":0.7692307692307692,"last_synced_commit":"12050fccb40bc34c7b8d03067a12a7e9fb2266df"},"previous_names":["sindresorhus/debounce","component/debounce"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fdebounce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fdebounce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fdebounce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fdebounce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/debounce/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247492783,"owners_count":20947588,"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":[],"created_at":"2024-08-17T08:05:08.134Z","updated_at":"2025-04-08T23:08:36.820Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["others","JavaScript"],"sub_categories":[],"readme":"# debounce\n\n\u003e Delay function calls until a set time elapses after the last invocation\n\n## Install\n\n```sh\nnpm install debounce\n```\n\n## Usage\n\n```js\nimport debounce from 'debounce';\n\nfunction resize() {\n\tconsole.log('height', window.innerHeight);\n\tconsole.log('width', window.innerWidth);\n}\n\nwindow.onresize = debounce(resize, 200);\n```\n\n*(You can also use `const debounce = require('debounce')`)*\n\nTo check if the debounce delay is currently active:\n\n```js\nwindow.onresize.isPending;\n```\n\nTo later clear the timer and cancel currently scheduled executions:\n\n```js\nwindow.onresize.clear();\n```\n\nTo execute immediately only if you have scheduled invocations and reset the timer:\n\n```js\nwindow.onresize.flush();\n```\n\nTo execute immediately and reset the timer if it was previously set:\n\n```js\nwindow.onresize.trigger();\n```\n\n## API\n\n### debounce(fn, wait, options?)\n\nCreates a debounced function that delays execution until `wait` milliseconds have passed since its last invocation.\n\nSet the `immediate` option to `true` to execute the function immediately at the start of the `wait` interval, preventing issues such as double-clicks on a button.\n\nThe returned function has the following methods:\n\n- `.isPending` indicates whether the debounce delay is currently active.\n- `.clear()` cancels any scheduled executions.\n- `.flush()` if an execution is scheduled then it will be immediately executed and the timer will be cleared.\n- `.trigger()` executes the function immediately and clears the timer if it was previously set.\n\n## Related\n\n- [p-debounce](https://github.com/sindresorhus/p-debounce) - Similar but handles promises\n- [throttleit](https://github.com/sindresorhus/throttleit) - Throttle a function to limit its execution rate\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fdebounce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fdebounce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fdebounce/lists"}