@@ -26,30 +26,42 @@ export const Case = ({ children, variant }: Props) => {
2626
2727const convertCase = ( text : string , variant : CaseVariant ) : string => {
2828 switch ( variant ) {
29- case "Uppercase" :
29+ case "Uppercase" : {
3030 return text . toUpperCase ( ) ;
31- case "Lowercase" :
31+ }
32+ case "Lowercase" : {
3233 return text . toLowerCase ( ) ;
33- case "Title Case" :
34+ }
35+ case "Title Case" : {
3436 return toTitleCase ( text ) ;
35- case "APA Title Case" :
37+ }
38+ case "APA Title Case" : {
3639 return toAPATitleCase ( text ) ;
37- case "Sentence Case" :
40+ }
41+ case "Sentence Case" : {
3842 return toSentenceCase ( text ) ;
39- case "Snake Case" :
43+ }
44+ case "Snake Case" : {
4045 return toSnakeCase ( text ) ;
41- case "Kebab Case" :
46+ }
47+ case "Kebab Case" : {
4248 return toKebabCase ( text ) ;
43- case "Pascal Case" :
49+ }
50+ case "Pascal Case" : {
4451 return toPascalCase ( text ) ;
45- case "Camel Case" :
52+ }
53+ case "Camel Case" : {
4654 return toCamelCase ( text ) ;
47- case "Train Case" :
55+ }
56+ case "Train Case" : {
4857 return toTrainCase ( text ) ;
49- case "Macro Case" :
58+ }
59+ case "Macro Case" : {
5060 return toMacroCase ( text ) ;
51- default :
61+ }
62+ default : {
5263 return text ;
64+ }
5365 }
5466} ;
5567
@@ -64,7 +76,7 @@ const toTitleCase = (text: string): string => {
6476
6577// Convert to APA Title Case (capitalize first letter of each word except articles, prepositions, and conjunctions)
6678const toAPATitleCase = ( text : string ) : string => {
67- const minorWords = [
79+ const minorWords = new Set ( [
6880 "a" ,
6981 "an" ,
7082 "the" ,
@@ -80,7 +92,7 @@ const toAPATitleCase = (text: string): string => {
8092 "by" ,
8193 "in" ,
8294 "of" ,
83- ] ;
95+ ] ) ;
8496
8597 const words = text . toLowerCase ( ) . split ( " " ) ;
8698
@@ -93,7 +105,7 @@ const toAPATitleCase = (text: string): string => {
93105 }
94106
95107 // Check if the word is a minor word
96- if ( minorWords . includes ( word ) ) {
108+ if ( minorWords . has ( word ) ) {
97109 return word ;
98110 }
99111
@@ -112,27 +124,27 @@ const toSentenceCase = (text: string): string => {
112124// Convert to Snake Case (lowercase with underscores between words)
113125const toSnakeCase = ( text : string ) : string => {
114126 return text
115- . replace ( / ( [ A - Z ] ) / g, " $1" ) // Add space before capital letters
127+ . replaceAll ( / ( [ A - Z ] ) / g, " $1" ) // Add space before capital letters
116128 . trim ( )
117129 . toLowerCase ( )
118- . replace ( / [ ^ \w \s ] / g, "" ) // Remove special characters
119- . replace ( / \s + / g, "_" ) ; // Replace spaces with underscores
130+ . replaceAll ( / [ ^ \w \s ] / g, "" ) // Remove special characters
131+ . replaceAll ( / \s + / g, "_" ) ; // Replace spaces with underscores
120132} ;
121133
122134// Convert to Kebab Case (lowercase with hyphens between words)
123135const toKebabCase = ( text : string ) : string => {
124136 return text
125- . replace ( / ( [ A - Z ] ) / g, " $1" ) // Add space before capital letters
137+ . replaceAll ( / ( [ A - Z ] ) / g, " $1" ) // Add space before capital letters
126138 . trim ( )
127139 . toLowerCase ( )
128- . replace ( / [ ^ \w \s ] / g, "" ) // Remove special characters
129- . replace ( / \s + / g, "-" ) ; // Replace spaces with hyphens
140+ . replaceAll ( / [ ^ \w \s ] / g, "" ) // Remove special characters
141+ . replaceAll ( / \s + / g, "-" ) ; // Replace spaces with hyphens
130142} ;
131143
132144// Convert to Pascal Case (capitalize first letter of each word, no spaces)
133145const toPascalCase = ( text : string ) : string => {
134146 return text
135- . replace ( / [ ^ \w \s ] / g, "" ) // Remove special characters
147+ . replaceAll ( / [ ^ \w \s ] / g, "" ) // Remove special characters
136148 . split ( / \s + / )
137149 . map ( ( word ) => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( ) )
138150 . join ( "" ) ;
@@ -147,7 +159,7 @@ const toCamelCase = (text: string): string => {
147159// Convert to Train Case (capitalize first letter of each word, hyphens between words)
148160const toTrainCase = ( text : string ) : string => {
149161 return text
150- . replace ( / [ ^ \w \s ] / g, "" ) // Remove special characters
162+ . replaceAll ( / [ ^ \w \s ] / g, "" ) // Remove special characters
151163 . split ( / \s + / )
152164 . map ( ( word ) => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( ) )
153165 . join ( "-" ) ;
0 commit comments