spellcheck
v0.0.5
Published
An async hunspell binding for node.js
Downloads
21
Maintainers
Readme
Description
An async hunspell binding for node.js.
Requirements
- node.js -- v0.6.0 or newer
- Dictionary and affix files
Install
npm install spellcheck
Examples
- Check a word:
// this example uses the en_US hunspell files from SCOWL:
// http://wordlist.sourceforge.net/
var SpellCheck = require('spellcheck'),
base = __dirname + (process.platform === 'win32' ? '\\' : '/'),
spell = new SpellCheck(base + 'en_US.aff', base + 'en_US.dic');
spell.check('sain', function(err, correct, suggestions) {
if (err) throw err;
if (correct)
console.log('Word is spelled correctly!');
else
console.log('Word not recognized. Suggestions: ' + suggestions);
});
// output:
// Word not recognized. Suggestions: chain,sin,saint,satin,stain,slain,swain,rain,sail,lain,said,gain,main,spin,pain
API
Methods
(constructor)(<String>affixPath, <Integer>dictPath) - Creates and returns a new SpellCheck instance. affixPath is an absolute path that points to an affix (.aff) file. dictPath is an absolute path that points to a dictionary (.dic) file.
check(<String>word, <Function>callback) - (void) - Spell checks the given word. The callback receives three arguments: an <Error> object in case of error (null otherwise), a <Boolean> indicating if the word was spelled correctly, and if the word was not recognized, an <Array> of suggested words.