Migrate to new node function style

This commit is contained in:
Nick O'Leary
2014-05-03 23:32:04 +01:00
parent 5afc5857c4
commit ff49d2b217
37 changed files with 3194 additions and 3170 deletions

View File

@@ -14,18 +14,19 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var sentiment = require('sentiment');
function SentimentNode(n) {
RED.nodes.createNode(this,n);
var node = this;
this.on("input", function(msg) {
sentiment(msg.payload, msg.overrides || null, function (err, result) {
msg.sentiment = result;
node.send(msg);
module.exports = function(RED) {
var sentiment = require('sentiment');
function SentimentNode(n) {
RED.nodes.createNode(this,n);
var node = this;
this.on("input", function(msg) {
sentiment(msg.payload, msg.overrides || null, function (err, result) {
msg.sentiment = result;
node.send(msg);
});
});
});
}
RED.nodes.registerType("sentiment",SentimentNode);
}
RED.nodes.registerType("sentiment",SentimentNode);

View File

@@ -14,31 +14,32 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var util = require("util");
var parseString = require('xml2js').parseString;
var useColors = true;
//util.inspect.styles.boolean = "red";
function Xml2jsNode(n) {
RED.nodes.createNode(this,n);
this.useEyes = n.useEyes||false;
var node = this;
this.on("input", function(msg) {
try {
parseString(msg.payload, {strict:true,async:true}, function (err, result) {
//parseString(msg.payload, {strict:false,async:true}, function (err, result) {
if (err) { node.error(err); }
else {
msg.payload = result;
node.send(msg);
if (node.useEyes == true) {
node.log("\n"+util.inspect(msg, {colors:useColors, depth:10}));
module.exports = function(RED) {
var util = require("util");
var parseString = require('xml2js').parseString;
var useColors = true;
//util.inspect.styles.boolean = "red";
function Xml2jsNode(n) {
RED.nodes.createNode(this,n);
this.useEyes = n.useEyes||false;
var node = this;
this.on("input", function(msg) {
try {
parseString(msg.payload, {strict:true,async:true}, function (err, result) {
//parseString(msg.payload, {strict:false,async:true}, function (err, result) {
if (err) { node.error(err); }
else {
msg.payload = result;
node.send(msg);
if (node.useEyes == true) {
node.log("\n"+util.inspect(msg, {colors:useColors, depth:10}));
}
}
}
});
}
catch(e) { util.log("[73-parsexml.js] "+e); }
});
});
}
catch(e) { util.log("[73-parsexml.js] "+e); }
});
}
RED.nodes.registerType("xml2js",Xml2jsNode);
}
RED.nodes.registerType("xml2js",Xml2jsNode);

View File

@@ -14,23 +14,24 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var js2xmlparser = require("js2xmlparser");
function Js2XmlNode(n) {
RED.nodes.createNode(this,n);
this.root = n.root;
var node = this;
this.on("input", function(msg) {
try {
var root = node.root || typeof msg.payload;
if (typeof msg.payload !== "object") { msg.payload = '"'+msg.payload+'"'; }
console.log(root, typeof msg.payload,msg.payload);
msg.payload = js2xmlparser(root, msg.payload);
node.send(msg);
}
catch(e) { console.log(e); }
});
module.exports = function(RED) {
var js2xmlparser = require("js2xmlparser");
function Js2XmlNode(n) {
RED.nodes.createNode(this,n);
this.root = n.root;
var node = this;
this.on("input", function(msg) {
try {
var root = node.root || typeof msg.payload;
if (typeof msg.payload !== "object") { msg.payload = '"'+msg.payload+'"'; }
console.log(root, typeof msg.payload,msg.payload);
msg.payload = js2xmlparser(root, msg.payload);
node.send(msg);
}
catch(e) { console.log(e); }
});
}
RED.nodes.registerType("json2xml",Js2XmlNode);
}
RED.nodes.registerType("json2xml",Js2XmlNode);