{"_id":"debounce@4.0.0","bugs":{"url":"https://github.com/sindresorhus/debounce/issues"},"dist":{"shasum":"63de5ae349506abf1e386df099b9dba52d1299ce","tarball":"http://registry-npm.ywwl.com/debounce/download/debounce-4.0.0.tgz","fileCount":5,"integrity":"sha512-o6nMNFRtqLR6mRlyt0b21cgYPSKAEMZFpROIRS9ZRH6hhSJWvGErqeSCJnWyiwVQYMSw7f/DZLilF5YRDwFz7w==","signatures":[{"sig":"MEUCIQD/qmM10TtbfWK05Tc/ACnMA2j2TW3FK7SRNQ+DcKpDsgIgM3BaH1ywTGKKzuMROZyY4HnEMJj/LnDKP3kiJf/SGJs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIC3+4hyHZKOepn1JSPJ75/EVXPxvfoooIV4c3srNGYWlAiEAyAyBoTRyoRAGPRBpwK5JQAXS6tOGMLuNvg8ShZxd7R4="}],"unpackedSize":12895,"size":4909,"noattachment":false,"key":"/debounce/-/debounce-4.0.0.tgz"},"name":"debounce","type":"module","types":"./index.d.ts","engines":{"node":">=22.2"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"56dde2942b4501aee41f5c7d0f94a0985f1709e7","license":"MIT","scripts":{"test":"xo && node --test && nz"},"version":"4.0.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"homepage":"https://github.com/sindresorhus/debounce#readme","keywords":["debouncing","function","throttle","invoke","limit","limited","interval","rate","batch","rate-limit"],"repository":{"url":"git+https://github.com/sindresorhus/debounce.git","type":"git"},"_npmVersion":"12.2.0","description":"Delay function calls until a set time elapses after the last invocation","directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"sideEffects":false,"_nodeVersion":"26.12.1","_hasShrinkwrap":false,"devDependencies":{"nz":"^0.1.1","xo":"^5.0.1","typescript":"^6.0.3"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/debounce_4.0.0_1794684523233_0.5656531619334502"},"readme":"# debounce\n\n> 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\nconst onResize = debounce(resize, 200);\nwindow.addEventListener('resize', onResize);\n```\n\nTo check if the debounce delay is currently active:\n\n```js\nonResize.isPending;\n```\n\nTo later clear the timer and cancel currently scheduled executions:\n\n```js\nonResize.clear();\n```\n\nExecute a pending call immediately (and clear the timer). Does nothing when there is no call waiting to run, which leaves any timer as it was:\n\n```js\nonResize.flush();\n```\n\nTo execute immediately and clear the timer if it was previously set:\n\n```js\nonResize.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\nThe `wait` is in milliseconds and defaults to `100`.\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 a call is waiting to run then it is run immediately and the timer is cleared. Otherwise nothing happens and any timer is left as it was. In `immediate` mode, the calls made during the wait do not run on their own, but `.flush()` runs the last of them.\n- `.trigger()` executes the function immediately and clears the timer if it was previously set. With no call waiting to run it still calls the function, with no arguments and no receiver.\n\n### Errors\n\n`debounce()` throws a `TypeError` if the first parameter is not a function, or if `options` is a boolean. It throws a `RangeError` if `wait` is negative, `NaN`, larger than the largest delay a timer can wait for, or a value that does not compare as a number such as a non-numeric string.\n\n### Using it in a class\n\nOne debounced function shares one timer between all its callers. If you put it on a prototype, all instances share it, so calls from different instances within one wait collapse into one and the others are silently dropped. Give each instance its own debounced function instead:\n\n```js\nclass Widget {\n\tonResize = debounce(() => {\n\t\tconsole.log('width', this.width);\n\t}, 200);\n}\n```\n\n## Related\n\n- [debounce-fn](https://github.com/sindresorhus/debounce-fn) - Similar but with more options like `maxWait` and `before`/`after`\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","publish_time":1794684523324,"_cnpm_publish_time":1794684523324,"dist-tags":{"latest":"4.0.0"}}