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

@cd-z/epub-constructor

v2.2.5

Published

This is a react library that create an epub structor. This library dose not save the structored epub file, you have to do that yourself. This library work for react, react-native and web. It simple create a structored epub object that you could save it to

Downloads

28

Readme

Epub-Constructor

This is a typescript library that create an epub structor. This library dose not save the structored epub file, you have to do that your self. This library work for react, react-native and web. It simple create a structored epub object that you could save it to your desired location later on.

Install

npm install @cd-z/epub-constructor

How to use

import EpubFile from 'epub-constructor'
    var epub = new EpubFile({
          title: "example",
          fileName: "examplefile" // optional, it will take title if not set
          language: "en",
          description: "this is a epub test",
          stylesheet:{
           p: {
            width:"100%"
           }
          },
          chapters:[{
            fileName: "examplefile" // optional, it will take title if not set
            title: "Air born",
            htmlBody: "<p>this is chapter 1</p>"
          },{
            title:"chapter 2",
            htmlBody: "<p>this is chapter 1</p>"
          }]
      });
    var file = await epub.constructEpub();
    // save the file to your device

This is what file will containe

[
  {path:"mimetype",content:"application/epub+zip"},
  {path:"META-INF/container.xml",content:"<?xml version="1.0" encoding="UTF-8"?> <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> <rootfiles> <rootfile full-path="EPUB/example.opf" media-type="application/oebps-package+xml"/> </rootfiles> </container>"},
  {path:"EPUB/styles.css",content:'body { font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif; font-size: 1.125em; line-height: 1.6em; color: #000; } h1, h2, h3, h4, h5, h6 { line-height: 1em; } h1 { font-size: 3em; } h2 { font-size: 2.5em; } p { width: 100%; }'},
  {path:"EPUB/Air born.html",content:'<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"> <head> <link rel="stylesheet" type="text/css" href="styles.css"/> <title>Air born</title> </head> <body> <p>this is a content</p> </body> </html>'},
  {path:"EPUB/chapter 2.html",content:' <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"> <head> <link rel="stylesheet" type="text/css" href="styles.css"/> <title>chapter 2</title> </head> <body> <p>this is a content</p> </body> </html>'},
  {path:"EPUB/example.opf",content:'<?xml version="1.0" encoding="utf-8"?> <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" version="3.0"> <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title class="title">example</dc:title><dc:language class="language">en</dc:language><dc:identifier class="identifier" id="BookId">364</dc:identifier><dc:description class="description">this is a epub test</dc:description><dc:date>Fri Oct 01 2021 16:04:48 GMT+0200 (Central European Summer Time)</dc:date><dc:rights class="rights"></dc:rights><dc:source class="source"></dc:source></metadata> <manifest><item href="styles.css" id="css1" media-type="text/css"></item><item id="Air born1" href="Air born.html" media-type="application/xhtml+xml" ></item><item id="chapter 22" href="chapter 2.html" media-type="application/xhtml+xml" ></item><item properties="nav" id="toc" href="toc.html" media-type="application/xhtml+xml" ></item> <item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml"></item></manifest> <spine toc="ncx"><itemref idref="Air born1" ></itemref><itemref idref="chapter 22" ></itemref></spine> </package>'},
  {path:"EPUB/toc.html",content:'<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"> <head> <link rel="stylesheet" type="text/css" href="styles.css" > <title>example - TOC</title> </head> <body> <nav epub:type="toc" id="toc"> <h1>Table of Contents</h1> <ol> <li><a href="Air born.html">Air born</a></li><li><a href="chapter 2.html">chapter 2</a></li></ol> </nav> </body> </html>'},
  {path:"EPUB/toc.ncx",content:'<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en" dir="ltr"> <head> <meta name="dtb:uid" content="http://digitalpublishingtoolkit.org/ExampleEPUB.html" > <meta name="dtb:depth" content="2" > <meta name="dtb:totalPageCount" content="2" > <meta name="dtb:maxPageNumber" content="0" > </head> <docTitle> <text>example EPUB</text> </docTitle> <docAuthor> <text>undefined</text> </docAuthor> <navMap> <navPoint id="Air born1" playOrder="1"> <navLabel> <text>Air born</text> </navLabel> <content src="Air born.html" ></content></navPoint><navPoint id="chapter 22" playOrder="2"> <navLabel> <text>chapter 2</text> </navLabel> <content src="chapter 2.html" ></content></navPoint></navMap> </ncx>'}
]

You will have to create those files and make a zip file there after.

You could also read an epub file and begin to modify or append chapters there after.

Currently not working

// file have to be extracted by your self. It should look like the above json and be created by this library
var settings = EpubFile.load(file);
settings.chapters.push({
  title: "chapter 3",
  htmlBody: "<p>this is chapter 3</p>",
});
var epub = new EpubFile(settings);
var file = await epub.constructEpub();
// save the file to your device

This library is new and it may containe some bugs so please report those. Will be glad if someone is able to create an android and IOS modules that can create the actual epub(zip) file