Skip to content

FastAPI Integration #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions case-types-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,28 @@ export function capitalizeFirstForClassName(str: string) {
return parts.join("");
}

function toSnakeCase(key) {
return key.replace(/([A-Z])/g, "_$1").toLowerCase();
}

export function convertCamelToSnakeCase(obj) {
const newObj = {};
Object.keys(obj).forEach((key) => {
const newKey = toSnakeCase(key);
const value = obj[key];
if (value && typeof value === 'object' && !Array.isArray(value)) {
newObj[newKey] = convertCamelToSnakeCase(value);
} else {
newObj[newKey] = value;
}
});
return newObj;
}

export function camelCaseToDashCase(str: string) {
return str.replace(/[A-Z]/g, m => "-" + m.toLowerCase());
}

export function snakeCaseToCamelCase(str: string) {
return str.toLowerCase().replace(/([_][a-z])/g, group =>
group
Expand All @@ -35,7 +54,6 @@ export function snakeCaseToCamelCase(str: string) {
);
}


export function convertVarToCamel(obj: any) {
if (isDict(obj)) {
const n = {};
Expand All @@ -54,7 +72,6 @@ export function convertVarToCamel(obj: any) {
return obj;
}


export enum caseType {
LOWER,
UPPER,
Expand Down