kopia lustrzana https://github.com/badgen/badgen
refactor: modernize codebase and unify code style (#9)
rodzic
c78693f6a6
commit
e76dfaa370
|
@ -2,7 +2,10 @@ const { Suite } = require('benchmark')
|
|||
const badgen = require('..')
|
||||
const dockerIcon = require('../test/docker-icon-b64.js')
|
||||
|
||||
const longParams = { subject: 'build-build-build', status: 'passing-passing-passing' }
|
||||
const longParams = {
|
||||
subject: 'build-build-build',
|
||||
status: 'passing-passing-passing'
|
||||
}
|
||||
const fullParams = { subject: 'license', status: 'Apache 2.0', color: 'cyan' }
|
||||
const emojiParams = { subject: 'emojis', status: '💩🤱🦄💩🤱🦄', emoji: true }
|
||||
const iconParams = { subject: 'docker', status: 'badge', icon: dockerIcon }
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const widthsVerdana11 = require('./widths-verdana-11.json')
|
||||
const astralRegex = require('unicode-astral-regex')
|
||||
|
||||
function calcWidth (charWidthTable) {
|
||||
const calcWidth = (charWidthTable) => {
|
||||
const SCALE = 10 // Prevent results like 60.599999999999994
|
||||
const widthTable = charWidthTable.map(w => Math.round(w * SCALE))
|
||||
widthTable[64] = widthTable[64] + 6 // Slightly increase width of "@" by 0.6px
|
||||
|
||||
return function (text, astral) {
|
||||
return (text, astral) => {
|
||||
if (astral) text = text.match(astralRegex)
|
||||
|
||||
let total = 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const calcWidth = require('./calc-text-width.js').Verdana11
|
||||
const colorPresets = require('./color-presets.js')
|
||||
|
||||
module.exports = function ({subject, status, color, style, emoji, icon, iconWidth = 13}) {
|
||||
module.exports = ({ subject, status, color, style, emoji, icon, iconWidth = 13 }) => {
|
||||
typeAssert(typeof subject === 'string', '<subject> must be string')
|
||||
typeAssert(typeof status === 'string', '<status> must be string')
|
||||
color = colorPresets[color] || color || colorPresets['blue']
|
||||
|
@ -54,6 +54,6 @@ module.exports = function ({subject, status, color, style, emoji, icon, iconWidt
|
|||
`
|
||||
}
|
||||
|
||||
function typeAssert (assertion, message) {
|
||||
const typeAssert = (assertion, message) => {
|
||||
if (!assertion) throw new TypeError(message)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ const serveBadge = (req, res) => {
|
|||
.map(s => qs.unescape(s))
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'image/svg+xml;charset=utf-8' })
|
||||
res.end(badgen({subject, status, color, style, emoji, icon}))
|
||||
res.end(badgen({ subject, status, color, style, emoji, icon }))
|
||||
}
|
||||
|
||||
// @example
|
||||
|
@ -44,8 +44,11 @@ const serve404 = (req, res) => {
|
|||
|
||||
http.createServer((req, res) => {
|
||||
switch (req.url) {
|
||||
case '/': return serveIndex(req, res)
|
||||
case '/favicon.ico': return serve404(req, res)
|
||||
default: return serveBadge(req, res)
|
||||
case '/':
|
||||
return serveIndex(req, res)
|
||||
case '/favicon.ico':
|
||||
return serve404(req, res)
|
||||
default:
|
||||
return serveBadge(req, res)
|
||||
}
|
||||
}).listen(3000)
|
||||
|
|
Ładowanie…
Reference in New Issue