This is a react 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 t
npm install epub-constructornpm install epub-constructor
js
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: "this is chapter 1
"
},{
title:"chapter 2",
htmlBody: "this is chapter 1
"
}]
});
var file = await epub.constructEpub();
// save the file to your device
`
This is what file will containe
`json
►0:{path:"mimetype",content:"application/epub+zip"}
►1:{path:"META-INF/container.xml",content:" "}
►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:" Air born this is a content
"}
►4:{path:"OEBPS/chapter 2.html",content:" chapter 2 this is a content
"}
►5:{path:"OEBPS/example.opf",content:" example en 364 this is a epub test Fri Oct 01 2021 16:04:48 GMT+0200 (Central European Summer Time) "}
►6:{path:"OEBPS/toc.html",content:" example - TOC "}
►7:{path:"OEBPS/toc.ncx",content:" example EPUB undefined Air born chapter 2 "}
`
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.
`js
// 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: "this is chapter 3
"
})
var epub = new EpubFile(settings);
var file = await epub.constructEpub();
// save the file to your device
``