toSentenceCase
Converts a string into sentence case format, where the first letter of the resulting sentence is capitalized, and all subsequent characters are lowercase unless naturally capitalized.> toSentenceCase(str: string): string
- str (string): The input string to be converted into sentence case. It can include mixed cases, numbers, or delimiters (e.g., spaces, dashes, underscores).
- Returns: A string formatted in sentence case, with the first letter capitalized and remaining text in proper case.
Example
import { toSentenceCase } from "string-toolset";
// Convert a regular phrase to sentence case
console.log(toSentenceCase("hello world")); // "Hello world"
// Handle camelCase
console.log(toSentenceCase("toSentenceCase")); // "To sentence case"
// Handle PascalCase
console.log(toSentenceCase("ToSentenceCase")); // "To sentence case"
// Handle kebab-case
console.log(toSentenceCase("to-sentence-case")); // "To sentence case"
// Handle snake_case
console.log(toSentenceCase("to_sentence_case")); // "To sentence case"
// Handle strings with numbers
console.log(toSentenceCase("chapter1 of the book")); // "Chapter1 of the book"
// Handle empty input
console.log(toSentenceCase("")); // ""
Use Cases
- Standardizing text for display in user interfaces.
- Improving readability of machine-generated identifiers or strings.
- Formatting text for titles, labels, or simple sentences.