Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ jobs:
${{ runner.os }}-node-v${{ matrix.node }}-
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Run All Node.js Tests
run: npm run test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

lib/
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Rate limiting utility
![version: 1.2.1](https://img.shields.io/badge/version-1.2.1-%233b82f6)
![version: 1.2.2](https://img.shields.io/badge/version-1.2.2-%233b82f6)
![test: passing](https://img.shields.io/badge/tests-passing-%2316a34a)
![coverage: 100%](https://img.shields.io/badge/coverage-100%25-%2316a34a)
![build: passing](https://img.shields.io/badge/build-passing-%2316a34a)
Expand Down Expand Up @@ -42,6 +42,7 @@ If you want to reset the rate limit after a successful login, call [`rateLimit.r
- [Static method: `RateLimit.attempt(name, source, [attempts], [callback])`](#static-method-ratelimitattemptname-source-attempts-callback)
- [Static method: `RateLimit.check(name, source, [callback])`](#static-method-ratelimitcheckname-source-callback)
- [Static method: `RateLimit.clear(name)`](#static-method-ratelimitclearname)
- [Static method: `RateLimit.cleanup([name])`](#static-method-ratelimitcleanupname)
- [Static method: `RateLimit.create(name, limit, timeWindow)`](#static-method-ratelimitcreatename-limit-timewindow)
- [Static method: `RateLimit.delete(name)`](#static-method-ratelimitdeletename)
- [Static method: `RateLimit.get(name)`](#static-method-ratelimitgetname)
Expand All @@ -51,6 +52,7 @@ If you want to reset the rate limit after a successful login, call [`rateLimit.r
- [`rateLimit.attempt(source, [attempts], [callback])`](#ratelimitattemptsource-attempts-callback)
- [`rateLimit.check(source, [callback])`](#ratelimitchecksource-callback)
- [`rateLimit.clear()`](#ratelimitclear)
- [`rateLimit.cleanup()`](#ratelimitcleanup)
- [`rateLimit.delete()`](#ratelimitdelete)
- [`rateLimit.limit`](#ratelimitlimit)
- [`rateLimit.name`](#ratelimitname)
Expand Down Expand Up @@ -102,6 +104,13 @@ Clear rate limit attempts storage. This is equivalent to resetting all rate limi
- Returns: [`void`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type)
- Throws: [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) If the rate limit does not exist

<a name="static-method-ratelimitcleanupname"></a>

### Static method: `RateLimit.cleanup([name])`
Clean up rate limit attempts storage. This will remove expired entries.

- `name` [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The name of the rate limit. Default: `undefined`

<a name="static-method-ratelimitcreatename-limit-timewindow"></a>
### Static method: `RateLimit.create(name, limit, timeWindow)`
Create a new rate limit
Expand Down Expand Up @@ -154,6 +163,7 @@ Create a new rate limit
- `name` [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The name of the rate limit
- `limit` [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The number of attempts allowed per time window (e.g. 60)
- `timeWindow` [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The time window in seconds (e.g. 60)
- `cleanupInterval` [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Cleanup interval in seconds (see [`rateLimit.cleanup()`](#ratelimitcleanup)). Set to `-1` to disable periodic cleanup. Defaults to `timeWindow`
- Throws: [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) If the rate limit already exists

<a name="ratelimitattemptsource-attempts-callback"></a>
Expand Down Expand Up @@ -183,6 +193,12 @@ Clear rate limit attempts storage. This is equivalent to resetting all rate limi

- Returns: [`void`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type)

<a name="ratelimitcleanup"></a>
### `rateLimit.cleanup()`
Clean up rate limit attempts storage. This will remove expired entries.

- Returns: [`void`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type)

<a name="ratelimitdelete"></a>
### `rateLimit.delete()`
Delete the rate limit instance. After it is deleted, it should not be used any further without constructing a new instance.
Expand Down
16 changes: 16 additions & 0 deletions README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ If you want to reset the rate limit after a successful login, call [`rateLimit.r
- [Static method: `RateLimit.attempt(name, source, [attempts], [callback])`](#static-method-ratelimitattemptname-source-attempts-callback)
- [Static method: `RateLimit.check(name, source, [callback])`](#static-method-ratelimitcheckname-source-callback)
- [Static method: `RateLimit.clear(name)`](#static-method-ratelimitclearname)
- [Static method: `RateLimit.cleanup([name])`](#static-method-ratelimitcleanupname)
- [Static method: `RateLimit.create(name, limit, timeWindow)`](#static-method-ratelimitcreatename-limit-timewindow)
- [Static method: `RateLimit.delete(name)`](#static-method-ratelimitdeletename)
- [Static method: `RateLimit.get(name)`](#static-method-ratelimitgetname)
Expand All @@ -51,6 +52,7 @@ If you want to reset the rate limit after a successful login, call [`rateLimit.r
- [`rateLimit.attempt(source, [attempts], [callback])`](#ratelimitattemptsource-attempts-callback)
- [`rateLimit.check(source, [callback])`](#ratelimitchecksource-callback)
- [`rateLimit.clear()`](#ratelimitclear)
- [`rateLimit.cleanup()`](#ratelimitcleanup)
- [`rateLimit.delete()`](#ratelimitdelete)
- [`rateLimit.limit`](#ratelimitlimit)
- [`rateLimit.name`](#ratelimitname)
Expand Down Expand Up @@ -102,6 +104,13 @@ Clear rate limit attempts storage. This is equivalent to resetting all rate limi
- Returns: [`void`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type)
- Throws: [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) If the rate limit does not exist

<a name="static-method-ratelimitcleanupname"></a>

### Static method: `RateLimit.cleanup([name])`
Clean up rate limit attempts storage. This will remove expired entries.

- `name` [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The name of the rate limit. Default: `undefined`

<a name="static-method-ratelimitcreatename-limit-timewindow"></a>
### Static method: `RateLimit.create(name, limit, timeWindow)`
Create a new rate limit
Expand Down Expand Up @@ -154,6 +163,7 @@ Create a new rate limit
- `name` [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The name of the rate limit
- `limit` [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The number of attempts allowed per time window (e.g. 60)
- `timeWindow` [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) The time window in seconds (e.g. 60)
- `cleanupInterval` [`number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Cleanup interval in seconds (see [`rateLimit.cleanup()`](#ratelimitcleanup)). Set to `-1` to disable periodic cleanup. Defaults to `timeWindow`
- Throws: [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) If the rate limit already exists

<a name="ratelimitattemptsource-attempts-callback"></a>
Expand Down Expand Up @@ -183,6 +193,12 @@ Clear rate limit attempts storage. This is equivalent to resetting all rate limi

- Returns: [`void`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type)

<a name="ratelimitcleanup"></a>
### `rateLimit.cleanup()`
Clean up rate limit attempts storage. This will remove expired entries.

- Returns: [`void`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type)

<a name="ratelimitdelete"></a>
### `rateLimit.delete()`
Delete the rate limit instance. After it is deleted, it should not be used any further without constructing a new instance.
Expand Down
33 changes: 0 additions & 33 deletions lib/AttemptResult.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/AttemptResult.d.ts.map

This file was deleted.

1 change: 0 additions & 1 deletion lib/AttemptResult.js

This file was deleted.

146 changes: 0 additions & 146 deletions lib/RateLimit.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/RateLimit.d.ts.map

This file was deleted.

Loading