kopia lustrzana https://github.com/badgen/badgen
chore: update tsconfig
rodzic
ef2f2914d8
commit
49b999f5da
|
@ -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 }}
|
||||||
|
|
|
@ -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]) => {
|
||||||
|
|
|
@ -10,4 +10,4 @@ export default {
|
||||||
gray: '999',
|
gray: '999',
|
||||||
cyan: '1BC',
|
cyan: '1BC',
|
||||||
black: '2A2A2A'
|
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'
|
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
|
||||||
|
|
||||||
|
|
|
@ -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"]
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue