简介
trove-electron-spellchecker
是一个 npm 包,它是基于 Electron 的拼写检查器。它使用 Trove 词典数据,可以精准地检查拼写并提供纠正建议。
安装
使用 npm 进行安装:
npm install trove-electron-spellchecker --save
使用
const SpellChecker = require('trove-electron-spellchecker'); const text = 'This is a testt.'; const suggestions = SpellChecker.getCorrectionsForMisspelling(text); console.log(suggestions); // ["test", "testy", "texts"]
API
SpellChecker.getCorrectionsForMisspelling(text: string): string[]
给定文本,返回建议的更正建议,如果没有拼写错误,则返回一个空数组。
示例
const SpellChecker = require('trove-electron-spellchecker'); const text = 'I cant spel'; const suggestions = SpellChecker.getCorrectionsForMisspelling(text); console.log(suggestions); // ["can't", "cant", "ant", "canst", "can'ts", "countless", "canest", "canter", "canst's", "can'tl", "canstl", "can't's", "cantaloupe", "can'ta", "can'tis", "can'te", "Canute", "can'tle", "can'ty", "can'ti", "cantala", "cantina", "cantabank", "consequential", "caruncle", "cantal", "countable", "cantalite", "cantarid", "cantaloups", "contulma", "cant-dog", "conte-clef", "canthus", "campal", "conical", "central", "contable", "cimbal", "Kimble", "combless", "comblike", "confusable", "confusible", "campanulaceous", "campanulate", "campaniliform", "campaniliformed", "Cannabine", "Cantal", "Cantabrian", "Cantaborian", "Cantab", "cant-refuse", "cantionally", "Christ-like", "Chrysippelian", "consentfully", "consentience"]
其他说明
trove-electron-spellchecker
仅适用于 Electron 应用,不适用于 Web 应用。如果您希望使用更大型的词典集,请考虑使用其他的拼写检查器,如 Hunspell。这个包不包含像 Hunspell 那样的算法,因此不适用于大量文本的检查。
该包使用 Node.js v10 或更高版本进行构建和测试。
总结
trove-electron-spellchecker
是一个基于 Electron 的拼写检查器,它使用 Trove 词典数据来提供精准的拼写检查和建议。该包简单易用,并且可以在您的项目中起到很好的作用。希望这篇文章对您有所帮助!
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/600562ca81e8991b448e0112