cfinke / Typo.js

A client-side JavaScript spellchecker that uses Hunspell-style dictionaries.
Other
501 stars 110 forks source link

API for adding custom words #66

Open mikeb-celtx opened 6 years ago

mikeb-celtx commented 6 years ago

It would be much appreciated if there were a way to add new custom words to the working dictionary. Right now I'm reloading the whole thing, though I saw on another PR that there is a hackaround to add single words using internal members. It seems like this is an obvious candidate for API extension.

dportuesi commented 3 years ago

What is the PR where it shows the hackaround? Currently trying to get adding single custom words to work in typo js, thanks.

cfinke commented 2 years ago

When adding a new word, would you expect to ever be specifying flags for the word, or would it always be just "learn this exact word"?

FWIW, without a proper API, the way to add a word to an existing Typo instance should be:

var newWord = "cromulent";

var typo = new Typo([...]);
...
typo.dictionaryTable[newWord] = null
whawker commented 2 years ago

The command line version of Hunspell only allows simple word lists in personal dictionary files. Perhaps that would be a good place to start, and possibly simpler with no need for flags?

Maybe there could be a public addPersonalDictionary method, that you pass a file name/file data to, and it calls _parseDIC under the hood?