Skip to content

Commit 952cd00

Browse files
committed
Adds object conversion method
1 parent c5c26b3 commit 952cd00

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

case-types-parser.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isDict } from "./general";
2+
13
export function capitalizeFirstPerWord(str: string) {
24
str = str.replace(/_/g, ' ');
35
const parts = str.split(" ");
@@ -33,6 +35,26 @@ export function snakeCaseToCamelCase(str: string) {
3335
);
3436
}
3537

38+
39+
export function convertVarToCamel(obj: any) {
40+
if (isDict(obj)) {
41+
const n = {};
42+
Object.keys(obj)
43+
.forEach((k) => {
44+
n[snakeCaseToCamelCase(k)] = convertVarToCamel(obj[k]);
45+
});
46+
47+
return n;
48+
} else if (Array.isArray(obj)) {
49+
return obj.map((i) => {
50+
return convertVarToCamel(i);
51+
});
52+
}
53+
54+
return obj;
55+
}
56+
57+
3658
export enum caseType {
3759
LOWER,
3860
UPPER,

general.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,9 @@ export function percentRoundString(value: number | string, decimals: number = 0,
205205
}
206206
else if (typeof value == 'undefined' || value == null) return "n/a";
207207
return value;
208+
}
209+
210+
211+
export function isDict(o: any): boolean {
212+
return o === Object(o) && !Array.isArray(o) && typeof o !== 'function';
208213
}

0 commit comments

Comments
 (0)