{"id":15541706,"url":"https://github.com/xavdid/epub-wordcount","last_synced_at":"2025-09-03T12:47:18.232Z","repository":{"id":42969554,"uuid":"67275115","full_name":"xavdid/epub-wordcount","owner":"xavdid","description":"[CLI] count the words in an epub file","archived":false,"fork":false,"pushed_at":"2025-02-03T07:10:51.000Z","size":12911,"stargazers_count":34,"open_issues_count":8,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-01T00:11:05.466Z","etag":null,"topics":["cli","drm","ebooks","epub","epub-wordcount","parsing"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/epub-wordcount","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xavdid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-09-03T06:30:41.000Z","updated_at":"2025-07-18T07:24:51.000Z","dependencies_parsed_at":"2024-06-21T19:08:31.013Z","dependency_job_id":"fd973e50-9a9a-4455-9bf4-70255b678a31","html_url":"https://github.com/xavdid/epub-wordcount","commit_stats":{"total_commits":81,"total_committers":3,"mean_commits":27.0,"dds":0.2222222222222222,"last_synced_commit":"e0edb2c9faf21c436b45070cd877e9023e517909"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/xavdid/epub-wordcount","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xavdid%2Fepub-wordcount","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xavdid%2Fepub-wordcount/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xavdid%2Fepub-wordcount/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xavdid%2Fepub-wordcount/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xavdid","download_url":"https://codeload.github.com/xavdid/epub-wordcount/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xavdid%2Fepub-wordcount/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273445979,"owners_count":25107150,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","drm","ebooks","epub","epub-wordcount","parsing"],"created_at":"2024-10-02T12:19:11.478Z","updated_at":"2025-09-03T12:47:18.204Z","avatar_url":"https://github.com/xavdid.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# epub-wordcount\n\nGiven an epub file, do our best to count the number of words in it.\n\n## Installation\n\nThis package is available on [npm](https://www.npmjs.com/package/epub-wordcount) as `epub-wordcount`. It can be installed using common JS tools:\n\n```sh\nnpm i -g epub-wordcount\n```\n\n## Basic Usage\n\nOn the CLI:\n\n```\n% word-count path/to/book.epub\n\nThe Strange Case of Dr. Jekyll and Mr. Hyde\n-------------------------------------------\n  * 26,341 words\n```\n\nIn code:\n\n```ts\n// TS:\nimport { countWords } from 'epub-wordcount'\n\n// JS:\n// const { countWords } = require('epub-wordcount')\n\ncountWords('./books/some-book.epub').then((numWords) =\u003e {\n  console.log(`There are ${numWords} words`)\n})\n// There are 106190 words\n```\n\n## CLI\n\nThere's also a cli tool to quickly get the count of any epub file! Invoke it via:\n\n```bash\nword-count path/to/file.epub\n```\n\nor\n\n```bash\nword-count directory/of/books\n```\n\nSee `word-count -h` for more info\n\n### Options\n\n- `-c, --chars` - Print the alphanumeric character count instead of the world count\n- `-r, --raw` - Instead of printing the nice title, just print out a numeral\n- `-t, --text` - Print out the whole text of the book. Great for passing into other unix functions, like `wc`.\n- `--ignore-drm` - If the function is saying your file has DRM when you know it doesn't, you can pass this flag to force the CLI to ignore the DRM warning. Might cause weird results if the actually _does_ have DRM.\n\n## Code API\n\nThere are a number of functions exported from this package. Each one takes either a path to a file or an already-parsed file. Mostly you'll use the path, but if the epub you're parsing is in a non-standard format, then you might use that function to ensure the file parses correctly. See [here](https://github.com/julien-c/epub#usage) for the options available.\n\n- `countWords(pathOrEpub, ignoreDrm?) =\u003e Promise\u003cnumber\u003e`\n- `countCharacters(pathOrEpub, ignoreDrm?) =\u003e Promise\u003cnumber\u003e`\n- `getText(pathOrEpub, ignoreDrm?) =\u003e Promise\u003cstring[]\u003e`\n\nEach of the above can be passed the result of the following:\n\n- `parseEpubAtPath(path, ignoreDrm?) =\u003e Promise\u003cEPub\u003e`\n\n## Limitations\n\nThere's no programmatic representation for the table of contents in epub and it's hard to skip over the reviews, copyright, etc. An effort is made to only parse the actual story text, but there's a margin of error. Probably no more than ~500 words.\n\nPull requests welcome.\n\n## Test Books\n\nUnit tests are run on the following e-books:\n\n- Stevenson's _THE STRANGE CASE OF DR. JEKYLL AND MR. HYDE_, from the public domain, provided by [Standard Ebooks](https://standardebooks.org/ebooks/robert-louis-stevenson/the-strange-case-of-dr-jekyll-and-mr-hyde)\n- A copy of _The Martian_, by Andy Weir. This is my copy, purchased from Apple Books. It's DRM encumbered, so releasing it publicly should not be seen as copyright infringement.\n\n## Fake ePubs\n\nIn modern versions of macOS, dragging a book out of the `Books` app won't give you an actual epub- it'll give you a folder with the `.epub` extension. Unsurprisingly, this doesn't play well with ePub tooling.\n\nTo fix, run the following command (pulled [from here](https://apple.stackexchange.com/questions/239050/how-to-convert-an-epub-package-to-regular-epub/429474)) fixes them for me:\n\n```sh\n# from inside the rogue directory\nzip -X -r ../fixed.epub mimetype *\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxavdid%2Fepub-wordcount","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxavdid%2Fepub-wordcount","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxavdid%2Fepub-wordcount/lists"}