yaspeller

repository·master·Indexed 20 days ago

https://github.com/hcodes/yaspeller

A search tool for finding typos in text, files, and websites using the Yandex.Speller API. Version 10.0.1 supports a CLI, integration with build tools like Gulp and Grunt, and pre-commit hooks. It features customizable configuration via .yaspellerrc, support for multiple languages (en, ru, uk), custom dictionaries, and various report formats including console, HTML, JSON, and Markdown.

Tokens
7.4K
Snippets
26
Records
33
Agent score
70%

What's inside yaspeller

  1. Ignore specific text from checking

    master

    You can instruct yaspeller to skip certain parts of your code or text using special comment markers or HTML comments.

    Ignore a single line: Use // yaspeller ignore, /* yaspeller ignore */, or <!-- yaspeller ignore --> on the same line as the text.

    Ignore a block of text: Wrap the block with yaspeller ignore:start and yaspeller ignore:end.

    Example (JS):

    /* yaspeller ignore:start */
    const reUpper = /A-Z/;
    /* yaspeller ignore:end */

    Example (HTML):

    <!-- yaspeller ignore:start -->
    <span>A-Z</span>
    <!-- yaspeller ignore:end -->
  2. Exclude text from checking

    master

    You can instruct yaspeller to ignore specific lines or blocks of text using special comments.

    Ignore a single line: Use // yaspeller ignore, /* yaspeller ignore */, or <!-- yaspeller ignore -->.

    var re = /А-ЯЁ/; // yaspeller ignore
    var re = /А-ЯЁ/; /* yaspeller ignore */
    <span>А-ЯЁ</span> <!-- yaspeller ignore -->

    Ignore a block of text: Use yaspeller ignore:start and yaspeller ignore:end.

    /* yaspeller ignore:start */
    const reUpper = /А-ЯЁ/;
    const reLower = /а-яё/;
    /* yaspeller ignore:end */
    <!-- yaspeller ignore:start -->
    <span>А-ЯЁ</span>
    <div>а-яё</div>
    <!-- yaspeller ignore:end -->
    /* yaspeller ignore:start */
    const reUpper = /А-ЯЁ/;
    /* yaspeller ignore:end */
  3. Create a custom dictionary

    master

    Custom dictionaries are provided as JSON files. You can include plain words or regular expressions.

    • A word like someword1 matches both someword1 and Someword1.
    • A word like Someword2 matches exactly Someword2.
    • Regular expressions allow for complex matching patterns.

    Example my_dict.json:

    [
        "someword1",
        "Someword2",
        "unknown(W|w)ord[12]?"
    ]

    Usage: yaspeller --dictionary my_dict.json . To use multiple dictionaries: yaspeller --dictionary my_dict.json:my_dict2.json .

  4. Use yaspeller with pre-commit

    master

    To run yaspeller as a git hook, add the following to your .pre-commit-config.yaml:

    - repo: https://github.com/hcodes/yaspeller.git
      rev: '' # Use the sha / tag you want to point at
      hooks:
        - id: yaspeller
    - repo: https://github.com/hcodes/yaspeller.git
      rev: ''
      hooks:
        - id: yaspeller
  5. Use the yaspeller CLI

    master

    Run the CLI by passing files, directories, or URLs as arguments. You can also use standard input or glob patterns.

    Basic Usage: yaspeller [options] <file-or-directory-or-link...>

    Common Examples:

    • Search a specific file: yaspeller README.md
    • Search using glob syntax (Windows): yaspeller "*.md"
    • Search specific extensions in a folder: yaspeller -e ".md,.html,.txt" ./texts/
    • Search a website: yaspeller https://ru.wikipedia.org/wiki/Example
    • Search a sitemap: yaspeller http://bem.info/sitemap.xml
    • Process from STDIN: echo "Hello, world!" | yaspeller --stdin
    • Process from STDIN with a specific filename: echo "Hello, world!" | yaspeller --stdin --stdin-filename hello.txt
    yaspeller README.md
  6. Install yaspeller

    master

    You can install yaspeller globally via npm to use it as a CLI tool, or as a development dependency in your project.

    Global installation:

    npm install yaspeller -g

    Project installation:

    npm install yaspeller --save-dev
    npm install yaspeller -g
  7. Create an external report plugin

    master

    You can extend yaspeller by providing your own report module. An external report must be a module that exports an object satisfying the Report interface.

    Required Properties and Methods

    • name: A unique string identifier for the report.
    • At least one of the following lifecycle methods must be implemented:
      • onStart()
      • onResourceComplete(hasError, data, dictionary)
      • onComplete(buffer, stats, configPath)

    Report Interface Type Definition

    /**
     * @typedef Report
     * @type {Object}
     * @property {string} name
     * @property {Function?} onStart
     * @property {Function?} onResourceComplete
     * @property {Function?} onComplete
     */
  8. Configure yaspeller with a configuration file

    master

    Yaspeller can be configured using a JSON file located at the project root. Supported filenames include:

    • .yaspellerrc
    • .yaspellerrc.js
    • .yaspellerrc.json
    • .yaspeller.json
    • package.json (using the yaspeller field)

    Example .yaspeller.json:

    {
      "excludeFiles": [
        ".git",
        "node_modules"
      ],
      "lang": "en",
      "fileExtensions": [
        ".md",
        ".css"
      ],
      "dictionary": [
        "someword1"
      ],
      "ignoreUrls": true,
      "findRepeatWords": true
    }
  9. Configure yaspeller via JSON

    master

    You can configure yaspeller using a JSON file located in your project root. Supported filenames include:

    • .yaspellerrc
    • .yaspellerrc.js
    • .yaspellerrc.json
    • .yaspeller.json
    • The yaspeller field in package.json

    Configuration Schema:

    PropertyTypeDescription
    formatStringOutput format (see --format)
    langStringLanguages (e.g., en, ru, uk)
    excludeFilesArrayFiles/directories to exclude
    fileExtensionsArrayExtensions to check (e.g., [".md", ".txt"])
    dictionaryArrayCustom dictionary entries (strings or regex)
    reportArrayReport types (e.g., ["console", "html"])
    checkYoBooleanCheck correctness of the letter "ё" in Russian
    findRepeatWordsBooleanFind consecutive repeated words
    ignoreTagsArrayHTML tags to ignore (e.g., ["code", "script"])
    ignoreTextArrayRegex patterns to exclude text
    ignoreCapitalizationBooleanIgnore case mismatches
    ignoreDigitsBooleanSkip words containing digits
    ignoreUrlsBooleanSkip URLs, emails, and filenames
    maxRequestsNumberConcurrent requests to Yandex Speller API

    Example Configuration:

    {
      "excludeFiles": [
        ".git",
        "node_modules"
      ],
      "format": "html",
      "lang": "en",
      "fileExtensions": [".md", ".txt"],
      "report": ["console", "html"],
      "dictionary": [
        "someword1",
        "Some(w|W)ord"
      ],
      "ignoreTags": ["code", "script"],
      "ignoreUrls": true,
      "findRepeatWords": true,
      "maxRequests": 5
    }
    {
      "excludeFiles": [
        ".git",
        "yaspeller",
        "node_modules",
        "libs"
      ],
      "format": "html",
      "lang": "en",
      "fileExtensions": [
        ".md",
        ".txt"
      ],
      "report": ["console", "html"],
      "dictionary": [
        "someword1",
        "Some(w|W)ord"
      ],
      "ignoreTags": ["code", "script"],
      "ignoreText": [
        "<php\?[^]*?\?>"
      ],
      "ignoreUrls": true,
      "findRepeatWords": true,
      "maxRequests": 5
    }
  10. Initialize a new .yaspellerrc configuration file

    master

    Use the initialization action to create a default .yaspellerrc file in your current working directory. This file contains the defaultConfig required for yaspeller to operate. If a .yaspellerrc file already exists, the process will warn you and exit without overwriting your existing configuration.

    # Note: The specific CLI command to trigger cliActionInit is not explicitly defined in this file,
    # but it is used to generate the .yaspellerrc file.
  11. Integrate yaspeller with Grunt

    master

    To use yaspeller in a Grunt workflow, use grunt-shell to execute the CLI command.

    module.exports = function(grunt) {
        grunt.loadNpmTasks('grunt-shell'); // npm install grunt-shell --save-dev
        grunt.initConfig({
            shell: {
                yaspeller: {
                    options: {stderr: false},
                    command: './node_modules/.bin/yaspeller .'
                }
            }
        });
        grunt.registerTask('lint', ['shell:yaspeller']);
    };
    module.exports = function(grunt) {
        grunt.loadNpmTasks('grunt-shell');
        grunt.initConfig({
            shell: {
                yaspeller: {
                    options: {stderr: false},
                    command: './node_modules/.bin/yaspeller .'
                }
            }
        });
        grunt.registerTask('lint', ['shell:yaspeller']);
    };
  12. Integrate yaspeller with Gulp

    master

    To use yaspeller in a Gulp workflow, use gulp-run to execute the CLI binary.

    const gulp = require('gulp');
    const run = require('gulp-run'); // npm install gulp-run --save-dev
    
    gulp.task('yaspeller', function (cb) {
        run('./node_modules/.bin/yaspeller ./').exec()
            .on('error', function (err) {
                console.error(err.message);
                cb();
            })
            .on('finish', cb);
    });
    const gulp = require('gulp');
    const run = require('gulp-run');
    
    gulp.task('yaspeller', function (cb) {
        run('./node_modules/.bin/yaspeller ./').exec()
            .on('error', function (err) {
                console.error(err.message);
                cb();
            })
            .on('finish', cb);
    });