Skip to content

An async hunspell binding for node.js

License

Notifications You must be signed in to change notification settings

mscdex/spellcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

An async hunspell binding for node.js.

Requirements

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.