项目作者: danakt

项目描述 :
Simple expandable tool for spell checking
高级语言: JavaScript
项目地址: git://github.com/danakt/spell-checker.js.git
创建时间: 2016-12-24T11:56:20Z
项目社区:https://github.com/danakt/spell-checker.js

开源协议:MIT License

下载


Spell-checker.js

Simple expandable tool for spell checking

npm
Travis branch

Readme: English Русский

Supported languages

  • English
  • Russian

Quickstart

Install:
npm i spell-checker-js

Code

  1. const spell = require('spell-checker-js')
  2. // Load dictionary
  3. spell.load('en')
  4. // Checking text
  5. const check = spell.check('Some text to check, blahblahblah, olololo')
  6. console.log(check)
  7. // -> ['blahblahblah', 'olololo']

Methods & properties

spell.load(dictionary) or spell.load(options) — load dictionary file

Examples:

  1. // ways for load default dictionary:
  2. spell.load('ru')
  3. spell.load({ input: 'ru' })
  4. // load custom dictionary with utf-8:
  5. spell.load('./my_custom_dictionary.txt')
  6. // laod custom dictionary with charset:
  7. spell.load({ input: './my_custom_dictionary.txt', charset: 'windows-1251' })
  8. // Asynchronous load default dictionary:
  9. spell.load({ input: 'en', async: true }).then(len => {
  10. console.log(len);
  11. // len — amount of added words to base
  12. spell.check('something')
  13. })

List of default dictionaries:

  • en — list of English words
  • ru — list of Russian words
  • ru_surnames — list of Russian surnames

You can help by adding other languages or expand existing dictionaries

spell.check(string) — spell checking of text

Returns: array of wrong words
Example:

  1. spell.load('en')
  2. const check = spell.check('Some text to check, blahblahblah, olololo')
  3. console.log(check)
  4. // -> ['blahblahblah', 'olololo']

spell.clear() — clear all loaded dictionaries

Example:

  1. spell.load('en')
  2. spell.clear()
  3. spell.check('something')
  4. // -> ERROR! Dictionaries are not loaded

spell.size — number of words in the dictionary are

Example

  1. spell.load('en')
  2. spell.load('ru')
  3. console.log(spell.size)
  4. // -> 1956898

License

MIT © 2016 Danakt Frost