package
Parse EPUB electronic book files with Node.JS
npm install epubGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
epub is a pure-JS module to parse EPUB electronic book files.
NB! Only ebooks in UTF-8 are currently supported!.
Read an Epub directly from your terminal 🔥
URL="https://github.com/progit/progit2/releases/download/2.1.449/progit.epub"
npx epub "$URL"
# or
pnpx epub "$URL"npm install epubimport EPub from "epub";
const epub = new EPub(pathToFile);Where
<img> blocks) is going to be /images/IMG_ID/IMG_FILENAME, IMG_ID can be used to fetch the image form the ebook with getImage. Default: /images/<a> links) is going to be /chapters/CHAPTER_ID/CHAPTER_FILENAME, CHAPTER_ID can be used to fetch the image form the ebook with getChapter. Default: /links/Before the contents of the ebook can be read, it must be parsed:
await epub.parse();
console.log(epub.metadata.title);
const text = await epub.getChapter("chapter_id");Property of the epub object that holds several metadata fields about the book.
epub.metadata;Available fields:
flow is a property of the epub object and holds the actual list of chapters (TOC is just an indication and can link to a # url inside a chapter file)
for (const chapter of epub.flow) {
console.log(chapter.id);
}Chapter id is needed to load the chapters getChapter
toc is a property of the epub object and indicates a list of titles/urls for the TOC. Actual chapter and it's ID needs to be detected with the href property
Load chapter text from the ebook.
const text = await epub.getChapter("chapter1");Load raw chapter text from the ebook.
Load image (as a Buffer value) from the ebook.
const { data, mimeType } = await epub.getImage("image1");Load any file (as a Buffer value) from the ebook.
const { data, mimeType } = await epub.getFile("css1");andris
andris@kreata.ee
Estimated unpacked size across 20 packages.
5.5 MB
Includes dependencies.