export const SMALL_WORDS = new Set([ "a", "an", "and", "as", "at", "because", "but", "by", "en", "for", "if", "in", "neither", "nor", "of", "on", "only", "or", "over", "per", "so", "some", "than", "that", "the", "to", "up", "upon", "v", "versus", "via", "vs", "when", "with", "without", "yet", ]); export function capitalize(word: string): string { return word.charAt(0).toUpperCase() + word.slice(1); } export function camelToTitleCase(camelCaseStr: string): string { const titleCaseStr = camelCaseStr.replace(/([A-Z])/g, ' $1'); const words = titleCaseStr.split(' ') .map(v => v.toLowerCase()) .map(word => { if (SMALL_WORDS.has(word)) { return word; } return capitalize(word) }); return capitalize(words.join(' ')); }