File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ export function kebabToCamelCase(str: string): string {
48
48
* @returns The snake_case string.
49
49
*/
50
50
export function camelToSnakeCase ( str : string ) : string {
51
- return str . replace ( / [ A - Z ] / g, ( match ) => `_${ match . toLowerCase ( ) } ` ) ;
51
+ return str . replace ( / [ A - Z 0 - 9 ] / g, ( match ) => `_${ match . toLowerCase ( ) } ` ) ;
52
52
}
53
53
54
54
/**
@@ -58,5 +58,5 @@ export function camelToSnakeCase(str: string): string {
58
58
* @returns The kebab-case string.
59
59
*/
60
60
export function camelToKebabCase ( str : string ) : string {
61
- return str . replace ( / [ A - Z ] / g, ( match ) => `-${ match . toLowerCase ( ) } ` ) ;
61
+ return str . replace ( / [ A - Z 0 - 9 ] / g, ( match ) => `-${ match . toLowerCase ( ) } ` ) ;
62
62
}
Original file line number Diff line number Diff line change @@ -60,6 +60,13 @@ describe("string", () => {
60
60
"camel_c_a_s_e_s_t_r_i_n_g" ,
61
61
) ;
62
62
} ) ;
63
+ assert . equal ( camelToSnakeCase ( "camelcasestring1" ) , "camelcasestring_1" ) ;
64
+ assert . equal (
65
+ camelToSnakeCase ( "camel1Case2String" ) ,
66
+ "camel_1_case_2_string" ,
67
+ ) ;
68
+ assert . equal ( camelToSnakeCase ( "camelC1A2S3E4" ) , "camel_c_1_a_2_s_3_e_4" ) ;
69
+ assert . equal ( camelToSnakeCase ( "camel123" ) , "camel_1_2_3" ) ;
63
70
} ) ;
64
71
65
72
describe ( "camelToKebabCase" , ( ) => {
@@ -70,6 +77,13 @@ describe("string", () => {
70
77
camelToKebabCase ( "camelCASESTRING" ) ,
71
78
"camel-c-a-s-e-s-t-r-i-n-g" ,
72
79
) ;
80
+ assert . equal ( camelToKebabCase ( "camelcasestring1" ) , "camelcasestring-1" ) ;
81
+ assert . equal (
82
+ camelToKebabCase ( "camel1Case2String" ) ,
83
+ "camel-1-case-2-string" ,
84
+ ) ;
85
+ assert . equal ( camelToKebabCase ( "camelC1A2S3E4" ) , "camel-c-1-a-2-s-3-e-4" ) ;
86
+ assert . equal ( camelToKebabCase ( "camel123" ) , "camel-1-2-3" ) ;
73
87
} ) ;
74
88
} ) ;
75
89
} ) ;
You can’t perform that action at this time.
0 commit comments