Add ensure string helper for nodes.

This commit is contained in:
Mark Hindess
2014-08-28 14:25:41 +01:00
parent e09ac859d3
commit a9e72858df
6 changed files with 77 additions and 24 deletions

View File

@@ -83,14 +83,7 @@ module.exports = function(RED) {
var k = this.key || msg.topic;
if (k) {
if (this.structtype == "string") {
if (Buffer.isBuffer(msg.payload)) {
msg.payload = msg.payload.toString();
} else if (typeof msg.payload === "object") {
msg.payload = JSON.stringify(msg.payload);
} else if (typeof msg.payload !== "string") {
msg.payload = ""+msg.payload;
}
this.client.set(k,msg.payload);
this.client.set(k,RED.utils.ensureString(msg.payload));
} else if (this.structtype == "hash") {
var r = hashFieldRE.exec(msg.payload);
if (r) {