Skip to content
Closed
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
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ limit.get(function(err, limit){
## Result Object
- `total` - `max` value
- `remaining` - number of calls left in current `duration` without decreasing current `get`
- `reset` - time since epoch in seconds that the rate limiting period will end (or already ended)
- `reset` - time since epoch in seconds at which the rate limiting period will end (or already ended)
- `resetMs` - time since epoch in milliseconds at which the rate limiting period will end (or already ended)

## Options

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Limiter.prototype.get = function (fn) {
fn(null, {
remaining: count < max ? max - count : 0,
reset: Math.floor((oldest + duration * 1000) / 1000000),
resetMs: Math.floor((oldest + duration * 1000) / 1000),
total: max
});
});
Expand Down
17 changes: 17 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ var Limiter = require('..'),
});
});

describe('.resetMs', function() {
it('should represent the next reset time in UTC epoch milliseconds', function(done) {
var limit = new Limiter({
max: 5,
duration: 60000,
id: 'something',
db: db
});
limit.get(function(err, res) {
var left = res.resetMs - Date.now();
Number.isInteger(left).should.be.true;
left.should.be.within(0, 60000);
done();
});
});
});

describe('when the limit is exceeded', function() {
it('should retain .remaining at 0', function(done) {
var limit = new Limiter({
Expand Down