exports.id = 'debug'; exports.title = 'Debug'; exports.author = 'Peter Širka'; exports.color = '#967ADC'; exports.click = true; exports.input = true; exports.icon = 'bug'; exports.version = '2.0.4'; exports.options = { enabled: true, repository: false, type: 'data' }; exports.readme = `# Debug Prints data to the debug tab.`; exports.html = `
@(Output type)
@(Path to the property (leave empty to show the whole data object))
@(A group name)
@(Enabled)
`; exports.install = function(instance) { instance.on('data', function(response) { if (instance.options.enabled) { var opt = instance.options; var rep = response.repository; var val = response.data; var id = response.id; switch (instance.options.type){ case 'both': var data = {}; data.repository = rep; data.data = val instanceof Error ? { error: val.message, stack: val.stack } : val; instance.debug(safeparse(opt.property ? U.get(data, opt.property) : data), undefined, opt.group, id); break; case 'repository': instance.debug(safeparse(opt.property ? U.get(rep, opt.property) : rep), undefined, opt.group, id); break; case 'data': default: if (val instanceof Error) instance.debug({ error: val.message, stack: val.stack }, undefined, opt.group, id); else instance.debug(safeparse(opt.property ? U.get(val, opt.property) : val), undefined, opt.group, id); break; } } }); instance.on('click', function() { instance.options.enabled = !instance.options.enabled; instance.custom.status(); instance.save(); }); instance.on('options', function() { instance.custom.status(); }); instance.custom.status = function() { instance.status(instance.options.enabled ? 'Enabled' : 'Disabled'); }; instance.custom.status(); function safeparse(o) { if (o instanceof Buffer) return o; if (o === undefined) return 'undefined'; if (o === null) return 'null'; var cache = []; var str = JSON.stringify(o, function(key, value) { if (typeof value === 'object' && value !== null) { if (cache.indexOf(value) !== -1) { try { return JSON.parse(JSON.stringify(value)); } catch (error) { return; } } cache.push(value); } return value; }); cache = null; return JSON.parse(str); } };