{"_id":"simple-rate-limiter","_rev":"29-4781f4e55af7a5a53a01cb668daa5066","name":"simple-rate-limiter","description":"A simple way to rate limit how often a function is executed.","dist-tags":{"latest":"0.5.0"},"versions":{"0.1.0":{"name":"simple-rate-limiter","version":"0.1.0","description":"A laughably simplistic router for node.js","keywords":["throttle","rate limit","queue calls"],"maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"main":"./index.js","repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"_id":"simple-rate-limiter@0.1.0","dist":{"shasum":"0d22fe597f74d3f81d563cf9e5e0791d7cb1f7ea","tarball":"https://registry.npmjs.org/simple-rate-limiter/-/simple-rate-limiter-0.1.0.tgz","integrity":"sha512-LBPbhF91eRzXTKoMT6w0dCbr6KOQNvhulvWstDrAYqpFvz7+XEGXxzXNXx0FmJZk7lsy8kG+Ebm1+8CglAhiYQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA97ymSXT2OsKA3Le3HuAHvX0M9Qm7A3X9OkNjK4AvD1AiEA1noiXcvx+SaJatalJU19oZ8AilyDvsmZKvKMzZFFsqg="}]},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"xavi","email":"xavi.rmz@gmail.com"},"directories":{}},"0.1.1":{"name":"simple-rate-limiter","version":"0.1.1","description":"A laughably simplistic router for node.js","keywords":["throttle","rate limit","queue calls"],"maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"main":"./index.js","repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"_id":"simple-rate-limiter@0.1.1","dist":{"shasum":"f8d261deeeee438e976f75cd444cc92352d699bf","tarball":"https://registry.npmjs.org/simple-rate-limiter/-/simple-rate-limiter-0.1.1.tgz","integrity":"sha512-rxng6DR1HjcArhVp7VevDbubItM3VSp1XypNDPDd5CW0055RvAQ4L/0FQGCPOeqx3IGxD16bcIhFRa6x3DWE8w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDrjPUOLj1ZDEaPgOT4kA5y3uRVf3KzPf4wWeKKvgAergIgGU9qslnGrhd/rAEbg/jP2/a9DefW+ilXWXHl6rRAR38="}]},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"xavi","email":"xavi.rmz@gmail.com"},"directories":{}},"0.2.0":{"name":"simple-rate-limiter","version":"0.2.0","description":"A simple way to rate limit how often a function is executed.","keywords":["throttle","rate limit","queue calls"],"maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"main":"./index.js","repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"_id":"simple-rate-limiter@0.2.0","dist":{"shasum":"5a2179b3e64385bfe46edf306f8e0db3894f6e0b","tarball":"https://registry.npmjs.org/simple-rate-limiter/-/simple-rate-limiter-0.2.0.tgz","integrity":"sha512-h57VjqSb/L1pay/WPWa64JLRafQXsbiwftUBikNN8AJIcJbfGUHwl006tYYRRrNsvmYRA7/ydpRHpQVtPbKf5A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCm5+X2qTlKLFZZmq9QWjtxdTWwwXEq56Oc1l40QTYq8AIhAINc44LbzguGgPMQO2rkJ0i2pHhdUHaQfQC0dKCOUF0Q"}]},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"xavi","email":"xavi.rmz@gmail.com"},"directories":{}},"0.2.1":{"name":"simple-rate-limiter","version":"0.2.1","description":"A simple way to rate limit how often a function is executed.","keywords":["throttle","rate limit","queue calls"],"maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"main":"./index.js","repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"_id":"simple-rate-limiter@0.2.1","dist":{"shasum":"0bceb908a7852a8111173d06a86782f35053068d","tarball":"https://registry.npmjs.org/simple-rate-limiter/-/simple-rate-limiter-0.2.1.tgz","integrity":"sha512-rbvQpckXXatPGwZYru7wDi3tVV9Q09xA5z0Q3yA9tweegCTQbzORkfgg/uqHkZYihMb7y9bC+VrT0PwmXsGuAw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCBqi/16tZkdFMsxDF+/ODhy5YtLqmFMrjf79v/ViVJBQIgNdfeh0Gp/hYAWHLwXPWUxQpqCdxf67vb9Yap9l2w/hw="}]},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"xavi","email":"xavi.rmz@gmail.com"},"directories":{}},"0.2.2":{"name":"simple-rate-limiter","version":"0.2.2","description":"A simple way to rate limit how often a function is executed.","keywords":["throttle","rate limit","queue calls"],"maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"main":"./index.js","repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"homepage":"https://github.com/xavi-/node-simple-rate-limiter","_id":"simple-rate-limiter@0.2.2","dist":{"shasum":"6cfcf985b10d430f2f20d7dfa533b498a9e1888d","tarball":"https://registry.npmjs.org/simple-rate-limiter/-/simple-rate-limiter-0.2.2.tgz","integrity":"sha512-y3VIhUda+6uuakgVOF54NTwhxbC15duS3bmx8Jm2sbH2euH77nM5bDM9BkXsgmEA4uPg5Sy0jWPkmRlQwzgdsA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCJLCkw0jpCfmnrrJ3bSlKbrSQ2lhRN6nrHyqC3PzAyFwIhAIAaAHt37YEQJW/SHKxGS3h6lUzAMVKPA1fymhVGt2bn"}]},"_from":".","_npmVersion":"1.3.23","_npmUser":{"name":"xavi","email":"xavi.rmz@gmail.com"},"directories":{}},"0.2.3":{"name":"simple-rate-limiter","version":"0.2.3","description":"A simple way to rate limit how often a function is executed.","keywords":["throttle","rate limit","queue calls"],"maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"main":"./index.js","repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"homepage":"https://github.com/xavi-/node-simple-rate-limiter","_id":"simple-rate-limiter@0.2.3","dist":{"shasum":"306466faff17e1f22ee758b0a37cd453e8351b41","tarball":"https://registry.npmjs.org/simple-rate-limiter/-/simple-rate-limiter-0.2.3.tgz","integrity":"sha512-0Vhtv4EifYKKJabm7460DOdYjl0tfssCRcwrrYy2Qz3O94WCvPezWCoJdEVR1KYOwaEySeWkJ8/YjLWFGNzw8Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICwTGGmABSpG4UIy4cBpmurBO7EVVum6XoYE5p+xRb6TAiAvkDzIYYDpoeASd/+yJE2dqYOaXE8PvCn+oieUojxJrQ=="}]},"_from":".","_npmVersion":"1.3.23","_npmUser":{"name":"xavi","email":"xavi.rmz@gmail.com"},"directories":{}},"0.3.0":{"name":"simple-rate-limiter","version":"0.3.0","description":"A simple way to rate limit how often a function is executed.","keywords":["throttle","rate limit","queue calls"],"maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"scripts":{"test":"node test.js"},"main":"./index.js","repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"gitHead":"2afe441b5166fb80d83b96e25786c84e4a956515","bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"homepage":"https://github.com/xavi-/node-simple-rate-limiter#readme","_id":"simple-rate-limiter@0.3.0","_nodeVersion":"18.12.1","_npmVersion":"9.3.0","dist":{"integrity":"sha512-fqRCOp9i7TJY6kI92KbwKHWSwM/gtmm/YSc6Z95gRorML2HeA3Su0/Wtb4sNkM4SRrqlpQ1qX3L1mlx8NAVcTg==","shasum":"b2a5995f99a667c0e36be09ca5a76981f7b213de","tarball":"https://registry.npmjs.org/simple-rate-limiter/-/simple-rate-limiter-0.3.0.tgz","fileCount":4,"unpackedSize":12545,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDQrMrKNni+U6wZnQAAanVYecY9cd6OcKhSCNDGowHcgAiB8J3uqfuYnwKsJ/MRquxWrBgK4DoqMb1KeQ3391litSQ=="}]},"_npmUser":{"name":"xavi","email":"xavi.rmz@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-rate-limiter_0.3.0_1685160431426_0.6046431779573787"},"_hasShrinkwrap":false},"0.4.0":{"name":"simple-rate-limiter","version":"0.4.0","description":"A simple way to rate limit how often a function is executed.","keywords":["throttle","rate limit","queue calls"],"maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"scripts":{"test":"node test.js"},"main":"./index.js","repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"gitHead":"9b8f17acb8f00774c96669738ab55e2e8449ed4b","bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"homepage":"https://github.com/xavi-/node-simple-rate-limiter#readme","_id":"simple-rate-limiter@0.4.0","_nodeVersion":"18.12.1","_npmVersion":"9.3.0","dist":{"integrity":"sha512-N9gH772EdMGH2kq/XyAvLwmz51e1BOoZhng9KRsa6JXlP8rkI2rsZ2cY4018kuJa652DqRejKkiA3G5XQygRgg==","shasum":"c40ce8040dcf1e95bf559bf4a1dc724ceb91100e","tarball":"https://registry.npmjs.org/simple-rate-limiter/-/simple-rate-limiter-0.4.0.tgz","fileCount":4,"unpackedSize":13705,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDujBPQltuByZnz3b1bo578Y+VBslrGC9xrf54sFXzLhgIgBO5m7OEqMot3eF6ZzXfJg/a99lVZePUCFIlPsPT+r4I="}]},"_npmUser":{"name":"xavi","email":"xavi.rmz@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-rate-limiter_0.4.0_1685163577523_0.06318697125839967"},"_hasShrinkwrap":false},"0.5.0":{"name":"simple-rate-limiter","version":"0.5.0","description":"A simple way to rate limit how often a function is executed.","keywords":["throttle","rate limit","queue calls"],"maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"scripts":{"test":"node test.js"},"main":"./index.js","repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"gitHead":"0a53e11e1a2176cdb459aa92bb0d25c6ec47cbc4","bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"homepage":"https://github.com/xavi-/node-simple-rate-limiter#readme","_id":"simple-rate-limiter@0.5.0","_nodeVersion":"18.12.1","_npmVersion":"9.3.0","dist":{"integrity":"sha512-03+IWcxofJ1K0IwlaNSZzyf1MC3LZijsCnYxzFLWwhHhS8UiQOJbDYe9smxlTNktvys+vQnEIAxoStkJkUrvmA==","shasum":"0c9ab3c10343c7fda6724a32d70dca794e99c253","tarball":"https://registry.npmjs.org/simple-rate-limiter/-/simple-rate-limiter-0.5.0.tgz","fileCount":4,"unpackedSize":17165,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC94l+7cEDzBmSLHeco1kaOChX1g8uGOtQHCVnQD++cQgIhAMfuBWO92kWSfgzZJ5Zbgnx1+5vNE9L27mwOfbHyusaj"}]},"_npmUser":{"name":"xavi","email":"xavi.rmz@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-rate-limiter_0.5.0_1685248889589_0.13423963049320875"},"_hasShrinkwrap":false}},"readme":"# simple-rate-limiter\n\nA simple way to limit how often a function is executed.\n\n## Examples\n\nIf you want to limit _all_ requests:\n\n```javascript\nvar limit = require(\"simple-rate-limiter\");\nvar request = limit(require(\"request\")).to(10).per(1000);\n\nuserIds.forEach(function(userId) {\n\tvar url = \"http://easily-overwhelmed-api.com/users/\" + userId;\n\trequest(url, function(err, res, body) {\n\t\t/* ... Yay! Not a too-many-request-per-second error! ... */\n\t});\n})\n```\n\nOr if you'd like to be a bit more fine grain and/or explicit:\n\n```javascript\nvar limit = require(\"simple-rate-limiter\");\nvar callApi = limit(function(userId, callback) {\n\tvar url = \"http://easily-overwhelmed-api.com/users/\" + userId;\n\trequest(url, callback);\n}).to(10).per(1000);\n\nuserIds.forEach(function(userId) {\n\tcallApi(userId, function(err, res, body) {\n\t\t/* ... Yay! Not a too-many-request-per-second error! ... */\n\t});\n})\n```\n\n## API\n\nBasic usage: `let limited = limit(fn)`\n\n- `limited(args...)`: Enqueues a set of arguments that `fn` will be executed with.  Returns an [EventEmitter](http://nodejs.org/docs/latest/api/events.html#events_class_events_eventemitter) that will emit a `limiter-exec` event when `fn` is executed with `args`.  Also, in the case that `fn` returns an EventEmitter, the events emmitted by the returned EventEmitter will be relayed to the EventEmitter returned by `limited`.  In other words, stuff like this works:\n\n\t```javascript\n\tvar limit = require(\"simple-rate-limiter\");\n\tvar request = require(\"request\");\n\tlimit(request)(\"http://google.com\").on(\"data\", function(chunk) { /*** code ***/ });\n\t```\n\n- `limited.to(count=1)`: The number of times `fn` will be execute within the time specified by `.per(time)`.\n- `limited.per(time=Infinity)`: The number of milliseconds in which `fn` will be executed `.to(count)` number of times.\n- `limited.evenly([toggle=true])`: Off by default.  When true, `fn` will be executed evenly through the time period specified by `.per(time)`.  For example, if set to true and `.to(10)` and `.per(1000)`, then `fn` will be executed every 100ms.\n- `limited.withFuzz([percent=0.1])`: Set to 0 by default.  Adds a random factor to the delay time.  For example if set to 0.1 and `.to(10)` and `.per(1000)`, then `fn` will be executed between every 100ms to 110ms.\n- `limited.maxQueueLength(max)`: Set to 5,000 by default.  If more than 5,000 pending actions are queued, then an exception will be thrown.\n\nAll methods attached to `limited` and can be chained.\n\nContext for a function can be set with `limit(fn, ctx)` or `limit.promise(promiser, ctx)`.\n\n### Promises\n\nSimple rate limiter supports promises with `limit.promise`.  Limited promises have support the same chainable methods as `limit`.  Example usage:\n\n```js\nconst limited = limit(getUser).to(10).per(1000);\n\nconst users = await Promise.all(userIds.map(id => limited(id)));\n\n/* ... Yay, I didn't spam anyone! ... */\n```\n\n- `limit.promise(promiser[, ctx])`: Returns a promise.  Calls the `promises` no more often than the `to` and `per` fields dictate.  An optional context parameter can be passed in.\n\n\n## Edge cases\n\nBasic usage: `limit(fn).to(count).per(interval)`\n\nThe `to` method or `per` can be called any number of times including zero.  The effective default count for `to` is 1 and the effective default interval for `per` is Infinity.  Which means if neither the `to` method or `per` method are called, then `limit` will only execute `fn` once ever:\n\n```javascript\nvar init = limit(function() { console.log(\"Runs only once\"); });\nfor(var i = 0; i < 3; i++) { init(); }\n\n/*** Console output: ***/\n// $ Runs only once\n// ... Nothing else is ever printed ...\n```\n\nSimilarly, if `per` is never called, `fn` is executed at most `count` number of times:\n\n```javascript\nvar dos = limit(function() { console.log(\"twice only\"); }).to(2);\nfor(var i = 0; i < 3; i++) { dos(); }\n\n/*** Console output: ***/\n// $ twice only\n// $ twice only\n// ... Nothing else is ever printed ...\n```\n\nOn the other hand, if `to` is never called, `fn` is only executed every `interval` milliseconds:\n\n```javascript\nvar tick = limit(function() { console.log(\"Once a second...\"); }).per(1000);\nfor(var i = 0; i < 3; i++) { tick(); }\n\n/*** Console output: ***/\n// $ Once a second\n// ... pause for 1 second ...\n// $ Once a second\n// ... pause for 1 second ...\n// $ Once a second\n```\n\nFinally, as mentioned earlier, `to` and `per` can be called any number of times.  Each time either `to` or `per` is called, the previous `count` or `interval` value is overriden:\n\n```javascript\nvar strange = limit(function() {\n\tconsole.log(\"Every once in a while\");\n}).to(1).per(1000).to(2).per(2000);\nfor(var i = 0; i < 3; i++) { strange(); }\n\n/*** Console output: ***/\n// $ Every once in a while\n// $ Every once in a while\n// ... pause for 2 second ...\n// $ Every once in a while\n```\n\n## Getting simple-rate-limiter\n\nThe easiest way to get simple-rate-limiter is with [npm](http://npmjs.org/):\n\n    npm install simple-rate-limiter\n\nAlternatively you can clone this git repository:\n\n    git clone git://github.com/xavi-/node-simple-rate-limiter.git\n\n\n## Developed by\n* Xavi Ramirez\n\n## License\nThis project is released under [The MIT License](http://www.opensource.org/licenses/mit-license.php).\n","maintainers":[{"name":"xavi","email":"xavi.rmz@gmail.com"}],"time":{"modified":"2023-05-28T04:41:29.861Z","created":"2013-10-13T18:49:32.510Z","0.1.0":"2013-10-13T18:49:33.929Z","0.1.1":"2013-10-18T15:19:43.895Z","0.2.0":"2013-10-20T21:57:49.940Z","0.2.1":"2013-10-21T04:55:38.114Z","0.2.2":"2014-03-08T19:21:06.456Z","0.2.3":"2014-03-08T20:33:21.072Z","0.3.0":"2023-05-27T04:07:11.579Z","0.4.0":"2023-05-27T04:59:37.689Z","0.5.0":"2023-05-28T04:41:29.759Z"},"repository":{"type":"git","url":"git://github.com/xavi-/node-simple-rate-limiter.git"},"homepage":"https://github.com/xavi-/node-simple-rate-limiter#readme","keywords":["throttle","rate limit","queue calls"],"bugs":{"url":"https://github.com/xavi-/node-simple-rate-limiter/issues"},"readmeFilename":"README.md","users":{"tunnckocore":true,"juno":true,"shahzaib":true,"batz":true,"wfalkwallace":true,"juju.chen":true}}