What is typo-js?
The typo-js npm package is a JavaScript library for spell checking. It uses Hunspell dictionaries to provide spell checking functionalities, which makes it highly customizable and capable of supporting multiple languages.
What are typo-js's main functionalities?
Spell Checking
This feature allows you to check if a word is spelled correctly. In this example, the word 'example' is checked against the 'en_US' dictionary.
const Typo = require('typo-js');
const dictionary = new Typo('en_US');
const isCorrect = dictionary.check('example');
console.log(isCorrect); // true
Suggesting Corrections
This feature provides suggestions for misspelled words. In this example, the word 'exampel' is misspelled, and the dictionary suggests 'example', 'exemplar', and 'exemplary' as corrections.
const Typo = require('typo-js');
const dictionary = new Typo('en_US');
const suggestions = dictionary.suggest('exampel');
console.log(suggestions); // ['example', 'exemplar', 'exemplary']
Loading Custom Dictionaries
This feature allows you to load custom dictionaries from a specified path. In this example, the 'en_US' dictionary is loaded from a custom path.
const Typo = require('typo-js');
const dictionary = new Typo('en_US', false, false, { dictionaryPath: '/path/to/dictionaries' });
const isCorrect = dictionary.check('example');
console.log(isCorrect); // true
Other packages similar to typo-js
spellchecker
The spellchecker package provides similar spell checking functionalities but is more focused on integration with native spell checking libraries on different operating systems. It is less customizable compared to typo-js but can be easier to set up for basic spell checking needs.
nodehun
Nodehun is another package that uses Hunspell dictionaries for spell checking. It offers similar functionalities to typo-js but is written in C++ for better performance. It can be more complex to set up due to its native dependencies.
nspell
Nspell is a spell checker that also uses Hunspell dictionaries. It is written in JavaScript and offers a good balance between performance and ease of use. It provides similar functionalities to typo-js but with a different API design.
Typo.js is a JavaScript spellchecker that uses Hunspell-style dictionaries.
Usage
To use Typo, simply load it like so:
var Typo = require("typo-js");
var dictionary = new Typo(lang_code);
Typo includes by default a dictionary for the en_US
lang_code.
To check if a word is spelled correctly, do this:
var is_spelled_correctly = dictionary.check("mispelled");
To get suggested corrections for a misspelled word, do this:
var array_of_suggestions = dictionary.suggest("mispeling");
Typo.js has full support for the following Hunspell affix flags:
- PFX
- SFX
- REP
- FLAG
- COMPOUNDMIN
- COMPOUNDRULE
- ONLYINCOMPOUND
- KEEPCASE
- NOSUGGEST
- NEEDAFFIX
Licensing
Typo.js is free software, licensed under the Modified BSD License.