From 37489a4698e452ee99a72e32f1a9d69a60f4035c Mon Sep 17 00:00:00 2001 From: typist Date: Tue, 28 Oct 2025 04:38:42 +0800 Subject: [PATCH] feat: add Base64 encoder/decoder tool component - Implemented a new Base64 tool with encoding and decoding functionalities. - Updated the tool index to include the new Base64 component with appropriate description and icon. --- src/components/tool/base64.tsx | 70 ++++++++++++++++++++++++++++++++++ src/components/tool/index.tsx | 10 ++++- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/components/tool/base64.tsx diff --git a/src/components/tool/base64.tsx b/src/components/tool/base64.tsx new file mode 100644 index 0000000..f47b957 --- /dev/null +++ b/src/components/tool/base64.tsx @@ -0,0 +1,70 @@ +import { useState, type FC } from "react"; +import { Textarea } from "@/components/ui/textarea"; +import { Button } from "@/components/ui/button"; +import { toast } from "sonner"; +import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react"; + +const Tool: FC = () => { + const [decoded, setDecoded] = useState(""); + const [encoded, setEncoded] = useState(""); + + const encode = () => { + try { + const encoded64 = btoa(decoded); + setEncoded(encoded64); + setDecoded(""); + toast.success("encoded successfully"); + } catch (error: unknown) { + if (error instanceof Error) { + toast.error(error.message); + } else { + toast.error("encoding failed"); + } + } + }; + + const decode = () => { + try { + const decoded64 = atob(encoded); + setDecoded(decoded64); + setEncoded(""); + toast.success("decoded successfully"); + } catch (error: unknown) { + if (error instanceof Error) { + toast.error(error.message); + } else { + toast.error("decoding failed"); + } + } + }; + + return ( +
+