From 61434d0216e16e0092e76f1232c2b80cad87a2bd Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Tue, 29 Oct 2024 23:34:31 +0100 Subject: [PATCH 1/2] Refactor req.is for cleaner argument handling - Simplified the logic for accepting both array and flattened arguments. - Used Array.from for improved readability and conciseness. --- lib/request.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/request.js b/lib/request.js index 372a9915e96..063f88a236f 100644 --- a/lib/request.js +++ b/lib/request.js @@ -255,16 +255,7 @@ defineGetter(req, 'query', function query(){ */ req.is = function is(types) { - var arr = types; - - // support flattened arguments - if (!Array.isArray(types)) { - arr = new Array(arguments.length); - for (var i = 0; i < arr.length; i++) { - arr[i] = arguments[i]; - } - } - + const arr = Array.isArray(types) ? types : Array.from(arguments); return typeis(this, arr); }; From 83b6642d510db45e481840cd42ef89ee4378a45d Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Tue, 29 Oct 2024 23:34:31 +0100 Subject: [PATCH 2/2] Refactor req.is for cleaner argument handling - Simplified the logic for accepting both array and flattened arguments. - Used Array.from for improved readability and conciseness. refactor: simplify req.is implementation while preserving support for multiple types - Refactored to use Array.isArray and Array.from for cleaner syntax. - Maintained existing support for both array and argument inputs. - Updated JSDoc to reflect the use of `(String|Array)` for types parameter. --- lib/request.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/request.js b/lib/request.js index 372a9915e96..ee3fb961cd0 100644 --- a/lib/request.js +++ b/lib/request.js @@ -249,22 +249,13 @@ defineGetter(req, 'query', function query(){ * req.is('html'); * // => false * - * @param {String|Array} types... - * @return {String|false|null} + * @param {(String|Array)} types... + * @return {(String|false|null)} * @public */ req.is = function is(types) { - var arr = types; - - // support flattened arguments - if (!Array.isArray(types)) { - arr = new Array(arguments.length); - for (var i = 0; i < arr.length; i++) { - arr[i] = arguments[i]; - } - } - + const arr = Array.isArray(types) ? types : Array.from(arguments); return typeis(this, arr); };