tally-ttl 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +61 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1 +1,61 @@
1
- # tally-ttl
1
+ ## Simple tally tracker with induvidual TTL per tally (sliding window tally)
2
+
3
+ Useful for tracking how many events have occured in a recent window of time.
4
+
5
+ Each tally has it's own TTL (rounded to 1 second increments).
6
+
7
+ Contains both CommonJS and ESM modules for counting items. Typescript types included with ESM version.
8
+
9
+ **Installation**
10
+
11
+ ```
12
+ npm install tally-ttl
13
+ ```
14
+
15
+ **Usage Examples**
16
+
17
+ ```javascript
18
+ // For ESM use
19
+ import TallyTTL from "tally-ttl";
20
+
21
+ // OR, for CommonJS use
22
+ const TallyTTL = require("tally-ttl");
23
+ ```
24
+
25
+ ```javascript
26
+ // Example: 5 minute (300 second) tally
27
+ const userActionTally = new TallyTTL({ defaultTtl: 60 });
28
+
29
+ // in this case, we want to track how many times a user has failed to login
30
+ userActionTally.tally("bob-login-failed");
31
+ userActionTally.tally("bob-login-failed");
32
+
33
+ let bobLoginFailedCount = userActionTally.get("bob-login-failed");
34
+ // bobLoginFailedCount would be 2
35
+
36
+ // wait a second...
37
+
38
+ // Each call to tally() gets it's own expiration time, so calling it again here would last 60 seconds (the defaultTtl) from this current time
39
+ // add another one
40
+ userActionTally.tally("bob-login-failed");
41
+
42
+ bobLoginFailedCount = userActionTally.get("bob-login-failed");
43
+ // bobLoginFailedCount would be 3
44
+
45
+ // wait 60 seconds...
46
+
47
+ bobLoginFailedCount = userActionTally.get("bob-login-failed");
48
+ // bobLoginFailedCount would be 1 since the first two have expired by now
49
+
50
+ // wait a second...
51
+
52
+ // out third call has now expired as well
53
+ bobLoginFailedCount = userActionTally.get("bob-login-failed");
54
+ // bobLoginFailedCount would be 0
55
+ ```
56
+
57
+ ```javascript
58
+ // You can also overriude the defaultTtl for an induvidual tally
59
+ // Example: this particular tally would persisit for 15 minutes (900 seconds)
60
+ userActionTally.tally("bob-login-failed", 3600);
61
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tally-ttl",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "A simple library to tally items with a configurable per-tally TTL",
5
5
  "keywords": [
6
6
  "tally",