@mazix/n8n-nodes-converter-documents
Version:
n8n node to convert various document formats (DOCX, DOC, XML, YML, XLSX, CSV, PDF, TXT, PPT, PPTX, HTML, JSON, ODT, ODP, ODS) to JSON or text format
29 lines • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.flattenJsonObject = flattenJsonObject;
/**
* Функция для нормализации JSON объектов
* Преобразует многоуровневые структуры в плоский объект
*/
function flattenJsonObject(obj, prefix = '', result = {}) {
if (obj === null || obj === undefined) {
return result;
}
if (typeof obj !== 'object' || obj instanceof Date || Buffer.isBuffer(obj)) {
result[prefix || 'value'] = obj;
return result;
}
if (Array.isArray(obj)) {
obj.forEach((item, index) => {
const key = prefix ? `${prefix}[${index}]` : `item_${index}`;
flattenJsonObject(item, key, result);
});
return result;
}
Object.keys(obj).forEach(key => {
const newKey = prefix ? `${prefix}.${key}` : key;
flattenJsonObject(obj[key], newKey, result);
});
return result;
}
//# sourceMappingURL=flatten.js.map