exports.id = 'timer'; exports.title = 'Timer'; exports.version = '1.0.1'; exports.group = 'Time'; exports.color = '#F6BB42'; exports.output = 1; exports.click = true; exports.author = 'Peter Širka'; exports.icon = 'clock-o'; exports.options = { interval: 1000 }; exports.html = `
@(Interval in milliseconds)
@(Data type (String by default))
@(Data)
`; exports.readme = `# Timer Timer will trigger flow in the given interval (in milliseconds). You can optionally define a data-type of the output and the data.`; exports.install = function(instance) { var value; var id; instance.on('click', () => value && instance.send2(value)); instance.reconfigure = function() { var options = instance.options; if (!options.interval) { instance.status('Not configured', 'red'); return; } value = null; switch (options.datatype) { case 'string': value = options.data; break; case 'integer': value = U.parseInt(options.data); break; case 'float': value = U.parseFloat(options.data); break; case 'date': var num = U.parseInt(options.data); value = num ? new Date(num) : options.data.parseDate(); break; case 'object': try { value = (new Function('return ' + options.data))(); } catch (e) { instance.error(e); } break; case 'boolean': value = options.data.parseBoolean(); break; case 'buffer': try { value = F.is4 ? Buffer.from(options.data) : U.createBuffer(options.data); } catch (e) { instance.error(e); } break; } clearInterval(id); options.interval && (id = setInterval(() => instance.send2(value), options.interval)); instance.status(''); }; instance.on('close', () => clearInterval(id)); instance.on('options', instance.reconfigure); instance.reconfigure(); };