const formatters = new Map(); const DEFAULT = 'bencoded'; formatters.set('bencoded', require('./bencoded')); formatters.set('json', require('./json')); formatters.set('compact', require('./compact')); module.exports = (peers, res, format = DEFAULT) => { if (!formatters.has(format)) { format = DEFAULT; } formatters.get(format)(peers, res); return format; };