@@ 1-48 (lines=48) @@ | ||
1 | "use strict"; |
|
2 | Object.defineProperty(exports, "__esModule", { value: true }); |
|
3 | var RateLimit = /** @class */ (function () { |
|
4 | function RateLimit(calls, time, callsLeft, timeLeft) { |
|
5 | if (callsLeft === void 0) { callsLeft = calls; } |
|
6 | if (timeLeft === void 0) { timeLeft = time; } |
|
7 | this.originCalls = calls; |
|
8 | this.originTime = time; |
|
9 | this.currentCalls = callsLeft; |
|
10 | this.currentTime = timeLeft; |
|
11 | this.active = false; |
|
12 | } |
|
13 | RateLimit.prototype.reset = function () { |
|
14 | this.currentCalls = this.originCalls; |
|
15 | this.currentTime = this.originTime; |
|
16 | }; |
|
17 | RateLimit.prototype.decrementCall = function () { this.currentCalls--; }; |
|
18 | RateLimit.prototype.decrementTime = function () { this.currentTime--; }; |
|
19 | RateLimit.prototype.getOriginalCalls = function () { return this.originCalls; }; |
|
20 | RateLimit.prototype.getOriginalTime = function () { return this.originTime; }; |
|
21 | RateLimit.prototype.getCallsLeft = function () { return this.currentCalls; }; |
|
22 | RateLimit.prototype.getTimeLeft = function () { return this.currentTime; }; |
|
23 | RateLimit.prototype.isActive = function () { return this.active; }; |
|
24 | RateLimit.prototype.setActive = function (active) { |
|
25 | this.active = active; |
|
26 | }; |
|
27 | RateLimit.prototype.startTimer = function () { |
|
28 | var _this = this; |
|
29 | this.setActive(true); |
|
30 | this.timer = setInterval(function () { |
|
31 | _this.decrementTime(); |
|
32 | if (_this.getTimeLeft() <= 0) { |
|
33 | _this.breakTimer(); |
|
34 | } |
|
35 | }, 1000); |
|
36 | }; |
|
37 | RateLimit.prototype.breakTimer = function () { |
|
38 | this.reset(); |
|
39 | this.setActive(false); |
|
40 | clearInterval(this.timer); |
|
41 | }; |
|
42 | RateLimit.prototype.restartTimer = function () { |
|
43 | this.breakTimer(); |
|
44 | this.startTimer(); |
|
45 | }; |
|
46 | return RateLimit; |
|
47 | }()); |
|
48 | exports.RateLimit = RateLimit; |
|
49 | //# sourceMappingURL=ratelimit.js.map |
@@ 1-46 (lines=46) @@ | ||
1 | var RateLimit = /** @class */ (function () { |
|
2 | function RateLimit(calls, time, callsLeft, timeLeft) { |
|
3 | if (callsLeft === void 0) { callsLeft = calls; } |
|
4 | if (timeLeft === void 0) { timeLeft = time; } |
|
5 | this.originCalls = calls; |
|
6 | this.originTime = time; |
|
7 | this.currentCalls = callsLeft; |
|
8 | this.currentTime = timeLeft; |
|
9 | this.active = false; |
|
10 | } |
|
11 | RateLimit.prototype.reset = function () { |
|
12 | this.currentCalls = this.originCalls; |
|
13 | this.currentTime = this.originTime; |
|
14 | }; |
|
15 | RateLimit.prototype.decrementCall = function () { this.currentCalls--; }; |
|
16 | RateLimit.prototype.decrementTime = function () { this.currentTime--; }; |
|
17 | RateLimit.prototype.getOriginalCalls = function () { return this.originCalls; }; |
|
18 | RateLimit.prototype.getOriginalTime = function () { return this.originTime; }; |
|
19 | RateLimit.prototype.getCallsLeft = function () { return this.currentCalls; }; |
|
20 | RateLimit.prototype.getTimeLeft = function () { return this.currentTime; }; |
|
21 | RateLimit.prototype.isActive = function () { return this.active; }; |
|
22 | RateLimit.prototype.setActive = function (active) { |
|
23 | this.active = active; |
|
24 | }; |
|
25 | RateLimit.prototype.startTimer = function () { |
|
26 | var _this = this; |
|
27 | this.setActive(true); |
|
28 | this.timer = setInterval(function () { |
|
29 | _this.decrementTime(); |
|
30 | if (_this.getTimeLeft() <= 0) { |
|
31 | _this.breakTimer(); |
|
32 | } |
|
33 | }, 1000); |
|
34 | }; |
|
35 | RateLimit.prototype.breakTimer = function () { |
|
36 | this.reset(); |
|
37 | this.setActive(false); |
|
38 | clearInterval(this.timer); |
|
39 | }; |
|
40 | RateLimit.prototype.restartTimer = function () { |
|
41 | this.breakTimer(); |
|
42 | this.startTimer(); |
|
43 | }; |
|
44 | return RateLimit; |
|
45 | }()); |
|
46 | export { RateLimit }; |
|
47 | //# sourceMappingURL=ratelimit.js.map |