Files
dancing-summarizer/src/util_string.ts
Lukas Wölfer 65f1a984cf Moved files
2025-06-11 23:09:19 +02:00

57 lines
960 B
TypeScript

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(' '));
}