Skip to content

transformCase

Converts a string between common case styles such as camelCase, kebab-case, snake_case, PascalCase, and Title Case.

import { transformCase } from "1o1-utils";
import { transformCase } from "1o1-utils/transform-case";
function transformCase({ str, to, preserveAcronyms }: TransformCaseParams): string
NameTypeRequiredDescription
strstringYesThe string to convert
to"camel" | "kebab" | "snake" | "pascal" | "title"YesTarget case style
preserveAcronymsbooleanNoWhen true, keeps all-uppercase words (e.g. "HTML") intact instead of lowercasing them. Default false.

string

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"
  • Throws if str is not a string.
  • Throws if to is not one of: camel, kebab, snake, pascal, title.
  • Returns "" for empty string.
  • Splits on word boundaries (uppercase transitions, hyphens, underscores, spaces).
  • With preserveAcronyms: true in camel, the leading word is always lowercased (acronyms at position 0 would break camelCase convention).

camelCase, snake_case, kebab-case, PascalCase, Title Case, convert case, acronym

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