Naming conventions: camelCase, snake_case and friends
Programming languages, databases and URLs each have their own customs for writing multi-word names. JavaScript variables use camelCase, Python functions use snake_case, CSS classes and URLs use kebab-case, and constants are often written in CONSTANT_CASE. Moving a name from one world to another means rewriting it by hand, and that is where typos creep in.
This converter splits your text into words once and shows it in all nine styles at the same time, so you can copy whichever one you need.
How to use it
- Type or paste a name or a phrase, in any style: user profile id, userProfileId or user_profile_id all work.
- Read the nine results: lower, UPPER, Title Case, Sentence case, camelCase, PascalCase, snake_case, kebab-case and CONSTANT_CASE.
- Copy the one you need.
- Check the output when the input contains acronyms or numbers, as described below.
Example: a function name with an acronym
parseHTTPResponse
camelCase: parseHttpResponse PascalCase: ParseHttpResponse snake_case: parse_http_response kebab-case: parse-http-response CONSTANT_CASE: PARSE_HTTP_RESPONSE
The converter spots the word boundary between HTTP and Response. In camelCase and PascalCase the acronym becomes Http, the style most modern style guides recommend.
How words are found
The tool breaks words at spaces, underscores and hyphens, at each change from a lowercase letter to an uppercase one, at the end of a run of capitals that is followed by a capitalised word, and between letters and digits. So base64Encode becomes base 64 encode, and snake_case gives base_64_encode.
Other punctuation is kept inside the word it touches. Remove commas and full stops first if you are converting a sentence into an identifier.
Which style goes where
camelCase is the norm for variables and functions in JavaScript, TypeScript and Java. PascalCase is used for classes, types and React components. snake_case is standard in Python, Ruby and most SQL databases. kebab-case suits URLs, file names and CSS class names, because search engines and browsers treat hyphens as word separators. CONSTANT_CASE marks constants and environment variables.
Title Case here capitalises every word, which is right for headings in some style guides. Editorial title case, which keeps small words like of and the in lowercase, depends on the style guide you follow and is better done by hand.
Questions
Does it handle accented letters?
Upper and lower case work for all languages. Word splitting on case changes only looks at the letters A to Z, so for accented names separate the words with spaces first.
Can I convert many names at once?
The tool treats the whole input as one name. Paste one identifier at a time for clean results.
Why did my acronym lose its capitals?
camelCase and PascalCase capitalise only the first letter of each word, so XMLParser becomes XmlParser. Restore the capitals by hand if your codebase keeps acronyms upper case.