A Node.js CLI tool to intelligently merge short chapters in EPUB files while preserving reading flow.
- 📖 Smart Merging - Merges chapters based on word count threshold
- 🔢 Preserves Order - Maintains chapter sequence and hierarchy
- 🎯 Configurable - Set minimum words per merged chapter
- 📋 Dry Run - Preview changes before applying
- ✨ Clean Output - Generates valid EPUB3 files
npm install# Basic usage - merge chapters under 2000 words
node merge-chapters.js input.epub -o output.epub
# Set custom minimum word count
node merge-chapters.js input.epub -o output.epub --min-words 3000
# Preview changes without modifying
node merge-chapters.js input.epub --dry-run
# Show verbose output
node merge-chapters.js input.epub -o output.epub --verbose| Option | Description | Default |
|---|---|---|
-o, --output <file> |
Output EPUB file path | Required |
-m, --min-words <n> |
Minimum words per merged chapter | 2000 |
-d, --dry-run |
Preview without creating file | false |
-v, --verbose |
Show detailed progress | false |
- Parses the EPUB structure (OPF, NCX, NAV)
- Calculates word count for each chapter
- Groups consecutive short chapters
- Merges content while updating navigation
- Outputs a new valid EPUB file
MIT License