From 315f52ce3a43a774f22cc07833797cdcda6a4e9a Mon Sep 17 00:00:00 2001 From: Sakura Knoll Date: Sun, 2 Jan 2022 14:49:23 +0900 Subject: [PATCH] Extract capitalize method --- src/components/atoms/TypeLabel.tsx | 4 +++- src/lib/string.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/atoms/TypeLabel.tsx b/src/components/atoms/TypeLabel.tsx index 363b191c..6b94c572 100644 --- a/src/components/atoms/TypeLabel.tsx +++ b/src/components/atoms/TypeLabel.tsx @@ -1,4 +1,5 @@ import { Flex, Text } from '@theme-ui/components' +import { capitalize } from '../../lib/string' import SquareImageBox from './SquareImageBox' interface TypeLabelProps { @@ -6,7 +7,8 @@ interface TypeLabelProps { } const TypeLabel = ({ type }: TypeLabelProps) => { - const label = type.replace(/^\w/, (c) => c.toUpperCase()) + const label = capitalize(type) + return ( {isValidType(type) && ( diff --git a/src/lib/string.ts b/src/lib/string.ts index 2088c807..f222c20d 100644 --- a/src/lib/string.ts +++ b/src/lib/string.ts @@ -34,3 +34,7 @@ export function addDateToDateString(dateString: string, duration: Duration) { }) ) } + +export function capitalize(value: string) { + return value.replace(/^\w/, (c) => c.toUpperCase()) +}