UNPKG

badge-size

Version:

Displays the size of a given file in your repository

40 lines (35 loc) 990 B
const color = require('./lib/color') const compression = require('./lib/compression') const constraints = require('./lib/constraints') const fetch = require('./lib/fetch') const init = require('./lib/init') const pretty = require('./lib/pretty') const send = require('./lib/send') const bind = (fn, ...args) => fn.bind(fn, ...args) const cond = (fn, param) => async (baton) => { if (baton[param] != null) { await fn(baton) } } const tap = (fn) => async (baton) => { await fn(baton) return baton } /** * Handle a badge request. * It redirects to a shields.io badge of type: `size-{size}-brightgreen`. * * @param {ServerRequest} req * @param {ServerResponse} res * @return {Promise} */ module.exports = function badgeSize(req, res) { return init(req) .then(tap(fetch)) .then(tap(cond(compression, 'compression'))) .then(tap(pretty)) .then(tap(cond(constraints, 'max'))) .then(tap(color)) .then(bind(send, res)) .catch(bind(send, res)) }