massage data
This commit is contained in:
parent
616fa1be79
commit
60d3f35988
7 changed files with 174 additions and 48 deletions
|
|
@ -1698,7 +1698,15 @@ class DataUtils {
|
|||
static toSnakeCaseObject(obj) {
|
||||
const newObj = Object.entries(obj).reduce((acc, [key, value]) => {
|
||||
const snakeKey = key.replace(/[A-Z]/g, (match) => "_" + match.toLowerCase());
|
||||
value = Object.prototype.toString.call(value) === "[object Object]" ? this.toSnakeCaseObject(value) : value;
|
||||
if (Array.isArray(value)) {
|
||||
value = value.map((item) => {
|
||||
return Object.prototype.toString.call(item) === "[object Object]"
|
||||
? this.toSnakeCaseObject(item)
|
||||
: item;
|
||||
});
|
||||
} else if (Object.prototype.toString.call(value) === "[object Object]") {
|
||||
value = this.toSnakeCaseObject(value);
|
||||
}
|
||||
acc[snakeKey] = value;
|
||||
return acc;
|
||||
}, {});
|
||||
|
|
@ -1709,7 +1717,16 @@ class DataUtils {
|
|||
static toCamelCaseObject(obj) {
|
||||
const newObj = Object.entries(obj).reduce((acc, [key, value]) => {
|
||||
const camelKey = key.replace(/_([a-z])/g, (match, p1) => p1.toUpperCase());
|
||||
value = Object.prototype.toString.call(value) === "[object Object]" ? this.toCamelCaseObject(value) : value;
|
||||
// check if value is an array
|
||||
if (Array.isArray(value)) {
|
||||
value = value.map((item) => {
|
||||
return Object.prototype.toString.call(item) === "[object Object]"
|
||||
? this.toCamelCaseObject(item)
|
||||
: item;
|
||||
});
|
||||
} else if (Object.prototype.toString.call(value) === "[object Object]") {
|
||||
value = this.toCamelCaseObject(value);
|
||||
}
|
||||
acc[camelKey] = value;
|
||||
return acc;
|
||||
}, {});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue