{"_id":"stopcock","_rev":"4-c42a94b2adc86176025bfe949f7b9aed","name":"stopcock","description":"Limit the execution rate of a function using the token bucket algorithm","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"stopcock","version":"1.0.0","description":"Limit the execution rate of a function using the leaky bucket algorithm","homepage":"https://github.com/lpinca/stopcock","bugs":{"url":"https://github.com/lpinca/stopcock/issues"},"repository":{"type":"git","url":"git+https://github.com/lpinca/stopcock.git"},"author":{"name":"Luigi Pinca"},"license":"MIT","main":"index.js","keywords":["token bucket","rate-limit","function","throttle","promise"],"scripts":{"test-travis":"istanbul cover -x test.js tape --report lcovonly -- test.js","coverage":"istanbul cover -x test.js tape -- test.js","test":"tape test.js"},"engines":{"node":">=4.0.0"},"files":["index.js"],"devDependencies":{"istanbul":"0.4.x","pre-commit":"1.2.x","tape":"4.6.x"},"gitHead":"80f0cf21ad1d5339302ac1aae61e584b2bd11554","_id":"stopcock@1.0.0","_shasum":"3149af13e0938f0190e8185e181c4a9ae18c9ce5","_from":".","_npmVersion":"4.2.0","_nodeVersion":"7.8.0","_npmUser":{"name":"lpinca","email":"luigipinca@gmail.com"},"dist":{"shasum":"3149af13e0938f0190e8185e181c4a9ae18c9ce5","tarball":"https://registry.npmjs.org/stopcock/-/stopcock-1.0.0.tgz","integrity":"sha512-VIZnG33U0DmrYPAJbARG1pCJfUwevGO80qA414oHbl5FdvEqLxb32sp1cKEmdfEoCpkmTLu9Gdc+M1bs0nqwPQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAmJ6RUnpDCVtzFW7au26lxQvbk9gL4I5ck97+G9bDiCAiBC1IE7Dxkh10EvN7ckioYQ07fET3bIx5/xcyT1Y8DrqQ=="}]},"maintainers":[{"name":"lpinca","email":"luigipinca@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/stopcock-1.0.0.tgz_1490895525774_0.9374403937254101"},"directories":{}},"1.1.0":{"name":"stopcock","version":"1.1.0","description":"Limit the execution rate of a function using the token bucket algorithm","homepage":"https://github.com/lpinca/stopcock","bugs":{"url":"https://github.com/lpinca/stopcock/issues"},"repository":{"type":"git","url":"git+https://github.com/lpinca/stopcock.git"},"author":{"name":"Luigi Pinca"},"license":"MIT","main":"index.js","keywords":["token bucket","rate-limit","function","throttle","promise"],"scripts":{"coverage":"npm test && nyc report --reporter=html","test":"nyc tape test.js"},"engines":{"node":">=4.0.0"},"devDependencies":{"coveralls":"^3.0.3","nyc":"^14.0.0","tape":"^4.10.1"},"gitHead":"6937f4bd9318cc2298590a1aa5cff33517297d13","_id":"stopcock@1.1.0","_nodeVersion":"11.14.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-SNTAH55X9Ra5uE1JIxiPT3WwZiNMTcdCup+7qWOULNVUqiqi62qctNJ+x1R4znNudtkyu8LGc7Ok6Ldt+8N5iQ==","shasum":"e0c875d98b819c0baa0a0edf3bcba2d7dc643175","tarball":"https://registry.npmjs.org/stopcock/-/stopcock-1.1.0.tgz","fileCount":4,"unpackedSize":7072,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcvB8rCRA9TVsSAnZWagAAM1QQAJeEAIMrdDFBydy9Qvh1\nMXzeDUyG1lSCyjf+DaFIbcF8IvA0RhDo03pq8GAYFlKSfra2QdvKg8vZJdN5\n9NIrCiVP05aAIs5t82OIqsMDCPsnotoqIbLsROdsTettujw87k80wv0tCGLT\noDOzZPtOhdVNt15ha/14UgXw9DsMIqF0SPKiihqIUR+PHO993LViIGzutx3D\nd2aWmFs3CPxViszkxAMqnmPEFvXbXOwJp2uHaSQQw8d6PTaOLXd8t3LYN5zI\np7hlNoJuZO8sVovYX62fCYy2Nxr8cCivZnxoFWePbvB08SojrNO7x4F/BKZm\nByLYD8/+q35UWGa2Fn91z5mscAW2tyv5CLx5OSqJLVq+dCPASjA9Cu7kxSRi\nHFyiIiS09uUnEQiJwlIsb+Lyv/oOrvHqrMlunPuNwlPSmhXf+Wawp8IGagOJ\nsmChPq2g9S2Pw1V3b144g9Wkr1D+6vW4YCz9D66w3GSSLjLyDzhdM/RzfqHM\nAm0piZktaigB56NWsbJocJ/FQxeIFT3VOV9j3dFee+hHgXz9M5YAovkwsDwH\n/afYt6dSO0PSwDQ3tn02pqLwMJaju2O0Oyqq+T7GpZD6Ww8f7WBlpbsug/FA\n/GeXPsD9Sh6FkcNynieaSo7NlG3YJFAXhqe7CaWWcCXUWYVIPgFPFxxe+Ulw\n1o/+\r\n=S4ZL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHRENYHr42SYh87TfBrzJ6qpkMHglcCZ8lRwXI9WgshRAiEAhJr8bnnm6fe9CeTlcBZYxKstvR+X+2Pjn8t5r2Akr9E="}]},"maintainers":[{"name":"lpinca","email":"luigipinca@gmail.com"}],"_npmUser":{"name":"lpinca","email":"luigipinca@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stopcock_1.1.0_1555832618309_0.6661123323727625"},"_hasShrinkwrap":false}},"readme":"# stopcock\n\n[![Version npm][npm-stopcock-badge]][npm-stopcock]\n[![Build Status][travis-stopcock-badge]][travis-stopcock]\n[![Coverage Status][coverage-stopcock-badge]][coverage-stopcock]\n\nLimit the execution rate of a function using the token bucket algorithm. Useful\nfor scenarios such as REST APIs consumption where the amount of requests per\nunit of time should not exceed a given threshold.\n\n## Install\n\n```\nnpm install --save stopcock\n```\n\n## API\n\nThe module exports a single function that takes two arguments.\n\n### `stopcock(fn[, options])`\n\nReturns a function which should be called instead of `fn`.\n\n#### Arguments\n\n- `fn` - The function to rate limit calls to.\n- `options` - A plain JavaScript object that contains the configuration options.\n\n#### Options\n\n- `limit` - The maximum number of allowed calls per `interval`. Defaults to 2.\n- `interval` - The timespan where `limit` is calculated. Defaults to 1000.\n- `bucketSize` - The capacity of the bucket. Defaults to 40.\n- `queueSize` - The maximum size of the internal queue. Defaults to 2^32 - 1\n  which is the maximum array size in JavaScript.\n\n#### Return value\n\nA function that returns a promise which resolves to the value returned by the\noriginal `fn` function. The returned function has a `size` accessor property\nwhich returns the internal queue size. When the queue is at capacity the promise\nis rejected.\n\n#### Example\n\n```js\nconst stopcock = require('stopcock');\n\nfunction request(i) {\n  return Promise.resolve(`${i} - ${new Date().toISOString()}`);\n}\n\nfunction log(data) {\n  console.log(data);\n}\n\nconst get = stopcock(request, { bucketSize: 5 });\n\nfor (let i = 0; i < 10; i++) {\n  get(i).then(log);\n}\n\n/*\n0 - 2017-03-30T16:46:39.938Z\n1 - 2017-03-30T16:46:39.940Z\n2 - 2017-03-30T16:46:39.940Z\n3 - 2017-03-30T16:46:39.940Z\n4 - 2017-03-30T16:46:39.940Z\n5 - 2017-03-30T16:46:40.443Z\n6 - 2017-03-30T16:46:40.943Z\n7 - 2017-03-30T16:46:41.441Z\n8 - 2017-03-30T16:46:41.942Z\n9 - 2017-03-30T16:46:42.439Z\n*/\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-stopcock-badge]: https://img.shields.io/npm/v/stopcock.svg\n[npm-stopcock]: https://www.npmjs.com/package/stopcock\n[travis-stopcock-badge]: https://img.shields.io/travis/lpinca/stopcock/master.svg\n[travis-stopcock]: https://travis-ci.org/lpinca/stopcock\n[coverage-stopcock-badge]: https://img.shields.io/coveralls/lpinca/stopcock/master.svg\n[coverage-stopcock]: https://coveralls.io/r/lpinca/stopcock?branch=master\n","maintainers":[{"name":"lpinca","email":"luigipinca@gmail.com"}],"time":{"modified":"2022-06-27T00:30:03.673Z","created":"2017-03-30T17:38:47.849Z","1.0.0":"2017-03-30T17:38:47.849Z","1.1.0":"2019-04-21T07:43:38.508Z"},"homepage":"https://github.com/lpinca/stopcock","keywords":["token bucket","rate-limit","function","throttle","promise"],"repository":{"type":"git","url":"git+https://github.com/lpinca/stopcock.git"},"author":{"name":"Luigi Pinca"},"bugs":{"url":"https://github.com/lpinca/stopcock/issues"},"license":"MIT","readmeFilename":"README.md"}