{"_id":"perfect-debounce","_rev":"4194863","name":"perfect-debounce","description":"<!-- automd:badges color=yellow codecov bundlephobia packagephobia  -->","dist-tags":{"latest":"2.1.0"},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"time":{"modified":"2026-03-02T02:52:54.000Z","created":"2022-03-14T19:27:22.970Z","2.1.0":"2026-01-21T23:47:33.457Z","2.0.0":"2025-08-22T21:24:14.956Z","1.0.0":"2023-05-03T23:17:12.783Z","0.1.3":"2022-03-16T09:47:44.803Z","0.1.2":"2022-03-15T20:45:55.741Z","0.1.1":"2022-03-15T15:56:03.741Z","0.1.0":"2022-03-15T15:31:17.647Z","0.0.1":"2022-03-15T15:30:49.571Z","0.0.0":"2022-03-14T19:27:22.970Z"},"users":{},"repository":{"type":"git","url":"git+https://github.com/unjs/perfect-debounce.git"},"versions":{"2.1.0":{"name":"perfect-debounce","version":"2.1.0","description":"<!-- automd:badges color=yellow codecov bundlephobia packagephobia  -->","repository":{"type":"git","url":"git+https://github.com/unjs/perfect-debounce.git"},"license":"MIT","sideEffects":false,"type":"module","exports":{".":"./dist/index.mjs"},"main":"./dist/index.mjs","module":"./dist/index.mjs","types":"./dist/index.d.mts","scripts":{"build":"obuild","dev":"vitest dev","lint":"eslint . && prettier --check src test","lint:fix":"eslint . --fix && prettier -w src test","release":"pnpm test && pnpm build && changelogen --release --push && npm publish","test":"vitest run --coverage"},"devDependencies":{"@types/node":"^25.0.10","@vitest/coverage-v8":"^4.0.17","automd":"^0.4.2","changelogen":"^0.6.2","eslint":"^9.39.2","eslint-config-unjs":"^0.6.2","in-range":"^3.0.0","obuild":"^0.4.18","prettier":"^3.8.1","time-span":"^5.1.0","typescript":"^5.9.3","vitest":"^4.0.17"},"packageManager":"pnpm@10.28.1","gitHead":"d3f83001dad6faa2090bd1aadab7312843fe6b79","_id":"perfect-debounce@2.1.0","bugs":{"url":"https://github.com/unjs/perfect-debounce/issues"},"homepage":"https://github.com/unjs/perfect-debounce#readme","_nodeVersion":"24.11.1","_npmVersion":"11.6.2","dist":{"shasum":"e7078e38f231cb191855c3136a4423aef725d261","size":3779,"noattachment":false,"key":"/perfect-debounce/-/perfect-debounce-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/perfect-debounce/download/perfect-debounce-2.1.0.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/perfect-debounce_2.1.0_1769039253320_0.49426584142687435"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-01-21T23:47:33.457Z","publish_time":1769039253457,"_source_registry_name":"default","_cnpm_publish_time":1769039253457},"2.0.0":{"name":"perfect-debounce","version":"2.0.0","description":"<!-- automd:badges color=yellow codecov bundlephobia packagephobia  -->","repository":{"type":"git","url":"git+https://github.com/unjs/perfect-debounce.git"},"license":"MIT","sideEffects":false,"type":"module","exports":{".":"./dist/index.mjs"},"main":"./dist/index.mjs","module":"./dist/index.mjs","types":"./dist/index.d.mts","scripts":{"build":"obuild","dev":"vitest dev","lint":"eslint . && prettier --check src test","lint:fix":"eslint . --fix && prettier -w src test","release":"pnpm test && pnpm build && changelogen --release --push && npm publish","test":"vitest run --coverage"},"devDependencies":{"@types/node":"^24.3.0","@vitest/coverage-v8":"^3.2.4","automd":"^0.4.0","changelogen":"^0.6.2","eslint":"^9.34.0","eslint-config-unjs":"^0.5.0","in-range":"^3.0.0","obuild":"^0.2.1","prettier":"^3.6.2","time-span":"^5.1.0","typescript":"^5.9.2","vitest":"^3.2.4"},"packageManager":"pnpm@10.15.0","_id":"perfect-debounce@2.0.0","gitHead":"d872850a230611e4972ecd7ee86784fb0aafe866","bugs":{"url":"https://github.com/unjs/perfect-debounce/issues"},"homepage":"https://github.com/unjs/perfect-debounce#readme","_nodeVersion":"22.18.0","_npmVersion":"10.9.3","dist":{"shasum":"0ff94f1ecbe0a6bca4b1703a2ed08bbe43739aa7","size":3775,"noattachment":false,"key":"/perfect-debounce/-/perfect-debounce-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/perfect-debounce/download/perfect-debounce-2.0.0.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/perfect-debounce_2.0.0_1755897854774_0.6973565376216238"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-08-22T21:24:14.956Z","publish_time":1755897854956,"_source_registry_name":"default","_cnpm_publish_time":1755897854956},"1.0.0":{"name":"perfect-debounce","version":"1.0.0","description":"[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href]","repository":{"type":"git","url":"git+https://github.com/unjs/perfect-debounce.git"},"license":"MIT","sideEffects":false,"type":"module","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","scripts":{"build":"unbuild","dev":"vitest dev","lint":"eslint --ext .ts,.js,.mjs,.cjs . && prettier --check src test","lint:fix":"eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test","release":"pnpm test && pnpm build && changelogen --release --push && npm publish","test":"vitest run --coverage"},"devDependencies":{"@types/node":"^18.16.3","@vitest/coverage-c8":"^0.31.0","changelogen":"^0.5.3","eslint":"^8.39.0","eslint-config-unjs":"^0.1.0","in-range":"^3.0.0","prettier":"^2.8.8","time-span":"^5.1.0","typescript":"^5.0.4","unbuild":"^1.2.1","vitest":"^0.31.0"},"packageManager":"pnpm@8.4.0","gitHead":"984406de0d31a49a35b8929197162a49ba26ec0f","bugs":{"url":"https://github.com/unjs/perfect-debounce/issues"},"homepage":"https://github.com/unjs/perfect-debounce#readme","_id":"perfect-debounce@1.0.0","_nodeVersion":"16.19.0","_npmVersion":"8.19.3","dist":{"shasum":"9c2e8bc30b169cc984a58b7d5b28049839591d2a","size":3406,"noattachment":false,"key":"/perfect-debounce/-/perfect-debounce-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/perfect-debounce/download/perfect-debounce-1.0.0.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/perfect-debounce_1.0.0_1683155832605_0.050683142885539434"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-05-03T23:17:12.783Z","publish_time":1683155832783,"_source_registry_name":"default","_cnpm_publish_time":1683155832783},"0.1.3":{"name":"perfect-debounce","version":"0.1.3","description":"","repository":"unjs/perfect-debounce","license":"MIT","sideEffects":false,"type":"module","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","devDependencies":{"@nuxtjs/eslint-config-typescript":"latest","c8":"latest","eslint":"latest","in-range":"^3.0.0","standard-version":"latest","time-span":"^5.0.0","typescript":"latest","unbuild":"latest","vitest":"latest"},"packageManager":"pnpm@6.32.3","scripts":{"build":"unbuild","dev":"vitest dev","lint":"eslint --ext .ts,.js,.mjs,.cjs .","release":"pnpm test && standard-version && git push --follow-tags && pnpm publish","test":"vitest run --coverage"},"_id":"perfect-debounce@0.1.3","_integrity":"sha512-NOT9AcKiDGpnV/HBhI22Str++XWcErO/bALvHCuhv33owZW/CjH8KAFLZDCmu3727sihe0wTxpDhyGc6M8qacQ==","_resolved":"/home/pooya/Code/perfect-debounce/perfect-debounce-0.1.3.tgz","_from":"file:perfect-debounce-0.1.3.tgz","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"shasum":"ff6798ea543a3ba1f0efeeaf97c0340f5c8871ce","size":3632,"noattachment":false,"key":"/perfect-debounce/-/perfect-debounce-0.1.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/perfect-debounce/download/perfect-debounce-0.1.3.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/perfect-debounce_0.1.3_1647424064688_0.7714550016971755"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-03-16T09:52:41.352Z","publish_time":1647424064803,"_cnpm_publish_time":1647424064803},"0.1.2":{"name":"perfect-debounce","version":"0.1.2","description":"","repository":"unjs/perfect-debounce","license":"MIT","sideEffects":false,"type":"module","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","devDependencies":{"@nuxtjs/eslint-config-typescript":"latest","c8":"latest","eslint":"latest","in-range":"^3.0.0","standard-version":"latest","time-span":"^5.0.0","typescript":"latest","unbuild":"latest","vitest":"latest"},"packageManager":"pnpm@6.32.3","scripts":{"build":"unbuild","dev":"vitest dev","lint":"eslint --ext .ts,.js,.mjs,.cjs .","release":"pnpm test && standard-version && git push --follow-tags && pnpm publish","test":"vitest run --coverage"},"_id":"perfect-debounce@0.1.2","_integrity":"sha512-kriOxd5uBA+cbC3VyUGu9sCQ6eZT7TuJNqIA0n1The47Eq0wpCZN6XxRIDC+S/Y0K9Z43t0i8giiMe83lmG/Sg==","_resolved":"/home/pooya/Code/perfect-debounce/perfect-debounce-0.1.2.tgz","_from":"file:perfect-debounce-0.1.2.tgz","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"shasum":"6b6ee3b08001f68ebc953fe063cf85acba485985","size":3643,"noattachment":false,"key":"/perfect-debounce/-/perfect-debounce-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/perfect-debounce/download/perfect-debounce-0.1.2.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/perfect-debounce_0.1.2_1647377155493_0.19578657407604827"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-03-15T20:45:57.856Z","publish_time":1647377155741,"_cnpm_publish_time":1647377155741},"0.1.1":{"name":"perfect-debounce","version":"0.1.1","description":"[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href]","repository":{"type":"git","url":"git+https://github.com/unjs/perfect-debounce.git"},"license":"MIT","sideEffects":false,"type":"module","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","scripts":{"build":"unbuild","dev":"vitest dev","lint":"eslint --ext .ts,.js,.mjs,.cjs .","prepack":"unbuild","release":"yarn test && standard-version && git push --follow-tags && npm publish","test":"vitest run --coverage"},"dependencies":{},"devDependencies":{"@nuxtjs/eslint-config-typescript":"latest","c8":"latest","eslint":"latest","in-range":"^3.0.0","standard-version":"latest","time-span":"^5.0.0","typescript":"latest","unbuild":"latest","vitest":"latest"},"gitHead":"a6125d86d4ee893dbfc6f89a6f421e21db584aa3","bugs":{"url":"https://github.com/unjs/perfect-debounce/issues"},"homepage":"https://github.com/unjs/perfect-debounce#readme","_id":"perfect-debounce@0.1.1","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"shasum":"920ebd3fd55ee9e38d82783fd93afe71e2693e4b","size":3337,"noattachment":false,"key":"/perfect-debounce/-/perfect-debounce-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/perfect-debounce/download/perfect-debounce-0.1.1.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/perfect-debounce_0.1.1_1647359763525_0.6086065934678444"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-03-15T15:56:40.481Z","publish_time":1647359763741,"_cnpm_publish_time":1647359763741},"0.1.0":{"name":"perfect-debounce","version":"0.1.0","description":"[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href]","repository":{"type":"git","url":"git+https://github.com/unjs/perfect-debounce.git"},"license":"MIT","sideEffects":false,"type":"module","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","scripts":{"build":"unbuild","dev":"vitest dev","lint":"eslint --ext .ts,.js,.mjs,.cjs .","prepack":"unbuild","release":"yarn test && standard-version && git push --follow-tags && npm publish","test":"vitest run --coverage"},"dependencies":{},"devDependencies":{"@nuxtjs/eslint-config-typescript":"latest","c8":"latest","eslint":"latest","in-range":"^3.0.0","standard-version":"latest","time-span":"^5.0.0","typescript":"latest","unbuild":"latest","vitest":"latest"},"gitHead":"e07645b98231837656e06b632bded578e853cb4e","bugs":{"url":"https://github.com/unjs/perfect-debounce/issues"},"homepage":"https://github.com/unjs/perfect-debounce#readme","_id":"perfect-debounce@0.1.0","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"shasum":"c2b73fe219b669eb4e94511911f41d2c36bab2ac","size":3348,"noattachment":false,"key":"/perfect-debounce/-/perfect-debounce-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/perfect-debounce/download/perfect-debounce-0.1.0.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/perfect-debounce_0.1.0_1647358277478_0.14772726931806068"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-03-15T15:31:23.115Z","publish_time":1647358277647,"_cnpm_publish_time":1647358277647},"0.0.1":{"name":"perfect-debounce","version":"0.0.1","description":"[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href]","repository":{"type":"git","url":"git+https://github.com/unjs/perfect-debounce.git"},"license":"MIT","sideEffects":false,"type":"module","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","scripts":{"build":"unbuild","dev":"vitest dev","lint":"eslint --ext .ts,.js,.mjs,.cjs .","prepack":"unbuild","release":"yarn test && standard-version && git push --follow-tags && npm publish","test":"vitest run --coverage"},"dependencies":{},"devDependencies":{"@nuxtjs/eslint-config-typescript":"latest","c8":"latest","eslint":"latest","in-range":"^3.0.0","standard-version":"latest","time-span":"^5.0.0","typescript":"latest","unbuild":"latest","vitest":"latest"},"gitHead":"d64738b233f5b5fea1f5fba88d63ab10c5dccdec","bugs":{"url":"https://github.com/unjs/perfect-debounce/issues"},"homepage":"https://github.com/unjs/perfect-debounce#readme","_id":"perfect-debounce@0.0.1","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"shasum":"68dfd578fc3e523a0d9a0fcb727ca1fa0c741de6","size":3347,"noattachment":false,"key":"/perfect-debounce/-/perfect-debounce-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/perfect-debounce/download/perfect-debounce-0.0.1.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/perfect-debounce_0.0.1_1647358249393_0.7086892895213273"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-03-15T15:30:53.206Z","publish_time":1647358249571,"_cnpm_publish_time":1647358249571},"0.0.0":{"name":"perfect-debounce","version":"0.0.0","license":"MIT","_id":"perfect-debounce@0.0.0","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"shasum":"6a272f6627cf841387e3f71632ccfda318d81b1c","size":162,"noattachment":false,"key":"/perfect-debounce/-/perfect-debounce-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/perfect-debounce/download/perfect-debounce-0.0.0.tgz"},"_npmUser":{"name":"pi0","email":"pyapar@gmail.com"},"directories":{},"maintainers":[{"name":"pi0","email":"pooya@pi0.ir"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/perfect-debounce_0.0.0_1647286042845_0.663483255153158"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-03-14T19:27:35.791Z","publish_time":1647286042970,"_cnpm_publish_time":1647286042970}},"readme":"# perfect-debounce\n\n<!-- automd:badges color=yellow codecov bundlephobia packagephobia  -->\n\n[![npm version](https://img.shields.io/npm/v/perfect-debounce?color=yellow)](https://npmjs.com/package/perfect-debounce)\n[![npm downloads](https://img.shields.io/npm/dm/perfect-debounce?color=yellow)](https://npm.chart.dev/perfect-debounce)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/perfect-debounce?color=yellow)](https://bundlephobia.com/package/perfect-debounce)\n[![install size](https://badgen.net/packagephobia/install/perfect-debounce?color=yellow)](https://packagephobia.com/result?p=perfect-debounce)\n[![codecov](https://img.shields.io/codecov/c/gh/unjs/perfect-debounce?color=yellow)](https://codecov.io/gh/unjs/perfect-debounce)\n\n<!-- /automd -->\n\nImproved debounce function with Promise support.\n\n## Features\n\n- Well tested debounce implementation\n- Native Promise support\n- Avoid duplicate calls while promise is being resolved\n- Configurable `trailing` and `leading` behavior\n- Control methods\n\n## Usage\n\nInstall package:\n\n```sh\nnpx nypm i perfect-debounce\n```\n\nImport:\n\n```js\nimport { debounce } from \"perfect-debounce\";\n```\n\nDebounce function:\n\n```js\nconst debounced = debounce(async () => {\n  // Some heavy stuff\n}, 25);\n```\n\nWhen calling `debounced`, it will wait at least for `25ms` as configured before actually calling your function. This helps to avoid multiple calls.\n\n### Control Methods\n\nThe returned debounced function provides additional control methods:\n\n- `debounced.cancel()`: Cancel any pending invocation that has not yet occurred.\n- `await debounced.flush()`: Immediately invoke the pending function call (if any) and return its result.\n- `debounced.isPending()`: Returns `true` if there is a pending invocation waiting to be called, otherwise `false`.\n\n```js\ndebounced.cancel(); // Cancel any pending call\nawait debounced.flush(); // Immediately invoke pending call (if any)\ndebounced.isPending(); // Returns true if a call is pending\n```\n\n### Example\n\n```js\nconst debounced = debounce(async (value) => {\n  // Some async work\n  return value * 2;\n}, 100);\n\ndebounced(1);\ndebounced(2);\ndebounced(3);\n\n// Check if a call is pending\nconsole.log(debounced.isPending()); // true\n\n// Immediately invoke the pending call\nconst result = await debounced.flush();\nconsole.log(result); // 6\n\n// Cancel any further pending calls\ndebounced.cancel();\n```\n\nTo avoid initial wait, we can set `leading: true` option. It will cause function to be immediately called if there is no other call:\n\n```js\nconst debounced = debounce(\n  async () => {\n    // Some heavy stuff\n  },\n  25,\n  { leading: true },\n);\n```\n\nIf executing async function takes longer than debounce value, duplicate calls will be still prevented a last call will happen. To disable this behavior, we can set `trailing: false` option:\n\n```js\nconst debounced = debounce(\n  async () => {\n    // Some heavy stuff\n  },\n  25,\n  { trailing: false },\n);\n```\n\n## ???? Development\n\n- Clone this repository\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)\n- Install dependencies using `pnpm install`\n- Run interactive tests using `pnpm dev`\n\n## License\n\nBased on [sindresorhus/p-debounce](https://github.com/sindresorhus/p-debounce).\n\nMade with ???? Published under [MIT License](./LICENSE).\n","_attachments":{},"homepage":"https://github.com/unjs/perfect-debounce#readme","bugs":{"url":"https://github.com/unjs/perfect-debounce/issues"},"license":"MIT"}