mirror of
https://github.com/theoleuthardt/werkzeugkiste.git
synced 2026-06-13 09:37:53 +00:00
regex-tester fully implemented
This commit is contained in:
parent
8787ee5c2b
commit
544ebaa7cf
4 changed files with 39 additions and 21 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
|
||||
interface RequestBody {
|
||||
input: string;
|
||||
regex: string;
|
||||
test: string;
|
||||
}
|
||||
|
||||
export async function regexTest(app: FastifyInstance) {
|
||||
|
|
@ -16,22 +17,25 @@ export async function regexTest(app: FastifyInstance) {
|
|||
if (!data) {
|
||||
return reply.status(400).send({ error: "No Regex declared!" });
|
||||
}
|
||||
const regexPattern = data.input;
|
||||
|
||||
// Überprüfe, ob der Regex-Pattern korrekt ist
|
||||
let regex: RegExp;
|
||||
// Überprüfe, ob die Felder regex und test vorhanden sind
|
||||
if (!data.regex || !data.test) {
|
||||
return reply.status(400).send({ error: "Regex or test string missing!" });
|
||||
}
|
||||
|
||||
// Versuche, den regulären Ausdruck zu erstellen
|
||||
let regexPattern;
|
||||
try {
|
||||
regex = new RegExp(regexPattern);
|
||||
regexPattern = new RegExp(data.regex);
|
||||
} catch (e) {
|
||||
return reply.status(400).send({ error: "Invalid regular expression!" });
|
||||
}
|
||||
|
||||
// Teste den Regex
|
||||
const result = regex.test(data.input);
|
||||
// Teste den Eingabestring gegen das Regex
|
||||
const result = regexPattern.test(data.test);
|
||||
|
||||
// Erstelle eine Ausgabe basierend auf dem Test-Ergebnis
|
||||
// Erstelle die Antwort basierend auf dem Testergebnis
|
||||
let output = "";
|
||||
|
||||
if (result) {
|
||||
output = `The input matches the regular expression!`;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import type { Metadata } from "next";
|
|||
import { toolLinks } from "@/constants";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: toolLinks[2].title,
|
||||
title: toolLinks[5].title,
|
||||
description: "Generator for secure strong passwords!",
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import type { Metadata } from "next";
|
|||
import { toolLinks } from "@/constants";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: toolLinks[2].title,
|
||||
title: toolLinks[3].title,
|
||||
description: "Tester for regular expressions!",
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ export default function RgbToHex() {
|
|||
|
||||
setLoading(true);
|
||||
|
||||
const input = (document.getElementById("input") as HTMLInputElement).value;
|
||||
const regex = (document.getElementById("regex") as HTMLInputElement).value;
|
||||
const test = (document.getElementById("test") as HTMLInputElement).value;
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
|
|
@ -24,7 +25,7 @@ export default function RgbToHex() {
|
|||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ input: input}),
|
||||
body: JSON.stringify({ regex: regex, test: test}),
|
||||
},
|
||||
);
|
||||
if (!response.ok) {
|
||||
|
|
@ -44,23 +45,36 @@ export default function RgbToHex() {
|
|||
|
||||
const clearInAndOutput = () => {
|
||||
setOutput("");
|
||||
const input = document.getElementById("input") as HTMLInputElement;
|
||||
input.value = "";
|
||||
const regex = document.getElementById("regex") as HTMLInputElement;
|
||||
const test = document.getElementById("test") as HTMLInputElement;
|
||||
test.value = "";
|
||||
regex.value = "";
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-screen w-screen bg-black text-white font-noto flex flex-col items-center">
|
||||
<Navbar renderHomeLink={true} />
|
||||
<div className="w-screen h-screen flex flex-col items-center justify-center">
|
||||
<h2 className="text-5xl font-bold text-white mb-16">password-generator</h2>
|
||||
<div className="border-2 border-white p-3 rounded-xl text-center text-white flex flex-row justify-between">
|
||||
<label className="mr-2" htmlFor="input">input:</label>
|
||||
<h2 className="text-5xl font-bold text-white mb-16">regex-tester</h2>
|
||||
<div className="border-2 border-white p-3 rounded-xl text-center text-white flex flex-col justify-between">
|
||||
<div>
|
||||
<label className="mr-2 m" htmlFor="regex">regex:</label>
|
||||
<input
|
||||
type="text"
|
||||
id="input"
|
||||
name="input"
|
||||
className="field-sizing-content bg-black border-1 border-white text-center"
|
||||
id="regex"
|
||||
name="regex"
|
||||
className="field-sizing-content bg-black border-1 border-white text-center mb-3"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mr-2" htmlFor="test">test string:</label>
|
||||
<input
|
||||
type="text"
|
||||
id="test"
|
||||
name="test"
|
||||
className="field-sizing-content bg-black border-1 border-white text-center"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className={"flex flex-row items-center gap-4 mt-4 mb-16"}>
|
||||
<Button
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue