npm install hunspell-asm
Loading module asynchronously
Hunspell-asm relies on wasm binary of hunspell, which need to be initialized first.
;const hunspellFactory = await ;
loadModule loads wasm binary, initialize it, and returns factory function to create instance of hunspell.
environment allow to set running environment and ignores internal runtime detection. This is mostly for Electron's renderer process where node.js and
fetch are available both, to selectively opt-in which way to use. It also accepts
timeout which can be used to pass a custom timeout to the loader. Default is 3000ms. It is important to note
loadModule doesn't interop incorrect option value matching, like try to load correct binary when supply endpoint to file path with set env to browser.
HunspellFactory provides few interfaces to interop physical file, or file contents into hunspell.
mountDirectory(dirPath: string): string: (node.js only) Mount physical path. Once directory is mounted hunspell can read all files under mounted path. Returns
virtualpath to mounted path.
mountBuffer(contents: ArrayBufferView, fileName?: string): string: Mount contents of file. Environment like browser which doesn't have access to filesystem can use this interface to create each file into memory.
unmount(mountedFilePath: string): Unmount path if it's exists in memory. If it's bufferFile created by
mountBuffer, unmount will remove those file object in wasm memory as well.
virtual paths for mounted filesystem uses unix separator regardless of platform.
Once you mounted dic / aff files you can create hunspell spellchecker instance via
HunspellFactory::create. Each path for files are mounted path and should not be actual path or server endpoint.
Hunspell exposes minimal interfaces to spellchecker.
spell(word: string): boolean: Check spelling for word. False for misspelled, True otherwise.
suggest(word: string): Array<string>: Get suggestion list for misspelled word. Empty if word is not misspelled or no suggestions.
dispose(): void: Destroy current instance of hunspell. It is important to note created instance of hunspell will not be destroyed automatically.
There are simple examples for each environments using different apis. In each example directory do
npm install && npm start.
Things to note
Building / Testing
Few npm scripts are supported for build / test code.
build: Transpiles code to ES5 commonjs to
hunspell-asmtest both. Does not require
buildbefore execute test.
test:hunspell: Run integration test for actual hunspell wasm binary, using hunspell's test case as-is.
test:hunspell-asm: Run unit test against
lint: Run lint over all codebases
lint:staged: Run lint only for staged changes. This'll be executed automatically with precommit hook.
commit: Commit wizard to write commit message