Native bindings to aspell spell checking library for Node.js.
Node.js v18+ are compatible with this version of node-aspell
npm install node-aspell
const spellChecker = require('node-aspell');
console.log(spellChecker.isMisspelled("pncils"));
console.log(spellChecker.getCorrectionsForMisspelling("pncils"));
Check if a word is misspelled.
word
- String word to check.
Returns true
if the word is misspelled, false
otherwise.
Check if a word is misspelled asynchronously.
word
- String word to check.
callback
- Function to call with result callback(err, misspelled)
Get the corrections for a misspelled word.
word
- String word to get corrections for.
Returns a non-null but possibly empty array of string corrections.
Get the corrections for a misspelled word asynchronously.
word
- String word to get corrections for.
callback
- Function to call with result
In addition to the above functions that are used on a default instance, a new instance of SpellChecker can be instantiated with the use of the new
operator. The same methods are available with the instance but the language/dictionary can be changed independently from the default instance. See the aspell options documentation for a full list of options: http://aspell.net/man-html/The-Options.html
const checker = new SpellChecker.Spellchecker({ lang: "es", encoding: "utf-8" });
const checker = new SpellChecker.Spellchecker({
'master': 'es.rws',
'dict-dir': '/var/lib/aspell',
'encoding': 'utf-8'
});
const checker = new SpellChecker.Spellchecker("en_US");
Sample Dockerfile for running unit tests:
FROM node:xx
RUN apt-get update && apt-get install -y aspell aspell-en aspell-es libaspell-dev
COPY . /module
WORKDIR /module
RUN npm install && npm run-script build
RUN npm test
These packages spawn a separate aspell process and parse the output: