Skip to content

Commit

Permalink
Merge pull request #47 from kwonoj/chore-update
Browse files Browse the repository at this point in the history
docs(readme): update description
  • Loading branch information
kwonoj authored Jul 28, 2017
2 parents e0e421f + 62ca1d8 commit 719114d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<a name="0.0.2"></a>
## [0.0.2](https://github.com/kwonoj/hunspell-asm/compare/v0.0.1...v0.0.2) (2017-07-28)



<a name="0.0.1"></a>
## 0.0.1 (2017-07-28)

Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# Hunspall-asm

`Hunspell-asm` is isomorphic javascript binding to [hunspell](https://github.com/hunspell/hunspell) spellchecker based on WebAssembly hunspell binary. This module aims to provide thin, lightweight interface to hunspell without requiring native modules.

# Install

```sh
Expand All @@ -13,6 +15,49 @@ npm install hunspall-asm

# Usage

## Loading module asynchronously

`Hunspell-asm` requires to wasm binary (or asm.js where wasm is not supported) of hunspell, need to initialize module first.

```js
import { loadModule } from 'hunspell-asm';

const hunspellFactory = await loadModule();
```

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

```js
loadModule(binaryEndpoint?: string): Promise<HunspellFactory>
```

It accepts `binaryEndpoint` as optional parameter for mainly browser environment. Unlike node, browser can't access wasm / asm binary directly in filesystem but have to `fetch`. Provide endpoints for paths to `dist/src/lib/**/*.(wasm|mem)` and it'll be fetched runtime. On node, this endpoint can be used to override physical path to binaries.

## 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 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 `virtual` path 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.

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.

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

`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](https://github.com/kwonoj/hunspell-asm/tree/e0e421fda667fb0d4888a4e0b21877e95540c29c/examples) for each environments using different apis. In each example directory do `npm install && npm start`.

# Building / Testing

Expand Down
2 changes: 1 addition & 1 deletion examples/runHunspell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//tslint:disable:no-console
import { HunspellFactory } from '../src/Hunspell';
import { HunspellFactory } from '../src/HunspellFactory';
const misSpelledWord = '들어오세';
const correctWord = '들어오세요';

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hunspell-asm",
"version": "0.0.1",
"description": "",
"version": "0.0.2",
"description": "WebAssembly based Javascript bindings for hunspell spellchecker",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"config": {
Expand Down Expand Up @@ -32,7 +32,7 @@
]
},
"scripts": {
"prepublish": "npm-run-all build test",
"prepublishOnly": "npm-run-all build test",
"precommit": "lint-staged",
"prepush": "npm-run-all build test",
"commitmsg": "validate-commit-msg",
Expand Down

0 comments on commit 719114d

Please sign in to comment.