fetch-dht/lib/peerListFormatters/index.js

15 lines
373 B
JavaScript
Raw Permalink Normal View History

2020-04-12 21:33:32 +00:00
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;
};