`;
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();
};