X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=src%2Ftemplate%2Fbadge-svg.js;h=7930a1f72911862777bdeb9d9f4f28bef0d92272;hb=8cd88ab4087a7fab2ccd6e231c64d7f0f1299f26;hp=3ef44d26533b1eb8247104c55bc6ab34e7396f36;hpb=737fbd003d5c4dfea81b667ef906f1c106a60612;p=websub-hub diff --git a/src/template/badge-svg.js b/src/template/badge-svg.js index 3ef44d2..7930a1f 100644 --- a/src/template/badge-svg.js +++ b/src/template/badge-svg.js @@ -13,6 +13,12 @@ const ctxDefaults = { }; +/** + * + * @param {number} n number + * @param {number} p precision + * @returns {number} rounded + */ function fixedRound(n, p = 2) { return Number(n.toFixed(p)); } @@ -20,19 +26,21 @@ function fixedRound(n, p = 2) { /** * image/svg+xml;charset=utf-8 formatted badge with subscriber count for a topic - * @param {Object} ctx - badge-specific context (not request context) - * @param {String} label - * @param {String} message - * @param {String} accessibleText - * @returns {String} + * @param {object} ctx - badge-specific context (not request context) + * @param {string} label label + * @param {string} message message + * @param {string} accessibleText accessible text + * @returns {string} svg element */ module.exports = (ctx, label, message, accessibleText) => { - ctx = Object.assign({}, ctxDefaults, ctx, { + ctx = { + ...ctxDefaults, + ...ctx, label, message, accessibleText, - }); + }; ctx.verticalMargin = fixedRound(ctx.height * 0.69); ctx.labelWidth = fixedRound(ctx.label.length * ctx.charWidth); ctx.messageWidth = fixedRound(ctx.message.length * ctx.charWidth);