UNPKG

node-red-contrib-smartnode

Version:

this project is a nodejs package for making the nodered support the Smart Device development. the pacakge require node-red enviroment.

24 lines (22 loc) 727 B
module.exports = function(RED) { function SubStringNode(config) { RED.nodes.createNode(this, config); this.From=config.From; this.To=config.To; var node = this; var length; this.on('input', function(msg) { length=Number(node.To)-Number(node.From)+1; if(Number(node.From) >= String(msg.payload).length || Number(node.To) >= String(msg.payload).length) msg.payload="Out of bounds"; else if(Number(node.From)>Number(node.To)) msg.payload="The 'from' can not > 'to'"; else msg.payload=String(msg.payload).substr(Number(node.From),length); node.send(msg); }); this.on('close',function(){ }); } RED.nodes.registerType("substring",SubStringNode); }