Update node-red-nodes sample, analysis, storage and time nodes to use strict and pass jshint scan

This commit is contained in:
Dave C-J 2014-06-28 23:37:19 +01:00
parent 43dfded402
commit ebf950d818
6 changed files with 279 additions and 268 deletions

View File

@ -19,10 +19,11 @@
// Sample Node-RED node file // Sample Node-RED node file
// Require main module // Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
"use strict";
// The main node definition - most things happen in here // The main node definition - most things happen in here
function SampleNode(n) { function SampleNode(n) {
// Create a RED node // Create a RED node
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
@ -45,8 +46,9 @@ function SampleNode(n) {
// Allows ports to be closed, connections dropped etc. // Allows ports to be closed, connections dropped etc.
// eg: this.client.disconnect(); // eg: this.client.disconnect();
}); });
} }
// Register the node by name. This must be called before overriding any of the // Register the node by name. This must be called before overriding any of the
// Node functions. // Node functions.
RED.nodes.registerType("sample",SampleNode); RED.nodes.registerType("sample",SampleNode);
}

View File

@ -14,12 +14,13 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var badwords = require('badwords'); "use strict";
if (badwords.length == 0 ) { return; } var badwords = require('badwords');
var badwordsRegExp = require('badwords/regexp'); if (badwords.length === 0 ) { return; }
var badwordsRegExp = require('badwords/regexp');
function BadwordsNode(n) { function BadwordsNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
@ -27,5 +28,6 @@ function BadwordsNode(n) {
if ( !badwordsRegExp.test(msg.payload) ) { node.send(msg); } if ( !badwordsRegExp.test(msg.payload) ) { node.send(msg); }
} }
}); });
}
RED.nodes.registerType("badwords",BadwordsNode);
} }
RED.nodes.registerType("badwords",BadwordsNode);

View File

@ -14,11 +14,12 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var WordPos = require('wordpos'); "use strict";
var wordpos = new WordPos(); var WordPos = require('wordpos');
var wordpos = new WordPos();
function WordPOSNode(n) { function WordPOSNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.on("input", function(msg) { this.on("input", function(msg) {
var node = this; var node = this;
@ -27,5 +28,6 @@ function WordPOSNode(n) {
node.send(msg); node.send(msg);
}); });
}); });
}
RED.nodes.registerType("wordpos",WordPOSNode);
} }
RED.nodes.registerType("wordpos",WordPOSNode);

View File

@ -14,25 +14,26 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var lvldb = require('level'); "use strict";
var lvldb = require('level');
function LevelNode(n) { function LevelNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.dbname = n.db; this.dbname = n.db;
var node = this; var node = this;
lvldb(this.dbname, function(err, db) { lvldb(this.dbname, function(err, db) {
if (err) node.error(err); if (err) { node.error(err); }
node.db = db; node.db = db;
}); });
this.on('close', function() { this.on('close', function() {
if (node.db) { node.db.close(); } if (node.db) { node.db.close(); }
}); });
} }
RED.nodes.registerType("leveldbase",LevelNode); RED.nodes.registerType("leveldbase",LevelNode);
function LevelDBNodeIn(n) { function LevelDBNodeIn(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.level = n.level; this.level = n.level;
this.levelConfig = RED.nodes.getNode(this.level); this.levelConfig = RED.nodes.getNode(this.level);
@ -52,18 +53,18 @@ function LevelDBNodeIn(n) {
}); });
} }
else { else {
if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined"); if (typeof msg.topic !== 'string') { node.error("msg.topic (the key is not defined"); }
} }
}); });
} }
else { else {
this.error("LevelDB database name not configured"); this.error("LevelDB database name not configured");
} }
} }
RED.nodes.registerType("leveldb in",LevelDBNodeIn); RED.nodes.registerType("leveldb in",LevelDBNodeIn);
function LevelDBNodeOut(n) { function LevelDBNodeOut(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.level = n.level; this.level = n.level;
this.operation = n.operation; this.operation = n.operation;
@ -78,17 +79,18 @@ function LevelDBNodeOut(n) {
} }
else { else {
node.levelConfig.db.put(msg.topic, msg.payload, function(err) { node.levelConfig.db.put(msg.topic, msg.payload, function(err) {
if (err) node.error(err); if (err) { node.error(err); }
}); });
} }
} }
else { else {
if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined"); if (typeof msg.topic !== 'string') { node.error("msg.topic (the key is not defined"); }
} }
}); });
} }
else { else {
this.error("LevelDB database name not configured"); this.error("LevelDB database name not configured");
} }
}
RED.nodes.registerType("leveldb out",LevelDBNodeOut);
} }
RED.nodes.registerType("leveldb out",LevelDBNodeOut);

View File

@ -14,26 +14,27 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var reconnect = RED.settings.mysqlReconnectTime || 30000; "use strict";
var mysqldb = require('mysql'); var reconnect = RED.settings.mysqlReconnectTime || 30000;
var querystring = require('querystring'); var mysqldb = require('mysql');
var querystring = require('querystring');
RED.httpAdmin.get('/MySQLdatabase/:id',function(req,res) { RED.httpAdmin.get('/MySQLdatabase/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { 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 { } else {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
}); });
RED.httpAdmin.delete('/MySQLdatabase/:id',function(req,res) { RED.httpAdmin.delete('/MySQLdatabase/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id); RED.nodes.deleteCredentials(req.params.id);
res.send(200); res.send(200);
}); });
RED.httpAdmin.post('/MySQLdatabase/:id',function(req,res) { RED.httpAdmin.post('/MySQLdatabase/:id',function(req,res) {
var body = ""; var body = "";
req.on('data', function(chunk) { req.on('data', function(chunk) {
body+=chunk; body+=chunk;
@ -41,12 +42,12 @@ RED.httpAdmin.post('/MySQLdatabase/:id',function(req,res) {
req.on('end', function(){ req.on('end', function(){
var newCreds = querystring.parse(body); var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{}; var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.user == null || newCreds.user == "") { if (newCreds.user == null || newCreds.user === "") {
delete credentials.user; delete credentials.user;
} else { } else {
credentials.user = newCreds.user; credentials.user = newCreds.user;
} }
if (newCreds.password == "") { if (newCreds.password === "") {
delete credentials.password; delete credentials.password;
} else { } else {
credentials.password = newCreds.password||credentials.password; credentials.password = newCreds.password||credentials.password;
@ -54,10 +55,10 @@ RED.httpAdmin.post('/MySQLdatabase/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials); RED.nodes.addCredentials(req.params.id,credentials);
res.send(200); res.send(200);
}); });
}); });
function MySQLNode(n) { function MySQLNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.host = n.host; this.host = n.host;
this.port = n.port; this.port = n.port;
@ -65,15 +66,15 @@ function MySQLNode(n) {
this.connected = false; this.connected = false;
this.connecting = false; this.connecting = false;
if (n.user) {
var credentials = {}; var credentials = {};
if (n.user) {
credentials.user = n.user; credentials.user = n.user;
credentials.password = n.pass; credentials.password = n.pass;
RED.nodes.addCredentials(n.id,credentials); RED.nodes.addCredentials(n.id,credentials);
this.user = n.user; this.user = n.user;
this.password = n.pass; this.password = n.pass;
} else { } else {
var credentials = RED.nodes.getCredentials(n.id); credentials = RED.nodes.getCredentials(n.id);
if (credentials) { if (credentials) {
this.user = credentials.user; this.user = credentials.user;
this.password = credentials.password; this.password = credentials.password;
@ -125,15 +126,15 @@ function MySQLNode(n) {
if (this.tick) { clearTimeout(this.tick); } if (this.tick) { clearTimeout(this.tick); }
if (this.connection) { if (this.connection) {
node.connection.end(function(err) { node.connection.end(function(err) {
if (err) node.error(err); if (err) { node.error(err); }
}); });
} }
}); });
} }
RED.nodes.registerType("MySQLdatabase",MySQLNode); RED.nodes.registerType("MySQLdatabase",MySQLNode);
function MysqlDBNodeIn(n) { function MysqlDBNodeIn(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.mydb = n.mydb; this.mydb = n.mydb;
this.mydbConfig = RED.nodes.getNode(this.mydb); this.mydbConfig = RED.nodes.getNode(this.mydb);
@ -153,18 +154,18 @@ function MysqlDBNodeIn(n) {
}); });
} }
else { else {
if (typeof msg.topic !== 'string') node.error("msg.topic : the query is not defined as a string"); if (typeof msg.topic !== 'string') { node.error("msg.topic : the query is not defined as a string"); }
} }
}); });
} }
else { else {
this.error("MySQL database not configured"); this.error("MySQL database not configured");
} }
} }
RED.nodes.registerType("mysql",MysqlDBNodeIn); RED.nodes.registerType("mysql",MysqlDBNodeIn);
//function MysqlDBNodeOut(n) { //function MysqlDBNodeOut(n) {
//RED.nodes.createNode(this,n); //RED.nodes.createNode(this,n);
//this.level = n.level; //this.level = n.level;
//this.operation = n.operation; //this.operation = n.operation;
@ -191,5 +192,6 @@ RED.nodes.registerType("mysql",MysqlDBNodeIn);
//else { //else {
//this.error("MySQL database not configured"); //this.error("MySQL database not configured");
//} //}
//} //}
//RED.nodes.registerType("mysql out",MysqlDBNodeOut); //RED.nodes.registerType("mysql out",MysqlDBNodeOut);
}

View File

@ -15,6 +15,7 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var SunCalc = require('suncalc'); var SunCalc = require('suncalc');
function SunNode(n) { function SunNode(n) {