Registry / llm-agents / hunspell-spellchecker

hunspell-spellchecker

JSON →
library1.0.2jsnpmunverified

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-spellchecker
INSTALL
IMPORT
SIG · HUNSPELL-SPELLCHEC
H
hunspell-spellchecker
llm-agentsjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Spellchecker
const Spellchecker = require('hunspell-spellchecker');
import Spellchecker from 'hunspell-spellchecker';
This package is CommonJS-only, last published over 11 years ago. ESM imports are not natively supported and require a CommonJS wrapper or bundler configuration.
Spellchecker (instance)
const spellchecker = new Spellchecker();
const spellchecker = hunspell_spellchecker();
The library exports a constructor function, not a direct instance or a factory function. It must be instantiated with `new`.

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.

const fs = require('fs'); const path = require('path'); const Spellchecker = require('hunspell-spellchecker'); // Initialize a spellchecker instance const spellchecker = new Spellchecker(); // Example dictionary files (replace with actual paths) // For demonstration, these files must exist in your project root // or be accessible via `fs.readFileSync`. // You would typically download official Hunspell dictionaries (e.g., from LibreOffice). const affFilePath = path.join(__dirname, 'en_US.aff'); // Placeholder const dicFilePath = path.join(__dirname, 'en_US.dic'); // Placeholder // In a real application, ensure these files exist // For testing, you might create dummy files or skip this part. if (!fs.existsSync(affFilePath) || !fs.existsSync(dicFilePath)) { console.error('Error: Dictionary files (en_US.aff, en_US.dic) not found.'); console.error('Please download them or provide valid paths for parsing.'); console.error('For example, download from: https://extensions.libreoffice.org/extensions/english-dictionaries (rename .oxt to .zip)'); process.exit(1); } // Parse an hunspell dictionary that can be serialized as JSON const DICT = spellchecker.parse({ aff: fs.readFileSync(affFilePath), dic: fs.readFileSync(dicFilePath) }); // Load a serialized dictionary into the spellchecker spellchecker.use(DICT); // Check a word const wordToCheck = 'typo'; const isRight = spellchecker.check(wordToCheck); console.log(`Is '${wordToCheck}' spelled correctly? ${isRight}`); // Should be false const correctWord = 'hello'; const isCorrect = spellchecker.check(correctWord); console.log(`Is '${correctWord}' spelled correctly? ${isCorrect}`); // Should be true
Debug
Known issues
breakingThis package is abandoned and has not been updated in over 11 years. It is unlikely to receive security patches, bug fixes, or new features. Consider more actively maintained alternatives like `nspell` or `nuspell` for modern applications.
fix
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.
affects: <=1.0.2
gotchaThe example code relies on Node.js's `fs.readFileSync` for parsing dictionary files. This makes the parsing step inherently server-side. Direct use in a browser environment will fail unless dictionary files are pre-parsed into JSON and loaded, or `fs` is polyfilled/mocked.
fix
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.
affects: >=1.0.0
gotchaThe library is CommonJS-only and does not natively support ES Modules (ESM) `import` syntax. Attempting to use `import Spellchecker from 'hunspell-spellchecker'` in an ESM context will likely result in errors.
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ES Module (ESM) context without proper configuration or transpilation.
fix
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')`.
TypeError: fs.readFileSync is not a function
Trying to run the dictionary parsing example code directly in a browser environment.
fix
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.
Error: ENOENT: no such file or directory, open './en_EN.aff'
The specified Hunspell dictionary (`.aff` or `.dic`) file path is incorrect or the file does not exist at the given location.
fix
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.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
20
OpenAI (training)
1
Resources
hunspell-spellchecker — npm install hunspell-spellchecker · libregistry