Nevertheless! Party Metaphorically
Miss any of our Open RFC calls?Watch the recordings here! »

@da440dil/js-counter

0.2.0 • Public • Published

js-counter

Build Status Coverage Status

Distributed rate limiting with pluggable storage for storing counters state.

Basic usage

// Create new Counter
const counter = new Counter({ limit: 1, ttl: 100 })
try {
  // Increment counter and get remainder
  const remainder = await counter.count('key')
  // Counter value equals 1
  // Remainder value equals 0
  // Next counter.count('key') call will return TTLError
} catch (err) {
  if (err instanceof TTLError) {
    // Use err.ttl if need
  } else {
    // Handle err
  }
}

Example usage

Install

npm i @da440dil/js-counter

DownloadsWeekly Downloads

12

Version

0.2.0

License

MIT

Unpacked Size

15.1 kB

Total Files

17

Last publish

Collaborators

  • avatar