For AI agents: the complete documentation index is available at https://anyformat.swc.rs/llms.txt, the full documentation bundle is available at https://anyformat.swc.rs/llms-full.txt, and this page is available as Markdown at https://anyformat.swc.rs/api/font.md.

Font

The font family identifies font formats from the leading bytes of a file.

LanguagePackageModule
Node.js@swc/anyformat-font@swc/anyformat-font
Pythonanyformat-fontanyformat_font

Supported formats

IdentifierMIME typeFormat
ttffont/ttfOpenType or TrueType font with TrueType outlines
otffont/otfOpenType font with CFF outlines
ttcfont/collectionTrueType or OpenType font collection
wofffont/woffWeb Open Font Format 1.0
woff2font/woff2Web Open Font Format 2.0
eotapplication/vnd.ms-fontobjectEmbedded OpenType

detect

Identifies the font format of data from its leading bytes. Returns null in Node.js and None in Python when the format is not recognized.

Node.js

function detect(data: Uint8Array): DetectedFormat | null
import { readFile } from 'node:fs/promises'
import { detect } from '@swc/anyformat-font'

detect(await readFile('Inter.woff2'))
// => { format: 'woff2', mimeType: 'font/woff2' }

Python

def detect(data: bytes) -> DetectedFormat | None
from pathlib import Path

import anyformat_font

anyformat_font.detect(Path("Inter.woff2").read_bytes())
# => DetectedFormat(format='woff2', mime_type='font/woff2')

DetectedFormat

A format identified by detect.

Node.jsPythonTypeDescription
formatformatstringThe stable lowercase identifier of the format, for example "ttf".
mimeTypemime_typestringThe most common MIME type of the format.

In Python, DetectedFormat is a final class with read-only properties, and the type of each property is str.

supportedFormats

Returns the identifier of each format that detect can return.

Node.js

function supportedFormats(): string[]
import { supportedFormats } from '@swc/anyformat-font'

supportedFormats()
// => ['ttf', 'otf', 'ttc', 'woff', 'woff2', 'eot']

Python

def supported_formats() -> list[str]
import anyformat_font

anyformat_font.supported_formats()
# => ['ttf', 'otf', 'ttc', 'woff', 'woff2', 'eot']