tokenized

1.0.7 • Public • Published

Tokenized

Easily create and manage a bucket of tokens

Package Dependencies

  • lodash

Usage

npm install --save tokenized

Methods

constructor

Add a token or array of tokens to your bucket when you instantiate it

const TokenBucket = require('tokenized')
const bucket = new TokenBucket()

The constructor will accept a single token or an array of tokens. You can also instantiate the TokenBucket class without a token if you do not have/need one right away.

addToken(token)

Adds a token to your bucket

bucket.addToken('single-token')

getToken()

Retrieves a token from your bucket

const token = bucket.getToken()

If no tokens are available, token will be null

addTokenAtInterval({token, [interval], [intervalValue]})

Adds token to your bucket at a regular interval

bucket.addTokenAtInterval('auto-token', 5, 'seconds')
  • token => your token to add to the bucket
  • interval => default 1 (number) the frequency to add this token to the bucket
  • intervalValue => default ms (string) value of the frequency number. options are: ms / milliseconds => milliseconds s / seconds => seconds m / minutes => minutes h / hours => hours d / days => days

stopAddingToken(token)

Stops the automatic adding of token that was started by using addTokenAtInterval

TokenBucket.stopAddingToken('auto-token')

Properties

limit

Set a limit for the number of tokens in your bucket at any one time. No tokens will be added above the limit.

Package Sidebar

Install

npm i tokenized

Weekly Downloads

5

Version

1.0.7

License

ISC

Last publish

Collaborators

  • _rkstar