tokenpipe
A simple, tested implementation of a 'token bucket' algorithm.
Code Example
const TokenPipe = ;const tokenPipe = ; { if tokenPipe console; else console; ;};
Motivation
The various token bucket implementations I came across either:
- didn't have tests
- weren't standalone, were part of a larger project
- were complex to configure
Installation
npm install --save tokenpipe
API Reference
factory method
const TokenPipe = ; const defaultPipe = ; // defaults to 1/s const rateDefinedPipe = ; const countAndPeriodDefinedPipe = ;
Object.assign
const TokenPipe = TokenPipe; const tokenPipe = Object;
TokenPipe.consume()
const TokenPipe = ;const tokenPipe = ; tokenPipe; // returns true if there are available tokens, false otherwise
Tests
npm run test
Contributors
If you'd like to contribute:
- Add tests for any new feature or bugfix
- Ensure your code passes jshint according to the .jshintrc
- Ensure your code is formatted according to the .jsbeautifyrc
- Submit a Pull Request
License
MIT