How bookracy/epub-converter works
Project type and purpose
• From the README and file tree, this is an NPM library (“bookracy-convertor”) that runs in a browser environment. Its sole purpose is to fetch and parse an EPUB file, then generate a PDF via jsPDF. It is not a full-stack service but an open-source client-side conversion tool (library) intended for embedding into web pages or other JS/TS projects.
File structure
• Top-level files:
• package.json, pnpm-lock.yaml, package-lock.json – NPM package metadata and locks
• README.md, CONTRIBUTING.md – docs
• .github/workflows/publish.yml – CI/CD pipeline for publishing to NPM/GitHub
• “src” directory: core implementation
• fetchFile.ts – retrieves the EPUB blob via HTTP or File API
• handleEpub.ts – unzips EPUB (JSZip) and extracts XHTML chapters, images, TOC
• htmlToText.ts – sanitizes and converts HTML nodes to plain text (html-to-text)
• buildPdf.ts – orchestrates jsPDF page creation, layout, fonts, images, TOC
• index.ts, main.ts – public API entry points (UMD/E SM builds)
• polyfills/node-globals.ts – environment shims for browser vs. Node
• “dist” directory: generated UMD and ESM bundles + sourcemaps
• Configuration: tsconfig.json, vite.config.ts, eslint.config.mjs
• “test” directory: minimal automated test for EPUB→PDF workflow
README for additional insights
• Key dependencies: jsPDF, JSZip, html-to-text
• Usage pattern: import buildPDFConvertor, supply EPUB URL and button element
• Build/test scripts via Vite, ESLint, Node v14+ requirement
Key takeaways
• Every discrete step in the conversion pipeline.
• Delineate build versus runtime clearly.
• How consumers integrate the library (import → button)
• Call out any environment shims/polyfills.