Files
accounted/lib/invoices/font-files.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

33 lines
851 B
TypeScript

export type InvoiceFontFileFormat = 'ttf' | 'woff'
export function detectInvoiceFontFileFormat(
bytes: Uint8Array,
): InvoiceFontFileFormat | null {
if (bytes.byteLength < 4) return null
if (
bytes[0] === 0x00 &&
bytes[1] === 0x01 &&
bytes[2] === 0x00 &&
bytes[3] === 0x00
) {
return 'ttf'
}
const signature = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3])
if (signature === 'true') return 'ttf'
if (signature === 'wOFF') return 'woff'
return null
}
export function getInvoiceFontContentType(format: InvoiceFontFileFormat): string {
return format === 'ttf' ? 'font/ttf' : 'font/woff'
}
export function toInvoiceFontDataUrl(
bytes: Uint8Array,
format: InvoiceFontFileFormat,
): string {
return `data:${getInvoiceFontContentType(format)};base64,${Buffer.from(bytes).toString('base64')}`
}