7983-testToMaster_2438 #2977

Merged
alexm merged 212 commits from 7983-testToMaster_2438 into master 2024-09-17 05:36:47 +00:00
2 changed files with 15 additions and 24 deletions
Showing only changes of commit 2aeff19578 - Show all commits

View File

@ -1,7 +1,22 @@
/**
* Flattens an array of objects by converting each object into a flat structure.
*
* @param {Array} dataArray Array of objects to be flattened
* @return {Array} Array of flattened objects
*/
function flatten(dataArray) { function flatten(dataArray) {
return dataArray.map(item => flattenObj(item.__data)); return dataArray.map(item => flattenObj(item.__data));
} }
/**
* Recursively flattens an object, converting nested properties into a single level object
* with keys representing the original nested structure.
*
* @param {Object} data The object to be flattened
* @param {String} [prefix=''] Optional prefix for nested keys
* @return {Object} Flattened object
*/
function flattenObj(data, prefix = '') { function flattenObj(data, prefix = '') {
let result = {}; let result = {};
try { try {

View File

@ -40,27 +40,3 @@ module.exports = Self => {
return [toCSV(dataFlatted), 'text/csv', `inline; filename="buys-${id}.csv"`]; return [toCSV(dataFlatted), 'text/csv', `inline; filename="buys-${id}.csv"`];
}; };
}; };
// function flattenJSON(dataArray) {
// return dataArray.map(item => flatten(item.__data));
// }
// function flatten(data, prefix = '') {
// let result = {};
// try {
// for (let key in data) {
// if (!data[key]) continue;
// const newKey = prefix ? `${prefix}_${key}` : key;
// const value = data[key];
// if (typeof value === 'object' && value !== null && !Array.isArray(value))
// Object.assign(result, flatten(value.__data, newKey));
// else
// result[newKey] = value;
// }
// } catch (error) {
// console.error(error);
// }
// return result;
// }