chore: update tsconfig

fix-undefined-label
Amio 2022-04-30 16:10:24 +08:00 zatwierdzone przez Amio Jin
rodzic ef2f2914d8
commit 49b999f5da
5 zmienionych plików z 14 dodań i 10 usunięć

Wyświetl plik

@ -7,7 +7,7 @@ jobs:
strategy: strategy:
matrix: matrix:
node: [8, 10, 12] node: [8, 10, 12, 14, 16, 18]
os: [ubuntu-latest] os: [ubuntu-latest]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}

Wyświetl plik

@ -1,8 +1,8 @@
// import widthsVerdana110 from './widths-verdana-110.json' // import widthsVerdana110 from './widths-verdana-110.json'
// @ts-ignore // @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 const fallbackWidth = charWidthTable[64] // Width as "@" for overflows
return ([...text]) => { return ([...text]) => {

Wyświetl plik

@ -10,4 +10,4 @@ export default {
gray: '999', gray: '999',
cyan: '1BC', cyan: '1BC',
black: '2A2A2A' black: '2A2A2A'
} } as Record<string, string>

Wyświetl plik

@ -3,11 +3,12 @@ import { Verdana110 as calcWidth } from './calc-text-width'
import colorPresets from './color-presets' import colorPresets from './color-presets'
type StyleOption = 'flat' | 'classic' type StyleOption = 'flat' | 'classic'
type ColorPreset = keyof typeof colorPresets
interface BadgenOptions { interface BadgenOptions {
status: string; status: string;
subject?: string; subject?: string;
color?: string; color?: ColorPreset;
label?: string; label?: string;
labelColor?: string labelColor?: string
style?: StyleOption; style?: StyleOption;
@ -38,16 +39,16 @@ export function badgen ({
labelColor = colorPresets[labelColor] || labelColor labelColor = colorPresets[labelColor] || labelColor
iconWidth = iconWidth * 10 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 sbTextStart = icon ? (iconSpanWidth + 50) : 50
const sbTextWidth = calcWidth(label) const sbTextWidth = label ? calcWidth(label) : 0
const stTextWidth = calcWidth(status) const stTextWidth = calcWidth(status)
const sbRectWidth = sbTextWidth + 100 + iconSpanWidth const sbRectWidth = sbTextWidth + 100 + iconSpanWidth
const stRectWidth = stTextWidth + 100 const stRectWidth = stTextWidth + 100
const width = sbRectWidth + stRectWidth const width = sbRectWidth + stRectWidth
const xlink = icon ? ' xmlns:xlink="http://www.w3.org/1999/xlink"' : '' const xlink = icon ? ' xmlns:xlink="http://www.w3.org/1999/xlink"' : ''
label = sanitize(label) label = label ? sanitize(label) : undefined
status = sanitize(status) status = sanitize(status)
color = sanitize(color) color = sanitize(color)
labelColor = sanitize(labelColor) labelColor = sanitize(labelColor)
@ -93,7 +94,7 @@ export function badgen ({
</svg>` </svg>`
} }
function bare ({ status, color, style, scale }) { function bare ({ status, color = 'blue', style, scale = 1 }: BadgenOptions) {
typeAssert(typeof status === 'string', '<status> must be string') typeAssert(typeof status === 'string', '<status> must be string')
color = colorPresets[color] || color || colorPresets.blue color = colorPresets[color] || color || colorPresets.blue

Wyświetl plik

@ -1,5 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"strict": true,
"target": "es2017", "target": "es2017",
"module": "commonjs", "module": "commonjs",
"lib": ["esnext", "dom"], "lib": ["esnext", "dom"],
@ -12,7 +14,8 @@
"resolveJsonModule": true, "resolveJsonModule": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"allowSyntheticDefaultImports": true "allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
}, },
"include": ["src"] "include": ["src"]
} }