@@ -26,30 +26,42 @@ export const Case = ({ children, variant }: Props) => {
26
26
27
27
const convertCase = ( text : string , variant : CaseVariant ) : string => {
28
28
switch ( variant ) {
29
- case "Uppercase" :
29
+ case "Uppercase" : {
30
30
return text . toUpperCase ( ) ;
31
- case "Lowercase" :
31
+ }
32
+ case "Lowercase" : {
32
33
return text . toLowerCase ( ) ;
33
- case "Title Case" :
34
+ }
35
+ case "Title Case" : {
34
36
return toTitleCase ( text ) ;
35
- case "APA Title Case" :
37
+ }
38
+ case "APA Title Case" : {
36
39
return toAPATitleCase ( text ) ;
37
- case "Sentence Case" :
40
+ }
41
+ case "Sentence Case" : {
38
42
return toSentenceCase ( text ) ;
39
- case "Snake Case" :
43
+ }
44
+ case "Snake Case" : {
40
45
return toSnakeCase ( text ) ;
41
- case "Kebab Case" :
46
+ }
47
+ case "Kebab Case" : {
42
48
return toKebabCase ( text ) ;
43
- case "Pascal Case" :
49
+ }
50
+ case "Pascal Case" : {
44
51
return toPascalCase ( text ) ;
45
- case "Camel Case" :
52
+ }
53
+ case "Camel Case" : {
46
54
return toCamelCase ( text ) ;
47
- case "Train Case" :
55
+ }
56
+ case "Train Case" : {
48
57
return toTrainCase ( text ) ;
49
- case "Macro Case" :
58
+ }
59
+ case "Macro Case" : {
50
60
return toMacroCase ( text ) ;
51
- default :
61
+ }
62
+ default : {
52
63
return text ;
64
+ }
53
65
}
54
66
} ;
55
67
@@ -64,7 +76,7 @@ const toTitleCase = (text: string): string => {
64
76
65
77
// Convert to APA Title Case (capitalize first letter of each word except articles, prepositions, and conjunctions)
66
78
const toAPATitleCase = ( text : string ) : string => {
67
- const minorWords = [
79
+ const minorWords = new Set ( [
68
80
"a" ,
69
81
"an" ,
70
82
"the" ,
@@ -80,7 +92,7 @@ const toAPATitleCase = (text: string): string => {
80
92
"by" ,
81
93
"in" ,
82
94
"of" ,
83
- ] ;
95
+ ] ) ;
84
96
85
97
const words = text . toLowerCase ( ) . split ( " " ) ;
86
98
@@ -93,7 +105,7 @@ const toAPATitleCase = (text: string): string => {
93
105
}
94
106
95
107
// Check if the word is a minor word
96
- if ( minorWords . includes ( word ) ) {
108
+ if ( minorWords . has ( word ) ) {
97
109
return word ;
98
110
}
99
111
@@ -112,27 +124,27 @@ const toSentenceCase = (text: string): string => {
112
124
// Convert to Snake Case (lowercase with underscores between words)
113
125
const toSnakeCase = ( text : string ) : string => {
114
126
return text
115
- . replace ( / ( [ A - Z ] ) / g, " $1" ) // Add space before capital letters
127
+ . replaceAll ( / ( [ A - Z ] ) / g, " $1" ) // Add space before capital letters
116
128
. trim ( )
117
129
. 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
120
132
} ;
121
133
122
134
// Convert to Kebab Case (lowercase with hyphens between words)
123
135
const toKebabCase = ( text : string ) : string => {
124
136
return text
125
- . replace ( / ( [ A - Z ] ) / g, " $1" ) // Add space before capital letters
137
+ . replaceAll ( / ( [ A - Z ] ) / g, " $1" ) // Add space before capital letters
126
138
. trim ( )
127
139
. 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
130
142
} ;
131
143
132
144
// Convert to Pascal Case (capitalize first letter of each word, no spaces)
133
145
const toPascalCase = ( text : string ) : string => {
134
146
return text
135
- . replace ( / [ ^ \w \s ] / g, "" ) // Remove special characters
147
+ . replaceAll ( / [ ^ \w \s ] / g, "" ) // Remove special characters
136
148
. split ( / \s + / )
137
149
. map ( ( word ) => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( ) )
138
150
. join ( "" ) ;
@@ -147,7 +159,7 @@ const toCamelCase = (text: string): string => {
147
159
// Convert to Train Case (capitalize first letter of each word, hyphens between words)
148
160
const toTrainCase = ( text : string ) : string => {
149
161
return text
150
- . replace ( / [ ^ \w \s ] / g, "" ) // Remove special characters
162
+ . replaceAll ( / [ ^ \w \s ] / g, "" ) // Remove special characters
151
163
. split ( / \s + / )
152
164
. map ( ( word ) => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( ) )
153
165
. join ( "-" ) ;
0 commit comments