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 epub-constructor
How to use
import EpubFile from 'epub-constructor'
var epub = new EpubFile({
title: "example",
fileName: "examplefile"
language: "en",
description: "this is a epub test",
stylesheet:{
p: {
width:"100%"
}
},
chapters:[{
fileName: "examplefile"
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();
This is what file will containe
►0:{path:"mimetype",content:"application/epub+zip"}
►1:{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="OEBPS/example.opf" media-type="application/oebps-package+xml"/> </rootfiles> </container>"}
►2:{path:"OEBPS/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%; } "}
►3:{path:"OEBPS/Air born.html",content:" <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <html xmlns="http:
►4:{path:"OEBPS/chapter 2.html",content:" <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <html xmlns="http:
►5:{path:"OEBPS/example.opf",content:"<?xml version="1.0" encoding="utf-8"?> <package xmlns="http:
►6:{path:"OEBPS/toc.html",content:"<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <html xmlns="http:
►7:{path:"OEBPS/toc.ncx",content:"<ncx xmlns="http:
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.
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();
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