hunspell-spellchecker is a lightweight JavaScript library designed to parse and utilize Hunspell dictionaries (typically `.aff` and `.dic` files) within a JavaScript environment. It facilitates the conversion of these dictionary files into a JSON format, which can then be efficiently loaded and used for spell-checking. The library supports both Node.js for server-side processing and, with careful pre-processing, browser environments. The current stable version is 1.0.2, last published over 11 years ago, indicating it is no longer actively maintained. Its primary differentiator is the ability to work directly with Hunspell dictionary formats, converting them to a more JavaScript-friendly JSON structure for use in applications requiring custom or offline spell-checking capabilities.
npm install hunspell-spellcheckerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the spellchecker, parse Hunspell dictionary files (.aff and .dic) from the filesystem, load the processed dictionary, and then check the spelling of a word. It assumes dictionary files are available locally.
Migrate to a contemporary spell-checking library such as `nspell` (JavaScript-based) or integrate with `Nuspell` (C++ with bindings) for more robust, actively maintained solutions.
For browser usage, pre-parse the `.aff` and `.dic` files into the JSON format using Node.js or a build step, then serve and load the JSON dictionary directly in the browser. Do not attempt to use `fs.readFileSync` client-side.
In Node.js ESM projects, use `const Spellchecker = require('hunspell-spellchecker');` if allowed, or configure your bundler (e.g., Webpack, Rollup) to correctly handle CommonJS modules. If strict ESM is required, consider alternative libraries.Ensure your project is configured for CommonJS, or if using ESM, adjust your build setup to handle CommonJS imports. For strict ESM, rewrite the import statement using `import * as Spellchecker from 'hunspell-spellchecker';` (though this package is CJS-first, this might still lead to issues) or use dynamic `import('hunspell-spellchecker')`.The `fs` module is a Node.js built-in. Dictionary parsing must occur on the server-side (Node.js) or as part of a build process. Only the resulting JSON dictionary should be loaded in the browser.
Verify the file paths provided to `fs.readFileSync()` are absolute or correctly relative to `process.cwd()` (Node.js) or `__dirname`. Ensure the dictionary files are present in the expected location.
No dependency data recorded yet.