diff --git a/README.md b/README.md index 78ddaf7..1637d87 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ files, generate content, or using other handy digital utilities. This page is ma ## Implemented Tools - **doc-converter**: Convert documents between different formats. -- **img-converter**: Convert images between different formats. +- **tmz-converter**: Convert between different timezones. - **rgb-to-hex**: Convert colors between different formats. - **qr-code-generator**: Generate QR codes for URLs, text, or other data. - **password-generator**: Generate secure passwords. - **regex-tester**: Test and validate your regular expressions. - **bg-remover**: Remove backgrounds from your images. - **word-counter**: Count words of your documents. -- **pomodoro-timer**: Use the Pomodoro technique to manage time. +- **video-to-audio**: Upload a video and extract your audio. ## Installation diff --git a/backend/server.ts b/backend/server.ts index 763dfe7..7593215 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -7,6 +7,7 @@ import { passwordGenerate } from "./src/routes/passwordgenerate.route"; import { regexTest } from "./src/routes/regextest.route"; import { tmzConvert } from "./src/routes/tmzconvert.route"; import { generateQRCode } from "./src/routes/generateqrcode.route"; +import { wordCounter } from "./src/routes/wordcounter.route"; const app = Fastify({ logger: true }); @@ -23,6 +24,7 @@ app.register(passwordGenerate); app.register(regexTest); app.register(tmzConvert); app.register(generateQRCode); +app.register(wordCounter); const PORT = process.env.PORT || 4000; app.listen({ port: Number(PORT), host: "0.0.0.0" }, () => { diff --git a/backend/src/routes/regextest.route.ts b/backend/src/routes/regextest.route.ts index 7f08bd6..025a3ef 100644 --- a/backend/src/routes/regextest.route.ts +++ b/backend/src/routes/regextest.route.ts @@ -34,12 +34,12 @@ export async function regexTest(app: FastifyInstance) { } const result = regexPattern.test(data.test); - + let output = ""; if (result) { - output = `The input matches the regular expression!`; + output = "The input matches the regular expression!"; } else { - output = `The input does not match the regular expression.`; + output = "The input does not match the regular expression."; } reply.header("Content-Type", "text/plain").status(200).send(output); diff --git a/backend/src/routes/wordcounter.route.ts b/backend/src/routes/wordcounter.route.ts new file mode 100644 index 0000000..3b747ac --- /dev/null +++ b/backend/src/routes/wordcounter.route.ts @@ -0,0 +1,34 @@ +import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify"; + +interface RequestBody { + input: string; +} + +export async function wordCounter(app: FastifyInstance) { + app.post( + "/api/word-counter", + async ( + request: FastifyRequest<{ Body: RequestBody }>, + reply: FastifyReply, + ) => { + try { + const data = request.body; + if (!data) { + return reply.status(400).send({ error: "No text declared!" }); + } else if (data.input == "") { + return reply.status(400).send({ error: "No text!" }); + } + + const output = data.input.trim().split(/\s+/).length; + + reply + .header("Content-Type", "text/plain") + .status(200) + .send(output.toString()); + } catch (error) { + console.error("Convert error:", error); + reply.status(500).send({ error: "Error while converting!" }); + } + }, + ); +} diff --git a/frontend/src/app/rgb-to-hex/page.tsx b/frontend/src/app/rgb-to-hex/page.tsx index a80141d..aa1825d 100644 --- a/frontend/src/app/rgb-to-hex/page.tsx +++ b/frontend/src/app/rgb-to-hex/page.tsx @@ -71,7 +71,7 @@ export default function RgbToHex() {

rgb-to-hex

) { + return ( + + {children} + + ); +} diff --git a/frontend/src/app/word-counter/page.tsx b/frontend/src/app/word-counter/page.tsx new file mode 100644 index 0000000..0434be1 --- /dev/null +++ b/frontend/src/app/word-counter/page.tsx @@ -0,0 +1,84 @@ +"use client"; + +import React, { useState } from "react"; +import Navbar from "../../components/Navbar"; +import Footer from "../../components/Footer"; +import Button from "../../components/Button"; + +export default function WordCounter() { + const [loading, setLoading] = useState(false); + const [output, setOutput] = useState(""); + + const countWords = async () => { + setLoading(true); + + const input = (document.getElementById("input") as HTMLInputElement).value; + + try { + const response = await fetch( + process.env.backend_url + "/api/word-counter", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ input: input }), + }, + ); + if (!response.ok) { + return new Error(`Error: ${response.statusText}`); + } + const output: string = await response.text(); + setOutput(output); + } catch (error) { + console.error("Error while converting:", error); + alert("Error while converting"); + } finally { + setLoading(false); + } + }; + + const clearInAndOutput = () => { + setOutput(""); + const input = document.getElementById("input") as HTMLInputElement; + input.value = ""; + }; + + return ( +
+ +
+

word-counter

+
+ +