# teapub

> generate epubs using typescript

Latest version **4.1.0** (published 2026-07-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install teapub
pnpm add teapub
yarn add teapub
bun add teapub
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2026-07-05 |
| First published | 2022-05-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=20.19 |
| Dependencies | 6 |
| Unpacked size | 443 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 7 |
| Author | Erik Brinkman |
| Maintainers | erik.brinkman |
| Keywords | epub, ebook, epub-generator, typescript, javascript |

## Links

- npm: https://www.npmjs.com/package/teapub
- Repository: https://github.com/erikbrinkman/teapub
- Homepage: https://erikbrinkman.github.io/teapub/
- Issues: https://github.com/erikbrinkman/teapub/issues
- npm.io page: https://npm.io/package/teapub

## Dependencies (6)

- [uuid](https://npm.io/package/uuid.md) ^13.0.0
- [jszip](https://npm.io/package/jszip.md) ^3.10.1
- [leven](https://npm.io/package/leven.md) ^4.1.0
- [parse5](https://npm.io/package/parse5.md) ^8.0.0
- [preact](https://npm.io/package/preact.md) ^10.29.0
- [preact-render-to-string](https://npm.io/package/preact-render-to-string.md) ^6.6.6

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2026-07-05
- 4.0.0 — 2026-07-05
- 3.3.0 — 2026-03-15
- 3.2.0 — 2026-03-14
- 3.1.0 — 2024-10-13
- 3.0.0 — 2024-04-20
- 2.2.1 — 2024-04-13
- 2.2.0 — 2023-10-10
- 2.1.0 — 2023-10-04
- 2.0.1 — 2023-10-03
- 2.0.0 — 2023-10-03
- 1.0.5 — 2023-09-30
- 1.0.4 — 2023-09-30
- 1.0.3 — 2023-07-19
- 1.0.2 — 2023-07-04
- … 5 more at https://npm.io/package/teapub/versions

## README

TeaPub :tea::beer:
==================
[![build](https://github.com/erikbrinkman/teapub/actions/workflows/build.yml/badge.svg)](https://github.com/erikbrinkman/teapub/actions/workflows/build.yml)
[![docs](https://img.shields.io/badge/docs-docs-blue)](https://erikbrinkman.github.io/teapub/)
[![npm](https://img.shields.io/npm/v/teapub)](https://www.npmjs.com/package/teapub)
[![license](https://img.shields.io/github/license/erikbrinkman/teapub)](LICENSE)

A pure TypeScript preact-based library for generating ePub files. In contrast
to [`html-to-epub`](https://www.npmjs.com/package/html-to-epub) and
[`nodepub`](https://www.npmjs.com/package/nodepub), this runs in any javascript
environment and seeks a more minimal approach to ePub generation rather than
autogenerating content like a cover and table of contents.

Usage
-----

A minimal example

```ts
import { render } from "teapub";

const buffer = await render({
  title: "title",
  sections: [{
    title: "section title",
    content: "<my html>",
  }],
});
```

This library can also include images encoded as buffers. To include them, add
an images mapping that maps the `src` attribute of images in the included html
to buffers with optional mime type.


```ts
import { readFile } from "fs/promises";
import { render } from "teapub";

const data = await readFile("myfile.jpg");

const buffer = await render({
  title: "title",
  sections: [{
    title: "section title",
    content: `<img src="myfile.jpg"></img>`,
  }],
  images: new Map([["myfile.jpg", { data }]]),
});
```

Custom `woff2` fonts can be embedded and referenced from your CSS. Each entry
is keyed by the filename it will be given under `fonts/` in the epub.

```ts
import { readFile } from "fs/promises";
import { render } from "teapub";

const data = await readFile("myfont.woff2");

const buffer = await render({
  title: "title",
  sections: [{ title: "section title", content: "<p>styled</p>" }],
  fonts: new Map([["myfont.woff2", data]]),
  css: `@font-face { font-family: "My Font"; src: url("fonts/myfont.woff2"); }`,
});
```

`iframe`s work like images: map the `src` attribute of each `iframe` to an
XHTML frame document. Unlike sections, frame content is embedded as-is and
must already be valid XHTML.

```ts
import { render } from "teapub";

const buffer = await render({
  title: "title",
  sections: [{
    title: "section title",
    content: `<iframe src="cid:frame"></iframe>`,
  }],
  frames: new Map([[
    "cid:frame",
    `<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><body><p>inside</p></body></html>`,
  ]]),
});
```

Missing
-------

This is intended as barebones, so a lot of aspects related to generating
"books" as epubs are missing, but easily includable upon request:

- [ ] covers, custom or otherwise
- [ ] table of contents page, custom or otherwise
- [ ] customizable node and attribute filtering

---
_Source: https://npm.io/package/teapub · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
