transformCase
Converts a string between common case styles such as camelCase, kebab-case, snake_case, PascalCase, and Title Case.
Import
Section titled “Import”import { transformCase } from "1o1-utils";import { transformCase } from "1o1-utils/transform-case";Signature
Section titled “Signature”function transformCase({ str, to, preserveAcronyms }: TransformCaseParams): stringParameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
| str | string | Yes | The string to convert |
| to | "camel" | "kebab" | "snake" | "pascal" | "title" | Yes | Target case style |
| preserveAcronyms | boolean | No | When true, keeps all-uppercase words (e.g. "HTML") intact instead of lowercasing them. Default false. |
Returns
Section titled “Returns”string
Examples
Section titled “Examples”transformCase({ str: "hello world", to: "camel" });// => "helloWorld"
transformCase({ str: "hello world", to: "kebab" });// => "hello-world"
transformCase({ str: "hello world", to: "snake" });// => "hello_world"
transformCase({ str: "hello world", to: "pascal" });// => "HelloWorld"
transformCase({ str: "hello world", to: "title" });// => "Hello World"
transformCase({ str: "myVariableName", to: "kebab" });// => "my-variable-name"
transformCase({ str: "HTMLParser", to: "title", preserveAcronyms: true });// => "HTML Parser"
transformCase({ str: "HTMLParser", to: "camel", preserveAcronyms: true });// => "htmlParser"Edge Cases
Section titled “Edge Cases”- Throws if
stris not a string. - Throws if
tois not one of:camel,kebab,snake,pascal,title. - Returns
""for empty string. - Splits on word boundaries (uppercase transitions, hyphens, underscores, spaces).
- With
preserveAcronyms: trueincamel, the leading word is always lowercased (acronyms at position 0 would break camelCase convention).
Also known as
Section titled “Also known as”camelCase, snake_case, kebab-case, PascalCase, Title Case, convert case, acronym
Prompt suggestion
Section titled “Prompt suggestion”I'm using 1o1-utils (npm: https://www.npmjs.com/package/1o1-utils, GitHub: https://github.com/pedrotroccoli/1o1-utils, LLM context: https://pedrotroccoli.github.io/1o1-utils/llms.txt). Show me how to use transformCase to convert API snake_case keys to camelCase