.csv, .xml, .json, вероятно, подходит для использования Nod Node. Это, тогда мне нужно, чтобы он использовал JavaScript для преобразования.
Код: Выделить всё
const tsvToCsv = (tsvString) => {
if (!tsvString || typeof tsvString !== 'string') {
return '';
}
const lines = tsvString.split('\n');
const csvLines = lines.map(line => {
const values = line.split('\t');
const csvValues = values.map(value => {
// Handle values with special characters that need to be quoted
if (value.includes(',') || value.includes('"') || value.includes('\n')) {
const escapedValue = value.replace(/"/g, '""');
return `"${escapedValue}"`;
}
return value;
});
return csvValues.join(',');
});
return csvLines.join('\n');
};
// Access the data directly from the first item of the previous node.
// This is where the file content is stored.
const tsvData = items[0].data;
// Convert the TSV data to CSV
const csvData = tsvToCsv(tsvData);
// Set the output for the next node in the workflow
return [{
json: {
csvData: csvData
}
}];
Подробнее здесь: https://stackoverflow.com/questions/797 ... son-or-xml
Мобильная версия