mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-08 15:49:07 +00:00
maestro connection with microservices - clients and modules
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
export const objectCamelToSnake = (object) => {
|
||||
const objectKeys = Object.keys(object);
|
||||
const objectValues = Object.values(object);
|
||||
|
||||
const newKeys = objectKeys.map((key) => {
|
||||
return key
|
||||
.split(/(?=[A-Z])/)
|
||||
.join("_")
|
||||
.toLowerCase();
|
||||
});
|
||||
|
||||
objectKeys.forEach((key, index) => {
|
||||
object[newKeys[index]] = object[key];
|
||||
if (newKeys[index] !== objectKeys[index]) {
|
||||
delete object[key];
|
||||
}
|
||||
});
|
||||
|
||||
objectValues.forEach((value) => {
|
||||
if (typeof value === "object") {
|
||||
objectCamelToSnake(value);
|
||||
}
|
||||
});
|
||||
|
||||
return object;
|
||||
};
|
||||
|
||||
export const objectSnakeToCamel = (object) => {
|
||||
const objectKeys = Object.keys(object);
|
||||
const objectValues = Object.values(object);
|
||||
|
||||
const newKeys = objectKeys.map((key) => {
|
||||
return key.replace(/([-_][a-z])/gi, ($1) => {
|
||||
return $1.toUpperCase().replace("-", "").replace("_", "");
|
||||
});
|
||||
});
|
||||
|
||||
objectKeys.forEach((key, index) => {
|
||||
object[newKeys[index]] = object[key];
|
||||
if (newKeys[index] !== objectKeys[index]) {
|
||||
delete object[key];
|
||||
}
|
||||
});
|
||||
|
||||
objectValues.forEach((value) => {
|
||||
if (typeof value === "object") {
|
||||
objectSnakeToCamel(value);
|
||||
}
|
||||
});
|
||||
|
||||
return object;
|
||||
};
|
||||
|
||||
export const trSnakeToCamel = (object) =>{
|
||||
|
||||
const convertedParams = object.params.map((param)=>{
|
||||
return objectSnakeToCamel(param)
|
||||
})
|
||||
|
||||
object.params = convertedParams
|
||||
|
||||
return objectSnakeToCamel(object)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user