• Stars
    star
    334
  • Rank 125,811 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 13 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

node.js epub reader

epub Build Status

epub is a node.js module to parse EPUB electronic book files.

NB! Only ebooks in UTF-8 are currently supported!.

Installation

npm install epub

Or, if you want a pure-JS version (useful if used in a Node-Webkit app for example):

npm install epub --no-optional

Usage

import EPub from 'epub'
const epub = new EPub(pathToFile, imageWebRoot, chapterWebRoot)

Where

  • pathToFile is the file path to an EPUB file
  • 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_ID can be used to fetch the image form the ebook with getImage. 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_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 opened (EPub is an EventEmitter).

epub.on('end', function() {
  // epub is initialized now
  console.log(epub.metadata.title)

  epub.getChapter('chapter_id', (err, text) => {})
})

epub.parse()

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)

epub.flow.forEach(chapter => {
    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, callback)

Load chapter text from the ebook.

epub.getChapter('chapter1', (error, text) => {})

getChapterRaw(chapter_id, callback)

Load raw chapter text from the ebook.

getImage(image_id, callback)

Load image (as a Buffer value) from the ebook.

epub.getImage('image1', (error, img, mimeType) => {})

getFile(file_id, callback)

Load any file (as a Buffer value) from the ebook.

epub.getFile('css1', (error, data, mimeType) => {})

More Repositories

1

Circular

An open source Buffer app clone
HTML
1,029
star
2

meteoric.sh

Deploy Meteor apps to EC2 (or your own server)
Shell
213
star
3

iso3166

ISO 3166-1 alpha-2 mapping
PHP
64
star
4

mongovel

A Laravel-ish wrapper to the PHP Mongo driver
PHP
33
star
5

laravel-oauth2-server

Demo integration of Brent Shaffer's oauth2-server-php into Laravel 4
PHP
28
star
6

annotator-php

Annotator store built on Silex and MongoDB
PHP
15
star
7

trainer-proposal

Python
13
star
8

topsites

Alexa Top Sites API
PHP
6
star
9

deepnoop

Noop object with arbitrary number of nested attributes that are also noop.
JavaScript
6
star
10

PageRank-Fast

PageRank extension for Google Chrome. Fast and simple.
JavaScript
5
star
11

arxiv-to-hf

Chrome extension to add a link from each Arxiv page to the corresponding HF Paper page
JavaScript
5
star
12

snapchat-lensstudio

4
star
13

Pinterest-Button-Javascript

Pinterest's Javascripts, beautified and stored for historical reference
JavaScript
4
star
14

ios11nlp-benchmark

Perl
4
star
15

tagger-http

Basic HTTP server for Tagger Named Entity Recognizer
Python
3
star
16

coreml-protobuf-parser

Protobuf bindings for ML model formats, inspired by netron
JavaScript
3
star
17

neuralconvo-data

2
star
18

mp4-convert

JavaScript
2
star
19

lofos

2
star
20

epubserver

Go
2
star
21

MammouthApp

A very simple productivity app for Mac OS X Lion
Objective-C
2
star
22

taxrates

PHP
1
star
23

conferencer

A package to easily set-up conference-like websites
PHP
1
star
24

MongoValidator

Adds support for the `unique` and `exists` Laravel validation rules for MongoDB.
PHP
1
star
25

masterofcoin

Turn Stripe Webhook events into Hipchat messages
CSS
1
star
26

flat-huggingface

TypeScript
1
star
27

oauth2-example-auth-server

An example OAuth 2.0 auth server
PHP
1
star
28

TrackUnfollowers

Track who unfollows you on Twitter
1
star
29

Tampon

Tampon is now Circular
1
star
30

AssetFixture

Swift
1
star
31

ScrollTest

Testing basic Phonegap WebView scrolling behavior
JavaScript
1
star
32

SimpleResize

Simple Composer port of Jarrod Oberto's Image Resizing class
1
star
33

Statusnet-Annotations

Plugin to do Twitter-style Annotations (arbitrary custom semantic metadata that can be attached to notices) in StatusNet
1
star
34

mongo-php-daemon-bug

Small set-up demonstrating a bug in PHP Mongo driver
1
star