From a40db16621dd0dbd322edb5990d2fea33da1086e Mon Sep 17 00:00:00 2001 From: diego69-foda Date: Mon, 18 May 2026 08:23:42 -0300 Subject: [PATCH 1/2] pro PR --- src/convertToCase/detectCase.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/convertToCase/detectCase.js b/src/convertToCase/detectCase.js index c1825c76d..c024c5a12 100644 --- a/src/convertToCase/detectCase.js +++ b/src/convertToCase/detectCase.js @@ -10,7 +10,6 @@ function detectCase(text) { } if (text.toLowerCase() === text) { - if (text.includes('_') || text.includes('-')) { // There are no uppercase in the text, so it's one of the lower cases // See if they're snake or kebab if (text.includes('_')) { @@ -21,7 +20,6 @@ function detectCase(text) { return 'KEBAB'; } } - } if (text[0].toUpperCase() === text[0]) { return 'PASCAL'; From 361ff1427d091cadf78516e9e112041d8c1a3f28 Mon Sep 17 00:00:00 2001 From: diego69-foda Date: Tue, 19 May 2026 17:25:11 -0300 Subject: [PATCH 2/2] =?UTF-8?q?foi=20mal,=20esqueci=20que=20criar=20o=20PR?= =?UTF-8?q?=20mandava=20para=20a=20corre=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/createServer.js | 61 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/src/createServer.js b/src/createServer.js index 89724c920..b80c8e3ab 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -1,3 +1,58 @@ -// Write code here -// Also, you can create additional files in the src folder -// and import (require) them here +const http = require('http'); +const { convertToCase } = require('./convertToCase/convertToCase'); +const CASES = ['SNAKE', 'KEBAB', 'CAMEL', 'PASCAL', 'UPPER']; + +function validateParams(text, toCase) { + const errors = []; + + if (!text) { + errors.push({ + message: + 'Text to convert is required. Correct request is: "/?toCase=".', + }); + } + + if (!toCase) { + errors.push({ + message: + '"toCase" query param is required. Correct request is: "/?toCase=".' + }); + } + + if (toCase && !CASES.includes(toCase.toUpperCase())) { + errors.push({ + message: + 'This case is not supported. Available cases: SNAKE, KEBAB, CAMEL, PASCAL, UPPER.' + }); + } + + return errors; +} + +function createServer() { + return http.createServer(function (req, res) { + const [path, queryString] = req.url.split('?'); + + const params = new URLSearchParams(queryString); + const toCase = params.get('toCase'); + const errors = validateParams(path.slice(1), toCase); + + if (errors.length) { + res.setHeader('Content-Type', 'application/json'); + res.statusCode = 400; + res.end(JSON.stringify({ errors })); + + return; + } + + const target = { originalText: path.slice(1), targetCase: toCase }; + const result = convertToCase(path.slice(1), toCase); + + res.setHeader('Content-Type', 'application/json'); + res.statusCode = 200; + + res.end(JSON.stringify({ ...result, ...target })); + }); +} + +module.exports = { createServer };