{"name":"debounce","version":"2.2.0","description":"Delay function calls until a set time elapses after the last invocation","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/debounce.git"},"funding":"https://github.com/sponsors/sindresorhus","exports":{"types":"./index.d.ts","default":"./index.js"},"main":"./index.js","types":"./index.d.ts","sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && node --test"},"keywords":["debounce","debouncing","function","throttle","invoke","limit","limited","interval","rate","batch","ratelimit"],"devDependencies":{"sinon":"^17.0.1","xo":"^0.56.0"},"xo":{"rules":{"unicorn/prefer-module":"off"}},"_id":"debounce@2.2.0","gitHead":"12050fccb40bc34c7b8d03067a12a7e9fb2266df","bugs":{"url":"https://github.com/sindresorhus/debounce/issues"},"homepage":"https://github.com/sindresorhus/debounce#readme","_nodeVersion":"22.6.0","_npmVersion":"10.6.0","dist":{"integrity":"sha512-Xks6RUDLZFdz8LIdR6q0MTH44k7FikOmnh5xkSjMig6ch45afc8sjTjRQf3P6ax8dMgcQrYO/AR2RGWURrruqw==","shasum":"f895fa2fbdb579a0f0d3dcf5dde19657e50eaad5","tarball":"http://registry-npm.ywwl.com/debounce/download/debounce-2.2.0.tgz","fileCount":5,"unpackedSize":7148,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGh5zTGCHQRD5nZoM8cPNlrlU4k/tTFyN7XmoJHvC86qAiEA2TGi3UK8zdPZ1lJ4OpDZu+pLw4U5+5FQRni3SQOb+JI="}],"size":3035,"noattachment":false,"key":"/debounce/-/debounce-2.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/debounce_2.2.0_1728923910988_0.7269666090014484"},"_hasShrinkwrap":false,"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\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","publish_time":1728923911183,"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_cnpm_publish_time":1728923911183,"dist-tags":{"latest":"4.0.0"}}