julien-c/epub
关于
Node.js 的 EPUB 阅读器。
其他项目实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文epub 
epub is a pure-JS module to parse EPUB electronic book files.
NB! Only ebooks in UTF-8 are currently supported!.
CLI
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"
Installation
npm install epub
Usage
import EPub from "epub";
const epub = new EPub(pathToFile);
Where
- pathToFile is the file path to an EPUB file
- Optional:
- imageWebRoot is the prefix for image URL's. If it's /images/ then the actual URL (inside chapter HTML
<img>blocks) is going to be /images/IMG_ID/IMG_FILENAME,IMG_IDcan be used to fetch the image form the ebook withgetImage. Default:/images/ - chapterWebRoot is the prefix for chapter URL's. If it's /chapter/ then the actual URL (inside chapter HTML
<a>links) is going to be /chapters/CHAPTER_ID/CHAPTER_FILENAME,CHAPTER_IDcan be used to fetch the image form the ebook withgetChapter. Default:/links/
- imageWebRoot is the prefix for image URL's. If it's /images/ then the actual URL (inside chapter HTML
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");
metadata
Property of the epub object that holds several metadata fields about the book.
epub.metadata;
Available fields:
- creator Author of the book (if multiple authors, then the first on the list) (Lewis Carroll)
- creatorFileAs Author name on file (Carroll, Lewis)
- title Title of the book (Alice's Adventures in Wonderland)
- language Language code (en or en-us etc.)
- subject Topic of the book (Fantasy)
- date creation of the file (2006-08-12)
- description
flow
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
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
getChapter(chapter_id)
Load chapter text from the ebook.
const text = await epub.getChapter("chapter1");
getChapterRaw(chapter_id)
Load raw chapter text from the ebook.
getImage(image_id)
Load image (as a Buffer value) from the ebook.
const { data, mimeType } = await epub.getImage("image1");
getFile(file_id)
Load any file (as a Buffer value) from the ebook.
const { data, mimeType } = await epub.getFile("css1");
探索相关项目
加载中…