{"_id":"@171h/debounce","_rev":"1-9c58ed401a48147739b6b9d6a9af9319","name":"@171h/debounce","dist-tags":{"latest":"1.1.1"},"versions":{"1.1.0":{"name":"@171h/debounce","version":"1.1.0","description":"[![npm version][npm-version-src]][npm-version-href]\r [![npm downloads][npm-downloads-src]][npm-downloads-href]\r [![Github Actions][github-actions-src]][github-actions-href]\r [![Codecov][codecov-src]][codecov-href]","repository":{"type":"git","url":"git+https://github.com/171h/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 build && changelogen --release --push && npm publish --access=public","test":"vitest run --coverage"},"devDependencies":{"@types/node":"^18.16.16","@vitest/coverage-c8":"^0.31.1","changelogen":"^0.5.3","eslint":"^8.41.0","eslint-config-unjs":"^0.2.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.1"},"packageManager":"pnpm@8.5.1","dependencies":{"lodash":"^4.17.21"},"gitHead":"a878850a8b54d705bdda76b566a19655f4356665","bugs":{"url":"https://github.com/171h/perfect-debounce/issues"},"homepage":"https://github.com/171h/perfect-debounce#readme","_id":"@171h/debounce@1.1.0","_nodeVersion":"20.3.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-WBcU9NwViBzzD+2GvnFNXZzpQJABbnK0VMl+GDcJCu3OLI+tcid/bJX2lo8NRAGyMYFVrxAswzEaGqOAsz133w==","shasum":"ce68d2c34fd67c9bf1324a6e84659d2419e4e1ea","tarball":"https://registry.npmjs.org/@171h/debounce/-/debounce-1.1.0.tgz","fileCount":6,"unpackedSize":11871,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC6lwtFVEUjIU/WAypRIx9nrxtSyuClHnrRWxp51PZr1AIga3E0YIArW7rEtRafIYjl0huUnniSHri6+sYpCz8Qr/Q="}]},"_npmUser":{"name":"171h","email":"1091088708@qq.com"},"directories":{},"maintainers":[{"name":"171h","email":"1091088708@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/debounce_1.1.0_1688393679190_0.5627060288044514"},"_hasShrinkwrap":false},"1.1.1":{"name":"@171h/debounce","version":"1.1.1","description":"[![npm version][npm-version-src]][npm-version-href]\r [![npm downloads][npm-downloads-src]][npm-downloads-href]\r [![Github Actions][github-actions-src]][github-actions-href]\r [![Codecov][codecov-src]][codecov-href]","repository":{"type":"git","url":"git+https://github.com/171h/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 build && changelogen --release --push && npm publish --access=public","test":"vitest run --coverage"},"devDependencies":{"@types/node":"^18.16.16","@vitest/coverage-c8":"^0.31.1","changelogen":"^0.5.3","eslint":"^8.41.0","eslint-config-unjs":"^0.2.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.1"},"packageManager":"pnpm@8.5.1","dependencies":{"lodash":"^4.17.21"},"gitHead":"d63f7dc62a5bfb37c7be60c2e199fe583a4ca068","bugs":{"url":"https://github.com/171h/perfect-debounce/issues"},"homepage":"https://github.com/171h/perfect-debounce#readme","_id":"@171h/debounce@1.1.1","_nodeVersion":"20.3.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-0Z9vChd4tzomDc+aORSxLZnW6FTmgdEPlTXTEaCl0Wqxtl/vCnJeP5qBi9K10OeixxCNK/LfEXYjzxO62myvHg==","shasum":"159ce855cf2f46459cd87bab6dc4133a6e475b5a","tarball":"https://registry.npmjs.org/@171h/debounce/-/debounce-1.1.1.tgz","fileCount":6,"unpackedSize":12149,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC8+riz0WZNLO5Z0kRag/W+3iPGS8XzCx9fGnZdKT4JpgIhAPYJqq+gUAHT4RHzw7uBxblcJEyDj1Ia2MqtWS12jzVA"}]},"_npmUser":{"name":"171h","email":"1091088708@qq.com"},"directories":{},"maintainers":[{"name":"171h","email":"1091088708@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/debounce_1.1.1_1688394561775_0.09464999438782695"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-03T14:14:39.135Z","1.1.0":"2023-07-03T14:14:39.410Z","modified":"2023-07-03T14:29:22.057Z","1.1.1":"2023-07-03T14:29:21.960Z"},"maintainers":[{"name":"171h","email":"1091088708@qq.com"}],"description":"[![npm version][npm-version-src]][npm-version-href]\r [![npm downloads][npm-downloads-src]][npm-downloads-href]\r [![Github Actions][github-actions-src]][github-actions-href]\r [![Codecov][codecov-src]][codecov-href]","homepage":"https://github.com/171h/perfect-debounce#readme","repository":{"type":"git","url":"git+https://github.com/171h/perfect-debounce.git"},"bugs":{"url":"https://github.com/171h/perfect-debounce/issues"},"license":"MIT","readme":"# perfect-debounce\r\n\r\n[![npm version][npm-version-src]][npm-version-href]\r\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\r\n[![Github Actions][github-actions-src]][github-actions-href]\r\n[![Codecov][codecov-src]][codecov-href]\r\n\r\n> An improved debounce function with Promise support.\r\n\r\n- Well tested debounce implementation\r\n- Native Promise support\r\n- Avoid duplicate calls while promise is being resolved\r\n- Configurable `trailing` and `leading` behavior\r\n\r\n## Usage\r\n\r\nInstall package:\r\n\r\n```sh\r\n# npm\r\nnpm install perfect-debounce\r\n\r\n# yarn\r\nyarn add perfect-debounce\r\n\r\n# pnpm\r\npnpm add perfect-debounce\r\n```\r\n\r\nImport:\r\n\r\n```js\r\n// ESM\r\nimport { debounce } from 'perfect-debounce'\r\n\r\n// CommonJS\r\nconst { debounce } = require('perfect-debounce')\r\n```\r\n\r\nDebounce function:\r\n\r\n```js\r\nconst debounced = debounce(async () => {\r\n  // Some heavy stuff\r\n}, 25)\r\n```\r\n\r\nWhen calling `debounced`, it will wait at least for `25ms` as configured before actually calling our function. This helps to avoid multiple calls.\r\n\r\nTo avoid initial wait, we can set `leading: true` option. It will cause function to be immediately called if there is no other call:\r\n\r\n```js\r\nconst debounced = debounce(async () => {\r\n  // Some heavy stuff\r\n}, 25, { leading: true })\r\n```\r\n\r\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:\r\n\r\n```js\r\nconst debounced = debounce(async () => {\r\n  // Some heavy stuff\r\n}, 25, { trailing: false })\r\n```\r\n\r\nIf you want to always execute functions with different parameters, please set `diff: true` option. Note that when `diff` is true, `leading` and `trailing` will be ignored.\r\n\r\n```js\r\nconst debounced = debounce(async (args) => {\r\n  // Some heavy stuff\r\n}, 25, { diff: false })\r\n```\r\n\r\n## 💻 Development\r\n\r\n- Clone this repository\r\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)\r\n- Install dependencies using `pnpm install`\r\n- Run interactive tests using `pnpm dev`\r\n\r\n## License\r\n\r\nMade with 💛\r\n\r\nBased on [sindresorhus/p-debounce](https://github.com/sindresorhus/p-debounce).\r\n\r\nPublished under [MIT License](./LICENSE).\r\n\r\n<!-- Badges -->\r\n[npm-version-src]: https://img.shields.io/npm/v/perfect-debounce?style=flat-square\r\n[npm-version-href]: https://npmjs.com/package/perfect-debounce\r\n\r\n[npm-downloads-src]: https://img.shields.io/npm/dm/perfect-debounce?style=flat-square\r\n[npm-downloads-href]: https://npmjs.com/package/perfect-debounce\r\n\r\n[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/perfect-debounce/ci/main?style=flat-square\r\n[github-actions-href]: https://github.com/unjs/perfect-debounce/actions?query=workflow%3Aci\r\n\r\n[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/perfect-debounce/main?style=flat-square\r\n[codecov-href]: https://codecov.io/gh/unjs/perfect-debounce\r\n","readmeFilename":"README.md"}