New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

linspell

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linspell

LinSpell spelling correction algorithm TypeScript implementation

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

Overview

No dependency TypeScript implementation of Linspell spell checking algorithm optimised for performance and low memory footprint

Installation

yarn install linspell

or

npm install linspell

API

LinSpell

Creates an instance of LinSpell class

  • input
    • words?: string[] (default: [])
    • maxEditDistance?: number (default: 2)
    • suggestionType?: SuggestionType (default: 'in-max-distance')
  • output
    • LinSpell instance

Note: words array is expected to be sorted as search for exact match is done using binary search algorithm

Example

import { LinSpell } from 'linspell';

const defaultChecker = new LinSpell();
const customChecker = new LinSpell({
  words: ['elo', 'hello', 'hell', 'help'].sort(),
  maxEditDistance: 3,
  suggestionType: 'top',
});

LinSpell#provideWords

Overrides instance's dictionary with provided array of words; array is expected to be sorted

  • input
    • words: string[]
  • output: none

Example

import { LinSpell } from 'linspell';

const words = ['elo', 'hello', 'hell', 'help'].sort();
const checker = new LinSpell();
checker.provideWords(words);

LinSpell#lookup

Provides match results for given word in instance's dictionary

  • input
    • word: string
    • maxEditDistance?: number (default: instance's maxEditDistance)
    • suggestionType?: SuggestionType (default: instance's suggestionType)
  • output
    • found: boolean; signifies whether an exact match was found
    • suggestions: string[]; suggestions sorted from best to worst match

Example

import { LinSpell } from 'linspell';

const words = ['elo', 'hello', 'hell', 'help'].sort();
const checker = new LinSpell();
checker.provideWords(['bar', 'foo']);
console.log(checker.lookup('foo')); // [true, ['foo']]

SuggestionType

  • 'top' - returns only the best match; best performance
  • 'smallest-distance' - returns all matches with the lowest distance found; medium performance
  • 'in-max-distance' - returns all matches with distance lower than maxEditDistance; worst performance

FAQs

Package last updated on 23 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts