Case Converter

Convert text between UPPERCASE, lowercase, Title Case, camelCase, snake_case, kebab-case, and more.

Text
100% Free
Runs in Browser

Preview

Source Code

Toggle the controls below the code to live-edit the initial state values.

case-converter.tsx
import { useState } from "react";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Copy, Check } from "lucide-react";

export default function CaseConverter() {
    const [text, setText] = useState("");
    const [copied, setCopied] = useState(false);

    const conversions = [
        { label: "UPPERCASE", fn: (t: string) => t.toUpperCase() },
        { label: "lowercase", fn: (t: string) => t.toLowerCase() },
        {
            label: "Title Case",
            fn: (t: string) =>
                t.replace(/\w\S*/g, (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()),
        },
        {
            label: "Sentence case",
            fn: (t: string) =>
                t.toLowerCase().replace(/(^\s*\w|[.!?]\s+\w)/g, (c) => c.toUpperCase()),
        },
        {
            label: "camelCase",
            fn: (t: string) =>
                t
                    .toLowerCase()
                    .replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()),
        },
        {
            label: "snake_case",
            fn: (t: string) =>
                t
                    .toLowerCase()
                    .replace(/[^a-zA-Z0-9]+/g, "_")
                    .replace(/^_|_$/g, ""),
        },
        {
            label: "kebab-case",
            fn: (t: string) =>
                t
                    .toLowerCase()
                    .replace(/[^a-zA-Z0-9]+/g, "-")
                    .replace(/^-|-$/g, ""),
        },
        {
            label: "aLtErNaTiNg",
            fn: (t: string) =>
                t
                    .split("")
                    .map((c, i) => (i % 2 === 0 ? c.toLowerCase() : c.toUpperCase()))
                    .join(""),
        },
    ];

    const [selected, setSelected] = useState(0);
    const result = text ? conversions[selected].fn(text) : "";

    const copyResult = async () => {
        await navigator.clipboard.writeText(result);
        setCopied(true);
        setTimeout(() => setCopied(false), 1500);
    };

    return (
        <div className="space-y-4">
            <Textarea
                placeholder="Enter your text here..."
                value={text}
                onChange={(e) => setText(e.target.value)}
                className="min-h-[120px] resize-y text-base"
            />
            <div className="flex flex-wrap gap-2">
                {conversions.map((c, i) => (
                    <Button
                        key={c.label}
                        variant={selected === i ? "default" : "outline"}
                        size="sm"
                        onClick={() => setSelected(i)}
                    >
                        {c.label}
                    </Button>
                ))}
            </div>
            {result && (
                <div className="relative rounded-lg border bg-muted/50 p-4">
                    <pre className="whitespace-pre-wrap break-words text-sm font-mono">
                        {result}
                    </pre>
                    <Button
                        variant="ghost"
                        size="icon"
                        className="absolute top-2 right-2"
                        onClick={copyResult}
                    >
                        {copied ? <Check className="h-4 w-4" /> : <Copy className="h-4 w-4" />}
                    </Button>
                </div>
            )}
        </div>
    );
}
Props Playground
2 props
0

Required Libraries

Install the external dependencies used by this tool.

bun add lucide-react react

Shadcn UI Setup

Add the required Shadcn UI primitives to your project.

bun x --bun shadcn@latest add badge button textarea

Shadcn UI Components

The following primitives are required in your @/components/ui directory.

Component Import Path
badge @/components/ui/badge
button @/components/ui/button
textarea @/components/ui/textarea

Imports

All import statements used in this tool.

Source Exports
react useState
@/components/ui/textarea Textarea
@/components/ui/button Button
@/components/ui/badge Badge
lucide-react Copy, Check

State Management

React state variables managed within this tool.

Variable Initial Value
text ""
copied false
selected 0

Variables & Constants

Constants and computed values defined in this tool.

Name Value
conversions [
result text ? conversions[selected].fn(text) : ""

Functional Logic

Internal functions that handle the tool's core logic.

Function Parameters Async
copyResult() None
Yes

External Resources

Documentation, tutorials, and package details for libraries used in this tool.