feat(FE): axios converter
This commit is contained in:
parent
f7a5ce1c2d
commit
47df64bd96
1 changed files with 27 additions and 1 deletions
|
@ -2,4 +2,30 @@ export function cleanOptions(options: Object): Object {
|
|||
return Object.fromEntries(
|
||||
Object.entries(options).filter(([_, value]) => value !== undefined && value !== null)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function camelToSnake(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(camelToSnake);
|
||||
} else if (obj !== null && typeof obj === 'object') {
|
||||
return Object.keys(obj).reduce((acc, key) => {
|
||||
const snakeKey = key.replace(/([A-Z])/g, '_$1').toLowerCase();
|
||||
acc[snakeKey] = camelToSnake(obj[key]);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
export function snakeToCamel(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(snakeToCamel);
|
||||
} else if (obj !== null && typeof obj === 'object') {
|
||||
return Object.keys(obj).reduce((acc, key) => {
|
||||
const camelKey = key.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
||||
acc[camelKey] = snakeToCamel(obj[key]);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue