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

Update node-red-nodes io nodes to use strict and pass jshint scan

This commit is contained in:
Dave C-J 2014-06-28 23:35:33 +01:00
parent 9e0585a721
commit 052a7d587d
4 changed files with 182 additions and 174 deletions

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var spawn = require('child_process').spawn;
var plat = require('os').platform();
@ -26,16 +27,16 @@ function PingNode(n) {
node.tout = setInterval(function() {
var ex;
if (plat == "linux") ex = spawn('ping', ['-n', '-w', '5', '-c', '1', node.host]);
else if (plat.match(/^win/)) ex = spawn('ping', ['-n', '1', '-w', '5000', node.host]);
else if (plat == "darwin") ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]);
else node.error("Sorry - your platform - "+plat+" - is not recognised.");
if (plat == "linux") { ex = spawn('ping', ['-n', '-w', '5', '-c', '1', node.host]); }
else if (plat.match(/^win/)) { ex = spawn('ping', ['-n', '1', '-w', '5000', node.host]); }
else if (plat == "darwin") { ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]); }
else { node.error("Sorry - your platform - "+plat+" - is not recognised."); }
var res = false;
ex.stdout.on('data', function (data) {
//console.log('[ping] stdout: ' + data.toString());
var regex = /from.*time.(.*)ms/;
var m = regex.exec(data.toString())||"";
if (m != '') { res = Number(m[1]); }
if (m !== '') { res = Number(m[1]); }
});
ex.stderr.on('data', function (data) {
//console.log('[ping] stderr: ' + data);
@ -43,7 +44,7 @@ function PingNode(n) {
ex.on('close', function (code) {
//console.log('[ping] result: ' + code);
var msg = { payload:false, topic:node.host };
if (code == 0) msg = { payload:res, topic:node.host };
if (code === 0) { msg = { payload:res, topic:node.host }; }
node.send(msg);
});
}, node.timer);
@ -53,3 +54,4 @@ function PingNode(n) {
});
}
RED.nodes.registerType("ping",PingNode);
}

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var settings = RED.settings;
var util = require("util");
var fs = require('fs');
@ -32,8 +33,8 @@ function RawSerialInNode(n) {
this.splitc = n.splitc||null;
this.out = n.out||"char";
this.bin = n.bin||false;
if (this.splitc == '\\n') this.splitc = "\n";
if (this.splitc == '\\r') this.splitc = "\r";
if (this.splitc == '\\n') { this.splitc = "\n"; }
if (this.splitc == '\\r') { this.splitc = "\r"; }
if (!isNaN(parseInt(this.splitc))) { this.splitc = parseInt(this.splitc); }
var node = this;
@ -46,7 +47,7 @@ function RawSerialInNode(n) {
var i = 0;
node.inp.on('data', function (data) {
for (var z = 0; z < data.length; z++) {
if ((node.out === "time") && (node.splitc != 0)) {
if ((node.out === "time") && (node.splitc !== 0)) {
if (node.tout) {
i += 1;
buf[i] = data[z];
@ -58,6 +59,7 @@ function RawSerialInNode(n) {
buf.copy(m,0,0,i+1);
if (node.bin !== "true") { m = m.toString(); }
node.send({"payload": m});
m = null;
}, node.splitc);
i = 0;
buf[0] = data[z];
@ -71,6 +73,7 @@ function RawSerialInNode(n) {
buf.copy(m,0,0,i);
if (node.bin !== "true") { m = m.toString(); }
node.send({"payload":m});
m = null;
i = 0;
}
}
@ -112,7 +115,7 @@ function RawSerialOutNode(n) {
var node = this;
var setupSerial = function() {
node.oup = fs.createWriteStream(pre+node.port,{ flags:'w', encoding:'utf8', mode:0666 });
node.oup = fs.createWriteStream(pre+node.port,{ flags:'w', encoding:'utf8', mode:'0666' });
node.on("input", function(msg) {
if (msg.payload != null) {
node.oup.write(msg.payload);
@ -142,3 +145,4 @@ function RawSerialOutNode(n) {
});
}
RED.nodes.registerType("rawserial out",RawSerialOutNode);
}

View File

@ -35,7 +35,7 @@ module.exports = function(RED) {
RED.httpAdmin.get('/stomp-server/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!=="")}));
} else {
res.send(JSON.stringify({}));
}
@ -54,12 +54,12 @@ module.exports = function(RED) {
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.user == null || newCreds.user == "") {
if (newCreds.user == null || newCreds.user === "") {
delete credentials.user;
} else {
credentials.user = newCreds.user;
}
if (newCreds.password == "") {
if (newCreds.password === "") {
delete credentials.password;
} else {
credentials.password = newCreds.password||credentials.password;

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var wol = require('wake_on_lan');
var chk = /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/;
@ -39,3 +40,4 @@ function WOLnode(n) {
});
}
RED.nodes.registerType("wake on lan",WOLnode);
}