fetch-dht/lib/peerListFormatters/index.js
2020-04-12 16:33:32 -05:00

15 lines
373 B
JavaScript

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;
};