1.0.7 • Published 10 years ago

tokenized v1.0.7

Weekly downloads
2
License
ISC
Repository
github
Last release
10 years ago

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.

1.0.7

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago