mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Misc tidy ups of jsHint "issues" for some node-red-nodes
This commit is contained in:
		| @@ -14,46 +14,48 @@ | ||||
|  * limitations under the License. | ||||
|  **/ | ||||
|  | ||||
| var RED = require(process.env.NODE_RED_HOME + "/red/red"); | ||||
| module.exports = function(RED) { | ||||
|     "use strict"; | ||||
|  | ||||
| function SmoothNode(n) { | ||||
|     RED.nodes.createNode(this, n); | ||||
|     this.action = n.action; | ||||
|     this.round = n.round || false; | ||||
|     this.count = Number(n.count); | ||||
|     var node = this; | ||||
|     var a = []; | ||||
|     var tot = 0; | ||||
|     var pop = 0; | ||||
|     var old = null; | ||||
|     function SmoothNode(n) { | ||||
|         RED.nodes.createNode(this, n); | ||||
|         this.action = n.action; | ||||
|         this.round = n.round || false; | ||||
|         this.count = Number(n.count); | ||||
|         var node = this; | ||||
|         var a = []; | ||||
|         var tot = 0; | ||||
|         var pop = 0; | ||||
|         var old = null; | ||||
|  | ||||
|     this.on('input', function (msg) { | ||||
|         var n = Number(msg.payload); | ||||
|         if (!isNaN(n)) { | ||||
|             if ((node.action === "low") || (node.action === "high")) { | ||||
|                 if (old == null) { old = n; } | ||||
|                 old = old + (n - old) / node.count; | ||||
|                 if (node.action === "low") { msg.payload = old; } | ||||
|                 else { msg.payload = n - old; } | ||||
|         this.on('input', function (msg) { | ||||
|             var n = Number(msg.payload); | ||||
|             if (!isNaN(n)) { | ||||
|                 if ((node.action === "low") || (node.action === "high")) { | ||||
|                     if (old == null) { old = n; } | ||||
|                     old = old + (n - old) / node.count; | ||||
|                     if (node.action === "low") { msg.payload = old; } | ||||
|                     else { msg.payload = n - old; } | ||||
|                 } | ||||
|                 else { | ||||
|                     a.push(n); | ||||
|                     if (a.length > node.count) { pop = a.shift(); } | ||||
|                     if (node.action === "max") { | ||||
|                         msg.payload = Math.max.apply(Math, a); | ||||
|                     } | ||||
|                     if (node.action === "min") { | ||||
|                         msg.payload = Math.min.apply(Math, a); | ||||
|                     } | ||||
|                     if (node.action === "mean") { | ||||
|                         tot = tot + n - pop; | ||||
|                         msg.payload = tot / a.length; | ||||
|                     } | ||||
|                 } | ||||
|                 if (node.round) { msg.payload = Math.round(msg.payload); } | ||||
|                 node.send(msg); | ||||
|             } | ||||
|             else { | ||||
|                 a.push(n); | ||||
|                 if (a.length > node.count) { pop = a.shift(); } | ||||
|                 if (node.action === "max") { | ||||
|                     msg.payload = Math.max.apply(Math, a); | ||||
|                 } | ||||
|                 if (node.action === "min") { | ||||
|                     msg.payload = Math.min.apply(Math, a); | ||||
|                 } | ||||
|                 if (node.action === "mean") { | ||||
|                     tot = tot + n - pop; | ||||
|                     msg.payload = tot / a.length; | ||||
|                 } | ||||
|             } | ||||
|             if (node.round) { msg.payload = Math.round(msg.payload); } | ||||
|             node.send(msg); | ||||
|         } | ||||
|         else { node.log("Not a number: "+msg.payload); } | ||||
|     }); | ||||
|             else { node.log("Not a number: "+msg.payload); } | ||||
|         }); | ||||
|     } | ||||
|     RED.nodes.registerType("smooth", SmoothNode); | ||||
| } | ||||
| RED.nodes.registerType("smooth", SmoothNode); | ||||
|   | ||||
| @@ -41,9 +41,6 @@ module.exports = function(RED) { | ||||
|     // GPIO pins 11 (R), 13 (G), 15 (B). | ||||
|  | ||||
|     function LedBorgNode(n) { | ||||
|         RED.nodes.createNode(this,n); | ||||
|         var node = this; | ||||
|  | ||||
|         RED.nodes.createNode(this,n); | ||||
|         this.pin = n.pin; | ||||
|         this.set = n.set || false; | ||||
| @@ -69,10 +66,10 @@ module.exports = function(RED) { | ||||
|             } | ||||
|             else if (p3.test(msg.payload)) { | ||||
|                 var c = msg.payload.split(","); | ||||
|                 var r = Math.floor(parseInt(c[0])*100/256).toString(); | ||||
|                 var g = Math.floor(parseInt(c[1])*100/256).toString(); | ||||
|                 var b = Math.floor(parseInt(c[2])*100/256).toString(); | ||||
|                 rgb = r+","+g+","+b; | ||||
|                 var r1 = Math.floor(parseInt(c[0])*100/256).toString(); | ||||
|                 var g1 = Math.floor(parseInt(c[1])*100/256).toString(); | ||||
|                 var b1 = Math.floor(parseInt(c[2])*100/256).toString(); | ||||
|                 rgb = r1+","+g1+","+b1; | ||||
|             } | ||||
|             else { | ||||
|                 // you can add fancy colours by name here if you want... | ||||
|   | ||||
| @@ -23,9 +23,9 @@ module.exports = function(RED) { | ||||
|     var pre = "\\\\.\\"; | ||||
|  | ||||
|     if (!plat.match(/^win/)) { | ||||
|         pre = ""; | ||||
|         throw "Info : only needed for Windows boxes without serialport npm module installed."; | ||||
|         //util.log("[26-rawserial.js] Info : only really needed for Windows boxes without serialport npm module installed."); | ||||
|         pre = ""; | ||||
|     } | ||||
|  | ||||
|     function RawSerialInNode(n) { | ||||
|   | ||||
| @@ -35,10 +35,10 @@ module.exports = function(RED) { | ||||
|                 } | ||||
|             } | ||||
|             else { | ||||
|                 var l = JSON.stringify(msg.payload).length; | ||||
|                 var le = JSON.stringify(msg.payload).length; | ||||
|                 msg.payload = msgpack.encode(msg.payload); | ||||
|                 node.send(msg); | ||||
|                 node.status({text:l +" o->b "+ msg.payload.length}); | ||||
|                 node.status({text:le +" o->b "+ msg.payload.length}); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|   | ||||
| @@ -23,7 +23,8 @@ var exifNode = require("../../../utility/exif/94-exif.js"); | ||||
| var helper = require('../../../../node-red/test/nodes/helper.js'); | ||||
|  | ||||
| describe('exif node', function() { | ||||
|      | ||||
|     "use strict"; | ||||
|  | ||||
|     beforeEach(function(done) { | ||||
|         helper.startServer(done); | ||||
|     }); | ||||
| @@ -34,43 +35,43 @@ describe('exif node', function() { | ||||
|     }); | ||||
|  | ||||
|     it('extracts location data from Exif data of JPEG', function(done) { | ||||
|          | ||||
|  | ||||
|         var exif = require('exif'); | ||||
|         var ExifImage = exif.ExifImage; | ||||
|          | ||||
|  | ||||
|         // the jpg file is a single black dot but it was originally a photo taken at IBM Hursley | ||||
|         var data = fs.readFileSync("./exif_test_image.jpg", null); // extracting genuine exif data to be fed back as the result of the stubbed ExifImage constructor | ||||
|          | ||||
|  | ||||
|         var eD; | ||||
|          | ||||
|  | ||||
|         new ExifImage({ image : data }, function (error, exifData) { | ||||
|             if(error) { | ||||
|                 done(error); | ||||
|             } else { | ||||
|                 eD = exifData; | ||||
|             } | ||||
|              | ||||
|  | ||||
|             var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]}, | ||||
|                         {id:"helperNode1", type:"helper"}]; | ||||
|             | ||||
|  | ||||
|             helper.load(exifNode, flow, function() { | ||||
|                 var exifNode1 = helper.getNode("exifNode1"); | ||||
|                 var helperNode1 = helper.getNode("helperNode1"); | ||||
|                  | ||||
|  | ||||
|                 helperNode1.on("input", function(msg) { | ||||
|                     msg.location.lat.should.equal(50.95624); // this data is stored in the jpg file | ||||
|                     msg.location.lon.should.equal(-1.36701); | ||||
|                     done(); | ||||
|                 }); | ||||
|                  | ||||
|  | ||||
|                 var stub = sinon.stub(ExifImage.prototype, 'loadImage', function(error, callback) { | ||||
|                     stub.restore(); | ||||
|                     callback(null, eD); | ||||
|                 }); | ||||
|                  | ||||
|  | ||||
|                 exifNode1.receive({payload:data}); | ||||
|             }); | ||||
|         }); | ||||
|          | ||||
|  | ||||
|     }); | ||||
| }); | ||||
|   | ||||
| @@ -15,7 +15,8 @@ | ||||
|  **/ | ||||
|  | ||||
| module.exports = function(grunt) { | ||||
|      | ||||
|     "use strict"; | ||||
|  | ||||
|     // Project configuration. | ||||
|     grunt.initConfig({ | ||||
|         simplemocha: { | ||||
| @@ -51,7 +52,5 @@ module.exports = function(grunt) { | ||||
|     grunt.loadNpmTasks('grunt-contrib-jshint'); | ||||
|     grunt.loadNpmTasks('grunt-lint-inline'); | ||||
|  | ||||
|     grunt.registerTask('default', | ||||
|                        ['jshint:all', 'simplemocha:all']); | ||||
|  | ||||
|     grunt.registerTask('default', ['jshint:all', 'simplemocha:all']); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user