feat: add helper function for title case

This commit is contained in:
Stefan Imhoff
2023-06-11 16:15:34 +02:00
parent 0ffeef5a65
commit 47d451e4d9
2 changed files with 8 additions and 0 deletions

View File

@@ -6,4 +6,5 @@ export * from './remark-widont';
export * from './sort-by-alphabet';
export * from './sort-by-date';
export * from './sort-by-sortkey';
export * from './titlecase';
export * from './word-count';

7
src/utils/titlecase.ts Normal file
View File

@@ -0,0 +1,7 @@
export const titleCase = (str: string) => {
let words = str.toLowerCase().split(' ');
for (let i = 0; i < words.length; i++) {
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
}
return words.join(' ');
};