JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 161
  • Score
    100M100P100Q66707F
  • License MIT

Check your text for grammar and spelling error using multiple providers

Package Exports

  • spech

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (spech) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

spech

Build Status NPM version

Check your text for grammar and spelling mistakes using multiple providers

  • Zero config
  • Multiple libraries/services support

Usage

Files checking

npx spech

By default, it finds **/*.md files and checks it using en-US language.

Use -l flag to specify another language:

spech -l ru

To specify file mask directly, pass it as an argument:

spech README.md 'docs/*.md'

String checking

You can check a string value using STDIN or --input argument

cat README.md | spech

spech --input 'Check the text'

Providers

Hunspell

Hunspell is the most popular open-source spell checker which supports a great variety of languages.

Read more.

GrammarBot

Free grammar checking API. With an API key, you can receive 250 requests/day (7500/mo) at no cost. Without an API key, requests are limited to 100 per day per IP address (3000/mo). The API supports only English (en-US and en-GB).

Read more.

Yandex Speller

Free and very fast spell checker API for en, ru and uk languages. It provides free 10k requests/day or 10m characters/day.

Read more.

Configuring

You can store configuration in two places:

  • spech.config.js
  • "spech" section of the package.json

spech.config.js

module.exports = {
  languages: ['en-us'],
  providers: [
    { name: 'hunspell' },
    { name: 'grammarBot', apiKey: 'YOUR_API_KEY' },
  ],
};

More details.

Dictionaries

You can place words/phrases which are marked as a mistake into your dictionary file. Just create a file with .dic extension in your project root:

mydictionary.dic

# Simple word
browserify
# Regexp
/Component.tsx?/

More details.

API Usage

The most useful parts of the library are available through facade class SpellChecker.

Here is a simple example how it can be used:

const { Config, SpellChecker } = require('spech');

async function getMistakes() {
  const config = new Config({ ignoreCase: false });
  const checker = new SpellChecker(config);

  await checker.addDocumentsByMask(process.cwd(), 'docs/*.md');
  checker.addDictionaryPhrase('exceptionphrase');
  checker.addProviderByConfig({ name: 'hunspell' });

  const noMistakes = await checker.checkDocuments();
  if (noMistakes) {
    return [];
  }
  
  const corrections = checker.documents.map(doc => doc.corrections).flat();
  return corrections.map(correction => correction.fragment);
}