From aec60654676597d696f2b21a8bd36ef5be49dbe3 Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Thu, 31 Oct 2024 01:49:43 +0100 Subject: [PATCH 1/2] Refactor firstchar function for conciseness and modern syntax - Replaced var with const for improved variable management - Used optional chaining for a more concise return statement - Enhanced readability while preserving functionality --- lib/types/json.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/types/json.js b/lib/types/json.js index 30bf8cab..bc2de839 100644 --- a/lib/types/json.js +++ b/lib/types/json.js @@ -189,11 +189,8 @@ function createStrictSyntaxError (str, char) { */ function firstchar (str) { - var match = FIRST_CHAR_REGEXP.exec(str) - - return match - ? match[1] - : undefined + const match = FIRST_CHAR_REGEXP.exec(str) + return match?.[1] } /** From a6f29408900ce074159fbf2e6ac2c16de9c6d570 Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Thu, 31 Oct 2024 01:57:03 +0100 Subject: [PATCH 2/2] Refactor typeChecker function for conciseness and modern syntax - Replaced traditional function declaration with an arrow function for brevity - Utilized implicit return to streamline the code - Enhanced readability while maintaining functionality --- lib/types/json.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/types/json.js b/lib/types/json.js index bc2de839..901b16c6 100644 --- a/lib/types/json.js +++ b/lib/types/json.js @@ -241,7 +241,5 @@ function normalizeJsonSyntaxError (error, obj) { */ function typeChecker (type) { - return function checkType (req) { - return Boolean(typeis(req, type)) - } + return (req) => Boolean(typeis(req, type)) }