Skip to content

Commit

Permalink
refactor: remove deprecated number argument for options (#30)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The function no longer supports passing a single number as the `options` argument. Use the `{ digits: <number> }` format instead.

See: #25
  • Loading branch information
carpasse authored Oct 20, 2024
1 parent bb51b2e commit f7f8363
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 52 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ Pending

* change:
- requires Node.js 18 or newer
- remove deprecated number argument for options
* breaking:
- drop support for Node.js 16 and older
- response-time no longer supports passing a single number as the `options` argument. Use the `{ digits: <number> }` format instead.
* deps:
- remove [email protected]

2.3.3 / 2024-10-07
==========
Expand Down
7 changes: 0 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* @private
*/

var deprecate = require('depd')('response-time')
var onHeaders = require('on-headers')

/**
Expand All @@ -38,12 +37,6 @@ module.exports = responseTime
function responseTime (options) {
var opts = options || {}

if (typeof options === 'number') {
// back-compat single number argument
deprecate('number argument: use {digits: ' + JSON.stringify(options) + '} instead')
opts = { digits: options }
}

// get the function to invoke
var fn = typeof opts !== 'function'
? createSetHeader(opts)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
],
"repository": "expressjs/response-time",
"dependencies": {
"depd": "~2.0.0",
"on-headers": "~1.0.1"
},
"devDependencies": {
Expand Down
49 changes: 5 additions & 44 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,11 @@ describe('responseTime()', function () {
.expect('X-Response-Time', 'bogus', done)
})

describe('with "digits"', function () {
it('should default to 3', function (done) {
var server = createServer()
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9]+\.[0-9]{3}ms$/, done)
})

it('should allow custom digits', function (done) {
var server = createServer(5)
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9]+\.[0-9]{5}ms$/, done)
})

it('should allow no digits', function (done) {
var server = createServer(0)
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9]+ms$/, done)
})
it('should default to 3 digits', function (done) {
var server = createServer()
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9]+\.[0-9]{3}ms$/, done)
})
})

Expand Down Expand Up @@ -82,29 +66,6 @@ describe('responseTime(fn)', function () {
})

describe('responseTime(options)', function () {
describe('with "digits" option', function () {
it('should default to 3', function (done) {
var server = createServer()
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9]+\.[0-9]{3}ms$/, done)
})

it('should allow custom digits', function (done) {
var server = createServer({ digits: 5 })
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9]+\.[0-9]{5}ms$/, done)
})

it('should allow no digits', function (done) {
var server = createServer({ digits: 0 })
request(server)
.get('/')
.expect('X-Response-Time', /^[0-9]+ms$/, done)
})
})

describe('with "header" option', function () {
it('should default to X-Response-Time', function (done) {
var server = createServer()
Expand Down

0 comments on commit f7f8363

Please sign in to comment.