File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,28 @@ export function capitalizeFirstForClassName(str: string) {
24
24
return parts . join ( "" ) ;
25
25
}
26
26
27
+ function toSnakeCase ( key ) {
28
+ return key . replace ( / ( [ A - Z ] ) / g, "_$1" ) . toLowerCase ( ) ;
29
+ }
30
+
31
+ export function convertCamelToSnakeCase ( obj ) {
32
+ const newObj = { } ;
33
+ Object . keys ( obj ) . forEach ( ( key ) => {
34
+ const newKey = toSnakeCase ( key ) ;
35
+ const value = obj [ key ] ;
36
+ if ( value && typeof value === 'object' && ! Array . isArray ( value ) ) {
37
+ newObj [ newKey ] = convertCamelToSnakeCase ( value ) ;
38
+ } else {
39
+ newObj [ newKey ] = value ;
40
+ }
41
+ } ) ;
42
+ return newObj ;
43
+ }
44
+
27
45
export function camelCaseToDashCase ( str : string ) {
28
46
return str . replace ( / [ A - Z ] / g, m => "-" + m . toLowerCase ( ) ) ;
29
47
}
48
+
30
49
export function snakeCaseToCamelCase ( str : string ) {
31
50
return str . toLowerCase ( ) . replace ( / ( [ _ ] [ a - z ] ) / g, group =>
32
51
group
@@ -35,7 +54,6 @@ export function snakeCaseToCamelCase(str: string) {
35
54
) ;
36
55
}
37
56
38
-
39
57
export function convertVarToCamel ( obj : any ) {
40
58
if ( isDict ( obj ) ) {
41
59
const n = { } ;
@@ -54,7 +72,6 @@ export function convertVarToCamel(obj: any) {
54
72
return obj ;
55
73
}
56
74
57
-
58
75
export enum caseType {
59
76
LOWER ,
60
77
UPPER ,
You can’t perform that action at this time.
0 commit comments