Typed String Case Converters
Utilities that convert strings into various case formats while preserving TypeScript string literal types.
Overview
The typed case converters convert string literals into various case formats while preserving their compile-time TypeScript types. This provides complete type safety and IDE autocompletion when working with string constant values.
Warning
- TypeScript Character Limit: For reliable literal type inference, TypeScript supports strings up to ~45 characters. For longer strings, type inference might fallback to
string. - No Acronym Handling: These functions do not support custom acronym preservation rules. Use convertStringCase instead if you need to handle acronyms.
Import
import {
toCamelCase,
toPascalCase,
toSnakeCase,
toKebabCase,
toTrainCase,
toDotCase,
toPathCase,
toConstantCase,
toPascalSnakeCase,
toTitleCase,
toSentenceCase
} from 'toolbox-x/change-case';Available Converters
toCamelCase
Converts a string into camelCase format.
toCamelCase("hello world") // "helloWorld"
toCamelCase("my-awesome_string") // "myAwesomeString"
toCamelCase("value*with+custom", "*+") // "valueWithCustom"toPascalCase
Converts a string into PascalCase format.
toPascalCase("hello world") // "HelloWorld"
toPascalCase("my-awesome_string") // "MyAwesomeString"
toPascalCase("value*with+custom", "*+") // "ValueWithCustom"toSnakeCase
Converts a string into snake_case format.
toSnakeCase("hello world") // "hello_world"
toSnakeCase("my-awesome_string") // "my_awesome_string"
toSnakeCase("value*with+custom", "*+") // "value_with_custom"toKebabCase
Converts a string into kebab-case format.
toKebabCase("hello world") // "hello-world"
toKebabCase("my-awesome_string") // "my-awesome-string"
toKebabCase("value*with+custom", "*+") // "value-with-custom"toTrainCase
Converts a string into Train-Case format.
toTrainCase("hello world") // "Hello-World"
toTrainCase("my-awesome_string") // "My-Awesome-String"
toTrainCase("value*with+custom", "*+") // "Value-With-Custom"toDotCase
Converts a string into dot.case format.
toDotCase("hello world") // "hello.world"
toDotCase("my-awesome_string") // "my.awesome.string"
toDotCase("value*with+custom", "*+") // "value.with.custom"toPathCase
Converts a string into path/case format.
toPathCase("hello world") // "hello/world"
toPathCase("my-awesome_string") // "my/awesome/string"
toPathCase("value*with+custom", "*+") // "value/with/custom"toConstantCase
Converts a string into CONSTANT_CASE format.
toConstantCase("hello world") // "HELLO_WORLD"
toConstantCase("my-awesome_string") // "MY_AWESOME_STRING"
toConstantCase("value*with+custom", "*+") // "VALUE_WITH_CUSTOM"toPascalSnakeCase
Converts a string into Pascal_Snake_Case format.
toPascalSnakeCase("hello world") // "Hello_World"
toPascalSnakeCase("my-awesome_string") // "My_Awesome_String"
toPascalSnakeCase("value*with+custom", "*+") // "Value_With_Custom"toTitleCase
Converts a string into Title Case format.
toTitleCase("hello world") // "Hello World"
toTitleCase("my-awesome_string") // "My Awesome String"
toTitleCase("value*with+custom", "*+") // "Value with Custom"toSentenceCase
Converts a string into Sentence case format.
toSentenceCase("hello world") // "Hello world"
toSentenceCase("my-awesome_string") // "My awesome string"
toSentenceCase("value*with+custom", "*+") // "Value with custom"Delimiters
All converters recognize space ( ), hyphen (-), underscore (_), period (.), and forward slash (/) as default delimiters. You can pass a string of custom delimiter characters as the second argument:
toCamelCase("hello*world+test", "*+") // "helloWorldTest"See Also
- convertStringCase - For runtime case conversion with acronym and Unicode support.
- capitalizeString - For basic capitalization.
Last updated: Mon, Jun 15, 2026 11:04:47AM (UTC)
