Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dictionary table building logic from typo.js #64

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[{src,scripts}/**.{ts,json,js}]
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
build/
43 changes: 15 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
Typo.js is a JavaScript spellchecker that uses Hunspell-style dictionaries.
Typo.js is a Typescript port of [Typo.js spellchecker](https://github.com/cfinke/Typo.js)

Usage
=====
# Usage

To use Typo in a Chrome extension, simply include the typo.js file in your extension's background page, and then initialize the dictionary like so:
This is designed to be used within a web application and I removed the original dictionary table building.
For Typo to work it needs the dictionary data already parsed and supplied to the constructor instead of the language string or .aff/.dic files, including:

```javascript
var dictionary = new Typo("en_US");
```

To use Typo in a standard web application you need to pass a settings object that provides a path to the folder containing the desired dictionary.

```javascript
var dictionary = new Typo("en_US", false, false, { dictionaryPath: "typo/dictionaries" }),
```

If using in node.js, load it like so:
The dictionaryTable including all words and rule sets
The compoundRules RegExp array
The replacementTable array pairs
The Hunspell affix flags object

```javascript
var Typo = require("typo-js");
var dictionary = new Typo([...]);
const Typo = require("typo-js");
const dictionary = new Typo(...);
```

To check if a word is spelled correctly, do this:

```javascript
var is_spelled_correctly = dictionary.check("mispelled");
const is_spelled_correctly = dictionary.check("mispelled");
```

To get suggested corrections for a misspelled word, do this:

```javascript
var array_of_suggestions = dictionary.suggest("mispeling");
const array_of_suggestions = dictionary.suggest("mispeling");

// array_of_suggestions == ["misspelling", "dispelling", "misdealing", "misfiling", "misruling"]
```
Expand All @@ -49,13 +43,6 @@ Typo.js has full support for the following Hunspell affix flags:
* NOSUGGEST
* NEEDAFFIX

_Note: The manifest.json file in the root directory of the project is there to simplify testing, as it allows you to load all of the files in the Typo project as a Chrome extension. It doesn't have any purpose if you're using Typo.js in your own project._

Demo
====
There's a live demo of Typo.js at http://www.chrisfinke.com/files/typo-demo/ and a complete Node.js example file at examples/node/index.js.

Licensing
=========
# Licensing

Typo.js is free software, licensed under the Modified BSD License.
Typo.js is free software, licensed under the Modified BSD License.