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

tweak CSV parser to better handle GSM style phone numbers.

This commit is contained in:
Dave C-J 2014-11-08 15:31:36 +00:00
parent 28da2dc38a
commit 8b7e367416

View File

@ -106,7 +106,7 @@ module.exports = function(RED) {
else if ((msg.payload[i] === node.sep) && f) { // if we are outside of quote (ie valid separator
if (!node.goodtmpl) { node.template[j] = "col"+(j+1); }
if ( node.template[j] && (node.template[j] !== "") && (k[j] !== "" ) ) {
if (!isNaN(Number(k[j]))) { k[j] = Number(k[j]); }
if ( (k[j].charAt(0) !== "+") && !isNaN(Number(k[j])) ) { k[j] = Number(k[j]); }
o[node.template[j]] = k[j];
}
j += 1;
@ -115,7 +115,7 @@ module.exports = function(RED) {
else if (f && ((msg.payload[i] === "\n") || (msg.payload[i] === "\r"))) { // handle multiple lines
//console.log(j,k,o,k[j]);
if ( node.template[j] && (node.template[j] !== "") && (k[j] !== "") ) {
if (!isNaN(Number(k[j]))) { k[j] = Number(k[j]); }
if ( (k[j].charAt(0) !== "+") && !isNaN(Number(k[j])) ) { k[j] = Number(k[j]); }
else { k[j].replace(/\r$/,''); }
o[node.template[j]] = k[j];
}
@ -136,7 +136,7 @@ module.exports = function(RED) {
//console.log(j,k,o,k[j]);
if (!node.goodtmpl) { node.template[j] = "col"+(j+1); }
if ( node.template[j] && (node.template[j] !== "") && (k[j] !== "") ) {
if (!isNaN(Number(k[j]))) { k[j] = Number(k[j]); }
if ( (k[j].charAt(0) !== "+") && !isNaN(Number(k[j])) ) { k[j] = Number(k[j]); }
else { k[j].replace(/\r$/,''); }
o[node.template[j]] = k[j];
}