Home

Awesome

Build Status Build status codecov npm node

Hunspell-asm

Hunspell-asm is isomorphic javascript binding to hunspell spellchecker based on WebAssembly hunspell binary. This module aims to provide thin, lightweight interface to hunspell without requiring native modules.

Install

npm install hunspell-asm

Usage

Loading module asynchronously

Hunspell-asm relies on wasm binary of hunspell, which need to be initialized first.

import { loadModule } from 'hunspell-asm';

const hunspellFactory = await loadModule();

loadModule loads wasm binary, initialize it, and returns factory function to create instance of hunspell.

loadModule({ timeout?: number }): Promise<HunspellFactory>

It allows to specify timeout to wait until wasm binary compliation & load.

Mounting files

Wasm binary uses different memory spaces allocated for its own and cannot access plain javascript object / or files directly. HunspellFactory provides few interfaces to interop file contents into hunspell.

All of virtual paths for mounted filesystem uses unix separator regardless of platform.

Creating spellchecker

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.

create(affPath: string, dictPath: string): Hunspell

Hunspell exposes minimal interfaces to spellchecker.

There are simple examples for each environments using different apis. In each example directory do npm install && npm start.

Adding words to dictionary in runtime

Hunspell exposes few interfaces allow to add words, or dictionaries in existing dictionary in runtime. This is runtime behavior, so it doesn't persist over once instance is disposed.

Things to note

Building / Testing

Few npm scripts are supported for build / test code.

License