GithubHelp home page GithubHelp logo

zhangwuji1991 / epub Goto Github PK

View Code? Open in Web Editor NEW

This project forked from julien-c/epub

0.0 1.0 0.0 608 KB

node.js epub reader

Home Page: https://www.npmjs.com/package/epub

License: Other

JavaScript 97.92% TypeScript 2.08%

epub's Introduction

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

const EPub = require("epub");
let epub = new EPub(epubfile, imagewebroot, chapterwebroot);

Where

  • epubfile 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 now usable
	console.log(epub.metadata.title);

	epub.getChapter("chapter_id", function(err, text){});
});
epub.parse();

metadata

Property of the epub object that holds several metadata fields about the book.

epub = new EPub(...);
...
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 = new EPub(...);
...
epub.flow.forEach(function(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.

const epub = new EPub(...);
...
epub.getChapter("chapter1", function(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.

const epub = new EPub(...);
...
epub.getImage("image1", function(error, img, mimeType){});

getFile(file_id, callback)

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

const epub = new EPub(...);
...
epub.getFile("css1", function(error, data, mimeType){});

epub's People

Contributors

julien-c avatar andris9 avatar xavdid avatar mawi12345 avatar christianroy avatar orthros avatar nemanjan00 avatar abrady0 avatar smarticles101 avatar graimon avatar craftsmaker avatar json02 avatar wxclover avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.