0.0.4 โ€ข Published 6 months ago

fast-spell v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

fast-spell

A fast and lightweight spell checker library optimized for performance. This library provides efficient spell checking and suggestion capabilities with support for affix rules.

Features

  • โšก High-performance spell checking (1M+ operations/sec)
  • ๐Ÿ” Smart word suggestions
  • ๐Ÿ“š Support for affix rules (prefixes and suffixes)
  • ๐Ÿ’พ Efficient memory usage with Trie-based dictionary
  • ๐Ÿ”„ Intelligent caching system
  • ๐Ÿ“Š Thoroughly benchmarked

Installation

npm install fast-spell
# or
bun install fast-spell

Usage

import SpellChecker from "fast-spell";

// Initialize with dictionary and affix rules files
const spellChecker = new SpellChecker(
  "path/to/dictionary.dic",
  "path/to/rules.aff",
);

// Check if a word is spelled correctly
const isCorrect = spellChecker.check("hello"); // true
const isIncorrect = spellChecker.check("helllo"); // false

// Get spelling suggestions
const suggestions = spellChecker.suggest("helllo"); // ['hello', 'hell', ...]

Where to find Dictionaries and Affix Rules

The GitHub repository contains dictionaries and affix rules for various languages.

Download the files above (or your custom dictionaries and affix rules) and put them where you want. Then, you can pass the file paths to the SpellChecker constructor.

Performance

Based on our benchmark tests, fast-spell achieves impressive performance metrics:

  • Dictionary load time: ~130ms
  • Single word check: ~1ยตs
  • Cached operations: 1M+ ops/sec
  • Suggestion generation: ~630K ops/sec
  • Memory usage: ~75MB heap for typical dictionary

Detailed Benchmarks

OperationTime (Average)Operations/sec
Cached Word Check920ns1,086,031
Uncached Word Check1.07ยตs938,457
Correct Word Check960ns1,041,043
Incorrect Word Check832ns1,201,789
Affixed Word Check866ns1,153,526
Spell Suggestions1.10ยตs909,406

API Reference

SpellChecker

Constructor

constructor(dicPath?: string, affPath?: string)
  • dicPath: Path to the dictionary file (optional)
  • affPath: Path to the affix rules file (optional)

Methods

check(word: string): boolean

Checks if a word is spelled correctly.

suggest(word: string): string[]

Returns an array of spelling suggestions for a given word.

Development

# Install dependencies
bun install

# Run tests
bun test

# Build
bun run build

# Lint
bun run lint

License

MIT

Author

BestCodes

0.0.4

6 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

8 months ago

0.0.0

8 months ago