kopia lustrzana https://github.com/badgen/badgen
chore: better warning of input type error
rodzic
9e7f0c1e64
commit
a8a7895702
|
@ -7,7 +7,6 @@ function calcWidth (charWidthTable) {
|
|||
widthTable[64] = widthTable[64] + 4 // Slightly increase width of "@" by 0.4px
|
||||
|
||||
return function (text, astral) {
|
||||
typeAssert(typeof text === 'string', 'Input must be string')
|
||||
if (astral) text = text.match(astralRegex)
|
||||
|
||||
let total = 0
|
||||
|
@ -21,10 +20,6 @@ function calcWidth (charWidthTable) {
|
|||
}
|
||||
}
|
||||
|
||||
const typeAssert = (assertion, message) => {
|
||||
if (!assertion) throw new TypeError(message)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Verdana11: calcWidth(widthsVerdana11)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ const calcWidth = require('./calc-text-width.js').Verdana11
|
|||
const colorPresets = require('./color-presets.js')
|
||||
|
||||
module.exports = function ({subject, status, color, style, emoji, icon}) {
|
||||
typeAssert(typeof subject === 'string', '<subject> must be string')
|
||||
typeAssert(typeof status === 'string', '<status> must be string')
|
||||
|
||||
color = colorPresets[color] || color || colorPresets['blue']
|
||||
|
||||
const stTextWidth = calcWidth(status, emoji)
|
||||
|
@ -51,3 +54,7 @@ module.exports = function ({subject, status, color, style, emoji, icon}) {
|
|||
function genIconMarkup (iconB64) {
|
||||
return `<image x="4.5" y="3" width="14" height="14" xlink:href="${iconB64}"/>`
|
||||
}
|
||||
|
||||
function typeAssert (assertion, message) {
|
||||
if (!assertion) throw new TypeError(message)
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue