symspell-ts
v0.0.2
Published
TypeScript port of SymSpell — symmetric delete spelling correction algorithm
Maintainers
Readme
symspell-ts
TypeScript port of SymSpell v6.7.3 by Wolf Garbe.
This is a vibe-coded port using moarcode. You should assume it'll blow up your computer and is not fit for any purpose whatsoever.
Features
- Lookup — single-word spelling correction (Top, Closest, All verbosity modes)
- LookupCompound — multi-word compound-aware correction (handles split/merged words)
- WordSegmentation — insert missing spaces into concatenated text, with simultaneous spelling correction
Usage
The package bundles English frequency dictionaries (82,765 words + 243,342 bigrams). Load them with a single call:
import { SymSpell, Verbosity, loadDefaultDictionaries } from "symspell-ts";
const symSpell = new SymSpell();
loadDefaultDictionaries(symSpell);
// Single-word correction
const suggestions = symSpell.lookup("helo", Verbosity.Top, 2);
console.log(suggestions[0].term); // "hello"
// Word segmentation
const result = symSpell.wordSegmentation("thequickbrownfox");
console.log(result.correctedString); // "the quick brown fox"
// Compound correction
const compound = symSpell.lookupCompound("whereis th");
console.log(compound[0].term); // "where is the"Custom Dictionaries
You can load your own frequency dictionaries instead of (or in addition to) the bundled ones. Dictionary files should have one entry per line in the format word count, separated by a space.
import { SymSpell, Verbosity } from "symspell-ts";
import { readFileSync } from "node:fs";
const symSpell = new SymSpell(83000, 2, 7);
// Load a unigram frequency dictionary
const dict = readFileSync("my_dictionary.txt", "utf-8");
symSpell.loadDictionary(dict, 0, 1);
// Optionally load a bigram dictionary (needed for lookupCompound)
const bigrams = readFileSync("my_bigrams.txt", "utf-8");
symSpell.loadBigramDictionary(bigrams, 0, 2);Frequency dictionaries for multiple languages are available at SymSpell/SymSpell.FrequencyDictionary.
API
new SymSpell(initialCapacity?, maxDictionaryEditDistance?, prefixLength?, countThreshold?, compactLevel?)
loadDefaultDictionaries(symSpell): void
symSpell.loadDictionary(corpus, termIndex, countIndex, separator?): boolean
symSpell.loadBigramDictionary(corpus, termIndex, countIndex, separator?): boolean
symSpell.lookup(input, verbosity, maxEditDistance?, includeUnknown?): SuggestItem[]
symSpell.lookupCompound(input, editDistanceMax?): SuggestItem[]
symSpell.wordSegmentation(input, maxEditDistance?, maxSegmentationWordLength?): WordSegmentationResult
License
MIT — original SymSpell algorithm and C# implementation by Wolf Garbe. SoftWx.Match edit distance algorithms by Steve Hatchett.
