From 47d451e4d92dcf64e966a668d9b1cce4b8b8b040 Mon Sep 17 00:00:00 2001 From: Stefan Imhoff Date: Sun, 11 Jun 2023 16:15:34 +0200 Subject: [PATCH] feat: add helper function for title case --- src/utils/index.ts | 1 + src/utils/titlecase.ts | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 src/utils/titlecase.ts 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(' '); +};