> 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.

# Font

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

| Language | Package               | Module                |
| -------- | --------------------- | --------------------- |
| Node.js  | `@swc/anyformat-font` | `@swc/anyformat-font` |
| Python   | `anyformat-font`      | `anyformat_font`      |

## Supported formats

| Identifier | MIME type                       | Format                                           |
| ---------- | ------------------------------- | ------------------------------------------------ |
| `ttf`      | `font/ttf`                      | OpenType or TrueType font with TrueType outlines |
| `otf`      | `font/otf`                      | OpenType font with CFF outlines                  |
| `ttc`      | `font/collection`               | TrueType or OpenType font collection             |
| `woff`     | `font/woff`                     | Web Open Font Format 1.0                         |
| `woff2`    | `font/woff2`                    | Web Open Font Format 2.0                         |
| `eot`      | `application/vnd.ms-fontobject` | Embedded 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

```ts
function detect(data: Uint8Array): DetectedFormat | null
```

```js
import { readFile } from 'node:fs/promises'
import { detect } from '@swc/anyformat-font'

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

### Python

```python
def detect(data: bytes) -> DetectedFormat | None
```

```python
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.js    | Python      | Type     | Description                                                         |
| ---------- | ----------- | -------- | ------------------------------------------------------------------- |
| `format`   | `format`    | `string` | The stable lowercase identifier of the format, for example `"ttf"`. |
| `mimeType` | `mime_type` | `string` | The 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

```ts
function supportedFormats(): string[]
```

```js
import { supportedFormats } from '@swc/anyformat-font'

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

### Python

```python
def supported_formats() -> list[str]
```

```python
import anyformat_font

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