Package Exports
- electron-hunspell
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (electron-hunspell) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Electron-hunspell
electron-hunspell provides hunspell based spell checker to Electron based applications with minimal, simple api. This module aims specific design goals compare to other spellchecker implementations
- No native module dependencies
- No platform specific, consistent behavior via hunspell
- Low level explicit api surface
There are couple of modules to improve spell checking experiences via electron-hunspell to check out if you're interested
cld3-asm: Javascript bindings for google compact language detector v3hunspell-dict-downloader: Downloader for hunspell dict around several available locales
Install
npm install electron-hunspellUsage
Creating spellchecker provider
electron-hunspell exposes SpellCheckerProvider, class to manage spellchecker instance for several dictionaries.
import { SpellCheckerProvider } from 'electron-hunspell';
const provider = new SpellCheckerProvider();
await provider.initialize();Once you have provider instance, you can manage each dictionary based on locale key.
await provider.loadDictionary('en', './en-US.dic', './en-US.aff');loadDictionary creates spellchecker instance to corresponding locale key.
public loadDictionary(key: string, dicPath: string, affPath: string): Promise<void>;
public loadDictionary(key: string, dicBuffer: ArrayBufferView, affBuffer: ArrayBufferView): Promise<void>;It also accepts overload of supplying ArrayBufferView for cases you're under environment download dictionary via fetch or similar manner and have object in memory.
Once dictionary is loaded in provider instance, you can specify which dictionary to check spells.
public switchDictionary(key: string): voidNote switching dictionary doesn't occur automatically, it should be called explicitly as needed.
When dictionary is no longer needed it should be manually disposed via unloadDictionary interface.
public unloadDictionary(key: string): voidIf given key is currently selected spellchecker instance, unload will dispose dictionary as well as clear currently selected spellchecker instance. Otherwise it'll simply dispose dictionary from provider.
To get suggested text for misspelled text use getSuggestion
public getSuggestion(text: string): Readonly<Array<string>>It'll ask currently selected spellchecker to get suggestion for misspelling.
Few other convenient interfaces are available as well.
//Returns array of key for currently loaded dictionaries
//in desecending order of how long it has been used.
public availableDictionaries: Readonly<Array<string>>;
//Returns key of currently selected dictionary.
public selectedDictionary: string | null;
//Writes bit more verbosed log. Setter only.
public verboseLog: boolean;Example provides simple code how to use SpellCheckerProvider in general. npm run browserwindow will executes example for general browserWindow, npm run browserview provides example for loading external page via browserView with preload scripts.
Building / Testing
Few npm scripts are supported for build / test code.
build: Transpiles code to ES5 commonjs todist.test: Run test cases.lint: Run lint over all codebaseslint:staged: Run lint only for staged changes. This'll be executed automatically with precommit hook.commit: Commit wizard to write commit message