Case Converter: how it works and how to build one
camelCase, snake_case, kebab-case, Title Case and more. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Convert names between the styles used in code, URLs and headings. Each line is converted separately, so you can paste a whole list of column names at once.
When to use it
- Renaming variables
- Turning headings into slugs or constants
- Cleaning data columns
How to use it
- Paste text, one item per line if you have a list.
- Pick a case.
- Copy the result.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/case-converter
How it works
Every case style is the same words joined differently. The converter first splits text into words, treating spaces, underscores, dashes and camelCase humps as boundaries. Then it joins them in the chosen style: camelCase, snake_case, kebab-case and so on.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
case.ts (ts)
const words = (s: string) =>
s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
.split(/[^A-Za-z0-9]+/).filter(Boolean).map((w) => w.toLowerCase());
const cap = (w: string) => w[0].toUpperCase() + w.slice(1);
export const CASES = {
camel: (s: string) => words(s).map((w, i) => (i ? cap(w) : w)).join(""),
pascal: (s: string) => words(s).map(cap).join(""),
snake: (s: string) => words(s).join("_"),
kebab: (s: string) => words(s).join("-"),
constant: (s: string) => words(s).join("_").toUpperCase(),
title: (s: string) => words(s).map(cap).join(" "),
};
Make it production-ready
- Keep acronyms like ID and URL upper case in Title Case.
- Convert each line separately.
Questions
How does it split words?
On spaces, dashes, underscores, dots and changes from lower to upper case, so myHTTPServer becomes my http server.
Free, runs in your browser, nothing is uploaded.