Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swap out ms for @lukeed/ms #312

Merged
merged 2 commits into from
Jul 28, 2023
Merged
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: 0 additions & 3 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
ts: false
jsx: false
flow: false
jobs: 1

branches: 96
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const fp = require('fastify-plugin')
const ms = require('ms')
const ms = require('@lukeed/ms')

const LocalStore = require('./store/LocalStore')
const RedisStore = require('./store/RedisStore')
Expand Down Expand Up @@ -56,7 +56,7 @@ async function fastifyRateLimit (fastify, settings) {

// define the global Time Window
globalParams.timeWindow = typeof settings.timeWindow === 'string'
? ms(settings.timeWindow)
? ms.parse(settings.timeWindow)
: typeof settings.timeWindow === 'number' && !isNaN(settings.timeWindow)
? settings.timeWindow
: 1000 * 60
Expand Down Expand Up @@ -154,7 +154,7 @@ async function fastifyRateLimit (fastify, settings) {
function makeParams (routeParams) {
const result = Object.assign({}, globalParams, routeParams)
if (typeof result.timeWindow === 'string') {
result.timeWindow = ms(result.timeWindow)
result.timeWindow = ms.parse(result.timeWindow)
}
if (typeof result.timeWindow === 'number') {
result.timeWindowInSeconds = (result.timeWindow / 1000) | 0
Expand All @@ -179,7 +179,7 @@ function rateLimitRequestHandler (params, pluginComponent) {
const theStore = pluginComponent.store
return async function onRequestRateLimiter (req, res) {
const run = pluginComponent.run
const after = ms(params.timeWindow, { long: true })
const after = ms.format(params.timeWindow, true)

if (req[run]) {
return
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"tsd": "^0.28.0"
},
"dependencies": {
"@lukeed/ms": "^2.0.1",
"fastify-plugin": "^4.0.0",
"ms": "^2.1.3",
"tiny-lru": "^11.0.0"
},
"publishConfig": {
Expand Down