npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@graasp/epub

v0.1.4

Published

A library to generate EPUB from HTML.

Downloads

10

Readme

epub-gen - a library to make EPUBs from HTML

Join the chat at https://gitter.im/cyrilis/epub-gen

Generate EPUB books from HTML with simple API in Node.js.


This epub library will generate temp html and download images in your DOMs, then generate the epub book you want.

It's very fast, except the time to download images from the web.

Usage

Install the lib and add it as a dependency (recommended), run on your project dir:

npm install epub-gen --save

Then put this in your code:

    const Epub = require("epub-gen");

    new Epub(option [, output]).promise.then(
        () => console.log("Ebook Generated Successfully!"),
	err => console.error("Failed to generate Ebook because of ", err)
    );

Options

  • title: Title of the book

  • author: Name of the author for the book, string or array, eg. "Alice" or ["Alice", "Bob"]

  • publisher: Publisher name (optional)

  • cover: Book cover image (optional), File path (absolute path) or web url, eg. "http://abc.com/book-cover.jpg" or "/User/Alice/images/book-cover.jpg"

  • output Out put path (absolute path), you can also path output as the second argument when use new , eg: new Epub(options, output)

  • version: You can specify the version of the generated EPUB, 3 the latest version (http://idpf.org/epub/30) or 2 the previous version (http://idpf.org/epub/201, for better compatibility with older readers). If not specified, will fallback to 3.

  • css: If you really hate our css, you can pass css string to replace our default style. eg: "body{background: #000}"

  • fonts: Array of (absolute) paths to custom fonts to include on the book so they can be used on custom css. Ex: if you configure the array to fonts: ['/path/to/Merriweather.ttf'] you can use the following on the custom CSS:

    @font-face {
        font-family: "Merriweather";
        font-style: normal;
        font-weight: normal;
        src : url("./fonts/Merriweather.ttf");
    }
  • lang: Language of the book in 2 letters code (optional). If not specified, will fallback to en.

  • tocTitle: Title of the table of contents. If not specified, will fallback to Table Of Contents.

  • appendChapterTitles: Automatically append the chapter title at the beginning of each contents. You can disable that by specifying false.

  • customOpfTemplatePath: Optional. For advanced customizations: absolute path to an OPF template.

  • customNcxTocTemplatePath: Optional. For advanced customizations: absolute path to a NCX toc template.

  • customHtmlTocTemplatePath: Optional. For advanced customizations: absolute path to a HTML toc template.

  • content: Book Chapters content. It's should be an array of sections. eg. [{title: "Section 1", data: [{title: "Chapter 1", data: "<div>..."}, ...]},...]

    Within each section object:

    • title: section title
    • coverContent: a chapter object, which represents the page the section's title in the TOC redirects to
    • data: required, HTML String of the chapter content. image paths should be absolute path (should start with "http" or "https"), so that they could be downloaded. With the upgrade is possible to use local images (for this the path must start with file: //)

    Within each chapter object:

    • title: optional, Chapter title
    • author: optional, if each book author is different, you can fill it.
    • data: required, HTML String of the chapter content. image paths should be absolute path (should start with "http" or "https"), so that they could be downloaded. With the upgrade is possible to use local images (for this the path must start with file: //)
    • excludeFromToc: optional, if is not shown on Table of content, default: false;
    • beforeToc: optional, if is shown before Table of content, such like copyright pages. default: false;
    • filename: optional, specify filename for each chapter, default: undefined;
  • verbose: specify whether or not to console.log progress messages, default: false.

  • backCover: optional, Object whose data attribute is the hmtl content of the back cover

Output

If you don't want pass the output pass the output path as the second argument, you should specify output path as option.output.


Demo Code:

    const Epub = require("epub-gen");

    const option = {
        title: "Alice's Adventures in Wonderland", // *Required, title of the book.
        author: "Lewis Carroll", // *Required, name of the author.
        publisher: "Macmillan & Co.", // optional
        cover: "http://demo.com/url-to-cover-image.jpg", // Url or File path, both ok.
        content: [
            {
                title: "About the author", // Optional
                author: "John Doe", // Optional
                data: "<h2>Charles Lutwidge Dodgson</h2>"
                +"<div lang=\"en\">Better known by the pen name Lewis Carroll...</div>" // pass html string
            },
            {
                title: "Down the Rabbit Hole",
                data: "<p>Alice was beginning to get very tired...</p>"
            },
            {
                ...
            }
            ...
        ]
    };

    new Epub(option, "/path/to/book/file/path.epub");

Demo Preview:

Demo Preview

From Lewis Carroll "Alice's Adventures in Wonderland", based on text at https://www.cs.cmu.edu/~rgs/alice-table.html and images from http://www.alice-in-wonderland.net/resources/pictures/alices-adventures-in-wonderland.

License

(The MIT License)

Copyright (c) 2015 Cyril Hou <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.