{"name":"throttle-debounce","version":"3.0.1","description":"Throttle and debounce functions.","license":"MIT","author":{"name":"Ivan Nikolić","email":"niksy5@gmail.com","url":"http://ivannikolic.com"},"contributors":[{"name":"Ben Alman","url":"http://benalman.com"}],"sideEffects":false,"exports":{".":{"import":"./esm/index.js","require":"./cjs/index.js"},"./package.json":"./package.json"},"main":"cjs/index.js","jsdelivr":"umd/index.js","unpkg":"umd/index.js","module":"esm/index.js","directories":{"test":"test"},"scripts":{"build":"rollup --config rollup.config.js","lint":"eslint '{index,debounce,throttle,test/**/*}.js'","module-check":"node -e 'require(\"throttle-debounce\");' && node --input-type=module -e 'import \"throttle-debounce\";'","prepublishOnly":"npm run build && npm run module-check","postpublish":"GITHUB_TOKEN=$GITHUB_RELEASE_TOKEN github-release-from-changelog","release":"np --no-release-draft","test":"npm run lint && npm run test:automated","test:automated":"BABEL_ENV=test karma start","test:automated:watch":"npm run test:automated -- --auto-watch --no-single-run","version":"version-changelog CHANGELOG.md && changelog-verify CHANGELOG.md && git add CHANGELOG.md"},"devDependencies":{"@babel/cli":"^7.2.3","@babel/core":"^7.2.2","@babel/plugin-transform-object-assign":"^7.2.0","@babel/plugin-transform-runtime":"^7.2.0","@babel/runtime":"^7.2.0","@rollup/plugin-babel":"^5.2.1","babel-loader":"^8.1.0","babel-preset-niksy":"^4.1.0","changelog-verify":"^1.1.2","core-js":"^2.6.5","eslint":"^7.11.0","eslint-config-niksy":"^9.0.0","eslint-config-prettier":"^6.14.0","eslint-plugin-extend":"^0.1.1","eslint-plugin-import":"^2.22.1","eslint-plugin-jsdoc":"^30.7.3","eslint-plugin-mocha":"^8.0.0","eslint-plugin-node":"^11.1.0","eslint-plugin-prettier":"^3.0.1","eslint-plugin-promise":"^4.1.1","eslint-plugin-react":"^7.9.1","eslint-plugin-unicorn":"^23.0.0","esm":"^3.0.51","get-port":"^4.0.0","get-port-cli":"^2.0.0","github-release-from-changelog":"^2.1.1","husky":"^4.3.0","karma":"^5.2.3","karma-browserstack-launcher":"^1.6.0","karma-chrome-launcher":"^3.1.0","karma-firefox-launcher":"^0.1.7","karma-mocha-reporter":"^2.2.5","karma-qunit":"^0.1.9","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^4.0.2","lint-staged":"^10.4.2","minimist":"^1.2.0","mocha":"^4.1.0","np":"^6.5.0","prettier":"^2.1.2","qunitjs":"^1.23.1","rollup":"^2.32.1","rollup-plugin-babel":"^4.2.0","version-changelog":"^3.1.1","webpack":"^4.44.2"},"engines":{"node":">=10"},"keywords":["debounce","throttle"],"repository":{"type":"git","url":"git+https://github.com/niksy/throttle-debounce.git"},"bugs":{"url":"https://github.com/niksy/throttle-debounce/issues"},"homepage":"https://github.com/niksy/throttle-debounce#readme","gitHead":"67aab0fdfe701b700741bdc2202d923e4b1fc0c3","_id":"throttle-debounce@3.0.1","_nodeVersion":"12.18.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-dTEWWNu6JmeVXY0ZYoPuH5cRIwc0MeGbJwah9KUNYSJwommQpCzTySTpEe8Gs1J23aeWEuAobe4Ag7EHVt/LOg==","shasum":"32f94d84dfa894f786c9a1f290e7a645b6a19abb","tarball":"http://registry-npm.ywwl.com/throttle-debounce/download/throttle-debounce-3.0.1.tgz","fileCount":13,"unpackedSize":68134,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfn+n4CRA9TVsSAnZWagAA7VIP/RuqZeeeKaz1tIVWjoSV\nIuPgahisJf78ZnNO7K9XvepHT2fBM539C2Kuf+6eP8hOtk7sJqbiyY7rnVWs\n4MSXSFLkb3m7wKEKj6D4tpsAC7bRZsY5PecKRoBNw4IzB40dvSx9gc8dXMQt\nUi6A2ku8QQh9gShSglbd0rLSpSb8DFbHtzjJDeiiowy6LSpJCXhiKbmHWAkw\nPVKZ/vIscOn96ov2mI3oO7RXN4w0CtA6nSc5YDjvkXr9/eEnK2qaNBhcKv1h\nv39RbKn2Dt72y4eKiqhoJNimRNlhGWNgjaiiBkBl3XAi3HzK7/vYlgeqLHzf\nAPFow4iw6CB3khFN6mENNbNUvuHec9yvP5aP32nE/TSDpZx9ZSZ9gHt7RNYj\nAyXcA3aq/21VIM0QMHcb8UK/5lBb7hGJ9PBRchyjuwRmp2MIy/5BdO+nBLDw\nzV6b7lzowhsZisCFAR492qet0FEX429m3ExyHurp1M962j50zwX+fDf02UX+\nAIgzRIFOipbB9mvRoZJ1baJgccX11OzDomRPZGTgnsQ924p+ZEfI/j5Qusmz\nlLTg0+A8PO1ZPYnTUAsVdXqTBvjcbha7YSz3iwnjIbulKWP35D81riYMlHIl\ncXnEushDDK/FHQT1ddyzx5tKlGSKdwDjP8bGq6qv6Yqu2XsGnrak459BpsHy\ntUHc\r\n=PdyL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCRyNIWsTQrXkpmDThtJ6np+UpN4VpgqdK9rCZ4oJnRtwIhAPsGMVhozaRB/JfNL32XgfTGkZ01mRNiQIejBxVebitB"}],"size":14035,"noattachment":false,"key":"/throttle-debounce/-/throttle-debounce-3.0.1.tgz"},"maintainers":[{"name":"niksy","email":"niksy5@gmail.com"}],"_npmUser":{"name":"niksy","email":"niksy5@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/throttle-debounce_3.0.1_1604315640303_0.4457450689021403"},"_hasShrinkwrap":false,"readme":"# throttle-debounce\n\n[![Build Status][ci-img]][ci]\n[![BrowserStack Status][browserstack-img]][browserstack]\n[![Mentioned in Awesome Micro npm Packages][awesome-img]][awesome]\n\nThrottle and debounce functions.\n\nThis module is the same as [jquery-throttle-debounce][jquery-throttle-debounce]\n([with some differences](#differences-with-original-module)), but it’s\ntransferred to ES Modules and CommonJS format.\n\n## Install\n\n```sh\nnpm install throttle-debounce --save\n```\n\n## Usage\n\n### `throttle`\n\n```js\nimport { throttle } from 'throttle-debounce';\n\nconst throttleFunc = throttle(\n\t1000,\n\t(num) => {\n\t\tconsole.log('num:', num);\n\t},\n\t{ noLeading: false, noTrailing: false }\n);\n\n// Can also be used like this, because noLeading and noTrailing are false by default\nconst throttleFunc = throttle(1000, (num) => {\n\tconsole.log('num:', num);\n});\n\nthrottleFunc(1); // Will execute the callback\nthrottleFunc(2); // Won’t execute callback\nthrottleFunc(3); // Won’t execute callback\n\n// Will execute the callback, because noTrailing is false,\n// but if we set noTrailing to true, this callback won’t be executed\nthrottleFunc(4);\n\nsetTimeout(() => {\n\tthrottleFunc(10); // Will execute the callback\n}, 1200);\n\n// Output\n// num: 1\n// num: 4\n// num: 10\n```\n\n### `debounce`\n\n```js\nimport { debounce } from 'throttle-debounce';\n\nconst debounceFunc = debounce(\n\t1000,\n\t(num) => {\n\t\tconsole.log('num:', num);\n\t},\n\t{ atBegin: false }\n);\n\n// Can also be used like this, because atBegin is false by default\nconst debounceFunc = debounce(1000, (num) => {\n\tconsole.log('num:', num);\n});\n\n// Won’t execute the callback, because atBegin is false,\n// but if we set atBegin to true, this callback will be executed.\ndebounceFunc(1);\n\ndebounceFunc(2); // Won’t execute callback\ndebounceFunc(3); // Won’t execute callback\n\n// Will execute the callback,\n// but if we set atBegin to true, this callback won’t be executed.\ndebounceFunc(4);\n\nsetTimeout(() => {\n\tdebounceFunc(10); // Will execute the callback\n}, 1200);\n\n// Output\n// num: 4\n// num: 10\n```\n\n### Cancelling\n\nDebounce and throttle can both be cancelled by calling the `cancel` function.\n\n```js\nconst throttleFunc = throttle(300, () => {\n\t// Throttled function\n});\n\nthrottleFunc.cancel();\n\nconst debounceFunc = debounce(300, () => {\n\t// Debounced function\n});\n\ndebounceFunc.cancel();\n```\n\nThe logic that is being throttled or debounced will no longer be called.\n\nTo cancel only one upcoming debounced call, you can pass `upcomingOnly: true`\noption to `cancel` function:\n\n```js\nconst debounceFunc = debounce(300, () => {\n\t// Debounced function\n});\n\ndebounceFunc(); // will not be invoked\n\ndebounceFunc.cancel({ upcomingOnly: true });\n\ndebounceFunc(); // will be invoked\n```\n\n## API\n\n### throttle(delay, callback, { noLeading, noTrailing, debounceMode })\n\nReturns: `Function`\n\nThrottle execution of a function. Especially useful for rate limiting execution\nof handlers on events like resize and scroll.\n\n#### delay\n\nType: `Number`\n\nA zero-or-greater delay in milliseconds. For event callbacks, values around 100\nor 250 (or even higher) are most useful.\n\n#### callback\n\nType: `Function`\n\nA function to be executed after delay milliseconds. The `this` context and all\narguments are passed through, as-is, to `callback` when the throttled-function\nis executed.\n\n#### noTrailing\n\nType: `Boolean`\n\nOptional, defaults to false. If noTrailing is true, callback will only execute\nevery `delay` milliseconds while the throttled-function is being called. If\nnoTrailing is false or unspecified, callback will be executed one final time\nafter the last throttled-function call. (After the throttled-function has not\nbeen called for `delay` milliseconds, the internal counter is reset)\n\n#### noLeading\n\nType: `Boolean`\n\nOptional, defaults to false. If noLeading is false, the first throttled-function\ncall will execute callback immediately. If noLeading is true, the first the\ncallback execution will be skipped. It should be noted that callback will never\nexecuted if both noLeading = true and noTrailing = true.\n\n#### debounceMode\n\nType: `Boolean`\n\nIf `debounceMode` is true (at begin), schedule `clear` to execute after `delay`\nms. If `debounceMode` is false (at end), schedule `callback` to execute after\n`delay` ms.\n\n### debounce(delay, callback, { atBegin })\n\nReturns: `Function`\n\nDebounce execution of a function. Debouncing, unlike throttling, guarantees that\na function is only executed a single time, either at the very beginning of a\nseries of calls, or at the very end.\n\n#### delay\n\nType: `Number`\n\nA zero-or-greater delay in milliseconds. For event callbacks, values around 100\nor 250 (or even higher) are most useful.\n\n#### callback\n\nType: `Function`\n\nA function to be executed after delay milliseconds. The `this` context and all\narguments are passed through, as-is, to `callback` when the debounced-function\nis executed.\n\n#### atBegin\n\nType: `Boolean`\n\nOptional, defaults to false. If `atBegin` is false or unspecified, callback will\nonly be executed `delay` milliseconds after the last debounced-function call. If\n`atBegin` is true, callback will be executed only at the first\ndebounced-function call. (After the throttled-function has not been called for\n`delay` milliseconds, the internal counter is reset).\n\n## Differences with original module\n\n-   Dependancy on jQuery is removed, so if you rely on GUIDs set by jQuery, plan\n    accordingly\n-   There is no standalone version available, so don’t rely on `$.throttle` and\n    `$.debounce` to be available\n\n## Browser support\n\nTested in Chrome 72, Edge 15, Firefox 65 and should work in all modern browsers\n([support based on Browserslist configuration](https://browserslist.dev/?q=bGFzdCAzIG1ham9yIHZlcnNpb25zLCBzaW5jZSAyMDE5LCBlZGdlID49IDE1LCBub3QgaWUgPiAw)).\n\n## Test\n\nFor automated tests, run `npm run test:automated` (append `:watch` for watcher\nsupport).\n\n## License\n\n<!-- prettier-ignore-start -->\n\n**Original module license:** Copyright (c) 2010 \"Cowboy\" Ben Alman (Dual licensed under the MIT and GPL licenses. http://benalman.com/about/license/)  \n**This module license:** MIT © [Ivan Nikolić](http://ivannikolic.com)\n\n[ci]: https://github.com/niksy/throttle-debounce/actions?query=workflow%3ACI\n[ci-img]: https://github.com/niksy/throttle-debounce/workflows/CI/badge.svg?branch=master\n[browserstack]: https://www.browserstack.com/\n[browserstack-img]: https://img.shields.io/badge/browser%20testing-BrowserStack-informational?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2NCA2NCI+CiAgPGRlZnMvPgogIDxyYWRpYWxHcmFkaWVudCBpZD0iYSIgY3g9IjIwLjk0Mjk3NiIgY3k9IjI4LjA5NDY3ODczIiByPSIzLjc5MTM0MTQxIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CiAgICA8c3RvcCBvZmZzZXQ9IjAiIHN0b3AtY29sb3I9IiM3OTc5NzkiLz4KICAgIDxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iIzRjNGM0YyIvPgogIDwvcmFkaWFsR3JhZGllbnQ+CiAgPGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTI5LjcyO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.com/parro-it/awesome-micro-npm-packages\n[awesome-img]: https://awesome.re/mentioned-badge.svg\n[jquery-throttle-debounce]: https://github.com/cowboy/jquery-throttle-debounce\n\n<!-- prettier-ignore-end -->\n","publish_time":1604315640404,"_cnpm_publish_time":1604315640404,"dist-tags":{"latest":"5.0.2"}}