mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
d63996eea1
and improve XML test coverage slightly
36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
|
|
module.exports = function(RED) {
|
|
"use strict";
|
|
var yaml = require('js-yaml');
|
|
function YAMLNode(n) {
|
|
RED.nodes.createNode(this,n);
|
|
var node = this;
|
|
this.on("input", function(msg) {
|
|
if (msg.hasOwnProperty("payload")) {
|
|
if (typeof msg.payload === "string") {
|
|
try {
|
|
msg.payload = yaml.load(msg.payload);
|
|
node.send(msg);
|
|
}
|
|
catch(e) { node.error(e.message,msg); }
|
|
}
|
|
else if (typeof msg.payload === "object") {
|
|
if (!Buffer.isBuffer(msg.payload)) {
|
|
try {
|
|
msg.payload = yaml.dump(msg.payload);
|
|
node.send(msg);
|
|
}
|
|
catch(e) {
|
|
node.error(RED._("yaml.errors.dropped-error"));
|
|
}
|
|
}
|
|
else { node.warn(RED._("yaml.errors.dropped-object")); }
|
|
}
|
|
else { node.warn(RED._("yaml.errors.dropped")); }
|
|
}
|
|
else { node.send(msg); } // If no payload - just pass it on.
|
|
});
|
|
}
|
|
RED.nodes.registerType("yaml",YAMLNode);
|
|
};
|