From 755fced384891f534da74f1c6ba8a625494f8206 Mon Sep 17 00:00:00 2001 From: Carlos Serrano Date: Mon, 14 Oct 2024 11:24:39 +0200 Subject: [PATCH] refactor: remove deprecated number argument for options BREAKING CHANGE: The function no longer supports passing a single number as the `options` argument. Use the `{ digits: }` format instead. See: https://github.com/expressjs/response-time/issues/25 --- HISTORY.md | 4 ++++ index.js | 7 ------- package.json | 1 - test/test.js | 49 +++++-------------------------------------------- 4 files changed, 9 insertions(+), 52 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 9816c3a..21fc4da 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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: }` format instead. + * deps: + - remove depd@2.0.0 2.3.3 / 2024-10-07 ========== diff --git a/index.js b/index.js index 645e32d..b865e76 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,6 @@ * @private */ -var deprecate = require('depd')('response-time') var onHeaders = require('on-headers') /** @@ -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) diff --git a/package.json b/package.json index 78888a0..125cd4e 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ ], "repository": "expressjs/response-time", "dependencies": { - "depd": "~2.0.0", "on-headers": "~1.0.1" }, "devDependencies": { diff --git a/test/test.js b/test/test.js index aa9dffe..3cdadaf 100644 --- a/test/test.js +++ b/test/test.js @@ -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) }) }) @@ -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()