xavdid/epub-wordcount

GitHub: xavdid/epub-wordcount

这是一个命令行工具和Node.js库,用于统计epub电子书文件中的单词数量,帮助用户快速了解文本长度。

Stars: 34 | Forks: 3

# kept, so I'll output "epub-wordcount" as is, but since it's a heading, maybe it needs a Chinese equivalent. 给定一个 epub 文件,尽力统计其中的单词数量。 ## 安装说明 此包在 [npm](https://www.npmjs.com/package/epub-wordcount) 上名为 `epub-wordcount`。可使用常见的 JS 工具进行安装: ``` npm i -g epub-wordcount ``` ## 基本用法 在命令行中: ``` % word-count path/to/book.epub The Strange Case of Dr. Jekyll and Mr. Hyde ------------------------------------------- * 26,341 words ``` 在代码中: ``` // TS: import { countWords } from 'epub-wordcount' // JS: // const { countWords } = require('epub-wordcount') countWords('./books/some-book.epub').then((numWords) => { console.log(`There are ${numWords} words`) }) // There are 106190 words ``` ## 命令行工具 还有一个命令行工具,可快速统计任意 epub 文件的单词数!通过以下方式调用: ``` word-count path/to/file.epub ``` 或者 ``` word-count directory/of/books ``` 更多信息请查看 `word-count -h` ### 选项 - `-c, --chars` - 打印字母数字字符数,而不是单词数 - `-r, --raw` - 不打印美观的标题,只打印数字 - `-t, --text` - 打印出整本书的文本。非常适合传递给其他 unix 函数,例如 `wc`。 - `--ignore-drm` - 如果函数提示你的文件有 DRM 而你确定它没有,可以传递此标志强制命令行工具忽略 DRM 警告。如果文件实际_确实_有 DRM,这可能会导致奇怪的结果。 ## 代码 API 此包导出了多个函数。每个函数接受一个文件路径或一个已解析的文件对象作为参数。大多数情况下你会使用路径,但如果你解析的 epub 是非标准格式,那么你可能使用该函数来确保文件被正确解析。有关可用选项,请参见[此处](https://github.com/julien-c/epub#usage)。 - `countWords(pathOrEpub, ignoreDrm?) => Promise` - `countCharacters(pathOrEpub, ignoreDrm?) => Promise` - `getText(pathOrEpub, ignoreDrm?) => Promise` 上述每个函数都可以传入以下函数的结果: - `parseEpubAtPath(path, ignoreDrm?) => Promise` ## 局限性 epub 中没有目录的程序化表示,并且很难跳过评论、版权等部分。我们努力只解析实际的故事情节文本,但存在误差范围。可能不超过约 500 个单词。 欢迎提交拉取请求。 ## 测试书籍 单元测试基于以下电子书运行: - Stevenson 的 _《变身怪医》_,来自公共领域,由 [Standard Ebooks](https://standardebooks.org/ebooks/robert-louis-stevenson/the-strange-case-of-dr-jekyll-and-mr-hyde) 提供 - Andy Weir 的 _《火星救援》_ 副本。这是我从 Apple Books 购买的副本。它受 DRM 保护,因此公开发布不应被视为侵犯版权。 ## 伪造的 ePubs 在 macOS 新版本中,将书从 "图书" 应用中拖出并不会给你一个真正的 epub 文件——它会给你一个带有 `.epub` 扩展名的文件夹。不出所料,这与 ePub 工具配合不好。 要解决此问题,请运行以下命令(从[此处](https://apple.stackexchange.com/questions/239050/how-to-convert-an-epub-package-to-regular-epub/429474)获取)修复了我遇到的问题: ``` # The instruction is to translate headings, so for "epub-wordcount", if it's the name of a tool, I might not translate it. But in the context of the output, I should provide a Chinese translation of the heading. zip -X -r ../fixed.epub mimetype * ```
标签:API哈希动态解析, CMS安全, epub单词计数, epub解析, GNU通用公共许可证, JavaScript, MITM代理, Node.js, npm, TypeScript, 书籍分析, 单词计数, 字符计数, 安全插件, 数据可视化, 数据统计, 文件分析, 文本处理, 文本提取, 暗色界面, 电子书工具, 端口扫描, 自动化攻击