kopia lustrzana https://github.com/badgen/badgen
chore: update tsconfig
rodzic
ef2f2914d8
commit
49b999f5da
|
@ -7,7 +7,7 @@ jobs:
|
|||
|
||||
strategy:
|
||||
matrix:
|
||||
node: [8, 10, 12]
|
||||
node: [8, 10, 12, 14, 16, 18]
|
||||
os: [ubuntu-latest]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// import widthsVerdana110 from './widths-verdana-110.json'
|
||||
// @ts-ignore
|
||||
const widthsVerdana110 = require('./widths-verdana-110.json')
|
||||
const widthsVerdana110: number[] = require('./widths-verdana-110.json')
|
||||
|
||||
const calcWidth = (charWidthTable) => {
|
||||
const calcWidth = (charWidthTable: number[]) => {
|
||||
const fallbackWidth = charWidthTable[64] // Width as "@" for overflows
|
||||
|
||||
return ([...text]) => {
|
||||
|
|
|
@ -10,4 +10,4 @@ export default {
|
|||
gray: '999',
|
||||
cyan: '1BC',
|
||||
black: '2A2A2A'
|
||||
}
|
||||
} as Record<string, string>
|
||||
|
|
11
src/index.ts
11
src/index.ts
|
@ -3,11 +3,12 @@ import { Verdana110 as calcWidth } from './calc-text-width'
|
|||
import colorPresets from './color-presets'
|
||||
|
||||
type StyleOption = 'flat' | 'classic'
|
||||
type ColorPreset = keyof typeof colorPresets
|
||||
|
||||
interface BadgenOptions {
|
||||
status: string;
|
||||
subject?: string;
|
||||
color?: string;
|
||||
color?: ColorPreset;
|
||||
label?: string;
|
||||
labelColor?: string
|
||||
style?: StyleOption;
|
||||
|
@ -38,16 +39,16 @@ export function badgen ({
|
|||
labelColor = colorPresets[labelColor] || labelColor
|
||||
iconWidth = iconWidth * 10
|
||||
|
||||
const iconSpanWidth = icon ? (label.length ? iconWidth + 30 : iconWidth - 18) : 0
|
||||
const iconSpanWidth = icon ? (label?.length ? iconWidth + 30 : iconWidth - 18) : 0
|
||||
const sbTextStart = icon ? (iconSpanWidth + 50) : 50
|
||||
const sbTextWidth = calcWidth(label)
|
||||
const sbTextWidth = label ? calcWidth(label) : 0
|
||||
const stTextWidth = calcWidth(status)
|
||||
const sbRectWidth = sbTextWidth + 100 + iconSpanWidth
|
||||
const stRectWidth = stTextWidth + 100
|
||||
const width = sbRectWidth + stRectWidth
|
||||
const xlink = icon ? ' xmlns:xlink="http://www.w3.org/1999/xlink"' : ''
|
||||
|
||||
label = sanitize(label)
|
||||
label = label ? sanitize(label) : undefined
|
||||
status = sanitize(status)
|
||||
color = sanitize(color)
|
||||
labelColor = sanitize(labelColor)
|
||||
|
@ -93,7 +94,7 @@ export function badgen ({
|
|||
</svg>`
|
||||
}
|
||||
|
||||
function bare ({ status, color, style, scale }) {
|
||||
function bare ({ status, color = 'blue', style, scale = 1 }: BadgenOptions) {
|
||||
typeAssert(typeof status === 'string', '<status> must be string')
|
||||
color = colorPresets[color] || color || colorPresets.blue
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"lib": ["esnext", "dom"],
|
||||
|
@ -12,7 +14,8 @@
|
|||
|
||||
"resolveJsonModule": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue