formatToCapitalizeFirstWordLetter
The formatToCapitalizeFirstWordLetter function is a utility for formatting sentences by capitalizing the first letter of each word while converting the remaining letters to lowercase, creating a title case format.
Import
import { formatToCapitalizeFirstWordLetter } from "@arkyn/shared";
Parameters
The function accepts the following parameter:
sentence (required)
The sentence to be formatted. This can be any string containing one or more words separated by spaces. The function will process each word individually, capitalizing its first letter and converting the rest to lowercase.
Type: string
Usage example
The function returns a formatted string with the first letter of each word capitalized and the remaining letters in lowercase.
Type: string
import { formatToCapitalizeFirstWordLetter } from "@arkyn/shared";
const formatted1 = formatToCapitalizeFirstWordLetter("hello world");
const formatted2 = formatToCapitalizeFirstWordLetter("HELLO WORLD");
const formatted3 = formatToCapitalizeFirstWordLetter("hELLO WoRLd");
console.log(formatted1);
console.log(formatted2);
console.log(formatted3);
Notes
The function splits the input string by spaces to identify individual words, so multiple consecutive spaces will be preserved in the output.
Each word is processed independently, meaning that the first letter is capitalized regardless of its original case, and all subsequent letters are converted to lowercase.
Empty strings are handled gracefully and will return an empty string without errors.
The function works with any language that uses uppercase and lowercase letters, though results may vary depending on locale-specific capitalization rules.