npm.io
1.0.1 • Published 3d ago

spellcore-core

Licence
MIT
Version
1.0.1
Deps
1
Size
75 kB
Vulns
0
Weekly
0

spellcore-core

The core engine of the SpellCore library.

This package contains the high-performance spell checking engine and its primary interfaces. It implements strict SOLID principles, allowing every sub-system to be overridden.

Installation

npm install spellcore-core

Usage

You construct a spell checker by providing all necessary dependencies:

import { 
    createSpellChecker, 
    StateMachineTokenizer, 
    DefaultNormalizer, 
    DefaultIgnoreFilter, 
    SymSpellSuggestionEngine 
} from 'spellcore-core';

// ... (Provide your own IDictionary implementation or use spellcore-dictionaries)

const checker = createSpellChecker({
    tokenizer: new StateMachineTokenizer(),
    normalizer: new DefaultNormalizer(),
    dictionary: myDictionary,
    personalDictionary: myPersonalDictionary,
    suggestionEngine: new SymSpellSuggestionEngine(['word1', 'word2']),
    ignoreFilter: new DefaultIgnoreFilter()
}, { maxSuggestions: 3 });

const result = await checker.check("Some text here.");

Internal Components

  • StateMachineTokenizer: Rapidly tokenizes strings without allocating regex match arrays.
  • DefaultNormalizer: Normalizes unicode characters (NFD) and converts them to lowercase.
  • DefaultIgnoreFilter: Pre-configured to ignore URLs, emails, and standard punctuation.
  • SymSpellSuggestionEngine: A port of the famous SymSpell algorithm optimized for fast Javascript execution using shard maps to bypass v8 property limits.
  • LevenshteinSuggestionEngine: A standard fallback suggestion engine.
  • PhoneticSuggestionEngine: Suggests words based on phonetic similarity (Soundex).

Keywords