diff --git a/src/utils/index.ts b/src/utils/index.ts index 3ca76a3..74c750c 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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'; diff --git a/src/utils/titlecase.ts b/src/utils/titlecase.ts new file mode 100644 index 0000000..981d3a1 --- /dev/null +++ b/src/utils/titlecase.ts @@ -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(' '); +};