@@ -14,7 +14,7 @@ export enum Case {
14
14
15
15
export const pascalCase = flow ( camelCase , upperFirst ) ;
16
16
17
- const isMultipleWords = ( str : string ) => Boolean ( str . match ( / [ \s _ - ] | [ a - z ] [ A - Z 0 - 9 ] / g) ) ;
17
+ const isMultipleWords = ( str : string ) => Boolean ( str . match ( / [ \s _ ] | [ a - z ] [ A - Z 0 - 9 ] / g) ) ;
18
18
19
19
const camelCaseForMultipleWords = ( str : string ) => ( isMultipleWords ( str ) ? camelCase ( str ) : str ) ;
20
20
const snakeCaseForMultipleWords = ( str : string ) => ( isMultipleWords ( str ) ? snakeCase ( str ) : str ) ;
@@ -25,6 +25,12 @@ const transforms = {
25
25
[ Case . PASCAL ] : pascalCase ,
26
26
} ;
27
27
28
+ const startsWithDigit = ( inputString : string ) : boolean => {
29
+ // Regular expression to check if the string starts with a digit
30
+ const regex = / ^ \d / ;
31
+ return regex . test ( inputString ) ;
32
+ } ;
33
+
28
34
// A recursive function that looks at the models and their properties and
29
35
// converts each property name using the provided transform function.
30
36
export const convertModelNames = < T extends Model | OperationResponse > ( model : T , type : Exclude < Case , Case . NONE > ) : T => {
@@ -40,9 +46,10 @@ export const convertModelNames = <T extends Model | OperationResponse>(model: T,
40
46
} ;
41
47
42
48
const convertEnumName = ( modelEnum : Enum , type : Exclude < Case , Case . NONE > ) : Enum => {
49
+ const transformedName = transforms [ type ] ( modelEnum . name ) ;
43
50
return {
44
51
...modelEnum ,
45
- name : transforms [ type ] ( modelEnum . name ) ,
52
+ name : startsWithDigit ( transformedName ) ? `_ ${ transformedName } ` : transformedName ,
46
53
} ;
47
54
} ;
48
55
0 commit comments