bunch of refactor and styling changes, coming along nicely

This commit is contained in:
Sriram Hariharan
2023-03-07 01:42:26 -06:00
parent f48f39e67b
commit 04a82fb6a6
16 changed files with 225 additions and 63 deletions

View File

@@ -3,11 +3,22 @@
* @input The string to capitalize.
*/
export function capitalize(input: string): string {
try {
return input.charAt(0).toUpperCase() + input.substring(1).toLowerCase();
} catch (err) {
return input;
let capitalized = '';
const words = input.split(' ');
for (const word of words) {
if (word.includes('-')) {
const hyphenatedWords = word.split('-');
for (const hyphenatedWord of hyphenatedWords) {
capitalized += `${capitalizeFirstLetter(hyphenatedWord)}-`;
}
capitalized = capitalized.substring(0, capitalized.length - 1);
} else {
capitalized += capitalizeFirstLetter(word);
}
capitalized += ' ';
}
return capitalized;
}
/**
@@ -16,7 +27,7 @@ export function capitalize(input: string): string {
* @returns the string with the first letter capitalized
*/
export function capitalizeFirstLetter(input: string): string {
return input.charAt(0).toUpperCase() + input.slice(1);
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
}
/**