1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Better template handling in CSV node - (can cope with quoted column names etc)

This commit is contained in:
Dave C-J 2014-08-30 13:22:22 +01:00
parent 64c95f1d1b
commit c3926f6513

View File

@ -23,6 +23,15 @@ module.exports = function(RED) {
this.sep = this.sep.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t"); this.sep = this.sep.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t");
this.quo = '"'; this.quo = '"';
var node = this; var node = this;
for (var t = 0; t < node.template.length; t++) {
node.template[t] = node.template[t].trim(); // remove leading and trailing whitespace
if (node.template[t].charAt(0) === '"' && node.template[t].charAt(node.template[t].length -1) === '"') {
// remove leading and trialing quotes (if they exist) - and remove whitepace again.
node.template[t] = node.template[t].substr(1,node.template[t].length -2).trim();
}
}
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg.hasOwnProperty("payload")) { if (msg.hasOwnProperty("payload")) {
if (typeof msg.payload == "object") { // convert to csv if (typeof msg.payload == "object") { // convert to csv