name-spell-checker
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

jsdelivr npm version test CI codecov

name-spell-checker

✓ name-spell-checker
✗ NameSpellChecker
✗ name-spell-checker.js

Installation

npm

# Install with peerDependencies nspell
npm install name-spell-checker nspell

Usage

ESM:

import NameSpellChecker from "name-spell-checker";

const nameSpellChecker = new NameSpellChecker();

console.log(nameSpellChecker.correct("vue")); // => false
console.log(nameSpellChecker.suggest("vue")); // => [ 'Vuex', 'Vue.js', 'vue-cli', 'Vue.js devtools' ]
console.log(nameSpellChecker.correct("React")); // => true
console.log(nameSpellChecker.correct("angular")); // => false

nameSpellChecker.add("name-spell-checker");

console.log(nameSpellChecker.suggest("NameSpellChecker")); // => [ 'name-spell-checker' ]
console.log(nameSpellChecker.correct("name-spell-checker")); // => true

CJS:

const NameSpellChecker = require("name-spell-checker");

const nameSpellChecker = new NameSpellChecker();

console.log(nameSpellChecker.correct("vue")); // => false
console.log(nameSpellChecker.suggest("vue")); // => [ 'Vuex', 'Vue.js', 'vue-cli', 'Vue.js devtools' ]
console.log(nameSpellChecker.correct("React")); // => true
console.log(nameSpellChecker.correct("angular")); // => false

nameSpellChecker.add("name-spell-checker");

console.log(nameSpellChecker.suggest("NameSpellChecker")); // => [ 'name-spell-checker' ]
console.log(nameSpellChecker.correct("name-spell-checker")); // => true

CDN:

<script src="https://cdn.jsdelivr.net/npm/name-dic@0.0.5/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/name-spell-checker@0.0.4/dist/nspell.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/name-spell-checker@0.0.4/dist/index.min.js"></script>
<script>
  const nameSpellChecker = new NameSpellChecker();

  console.log(nameSpellChecker.correct("vue")); // => false
  console.log(nameSpellChecker.suggest("vue")); // => [ 'Vuex', 'Vue.js', 'vue-cli', 'Vue.js devtools' ]
  console.log(nameSpellChecker.correct("React")); // => true
  console.log(nameSpellChecker.correct("angular")); // => false

  nameSpellChecker.add("name-spell-checker");

  console.log(nameSpellChecker.suggest("NameSpellChecker")); // => [ 'name-spell-checker' ]
  console.log(nameSpellChecker.correct("name-spell-checker")); // => true
</script>

API

NameSpellChecker(dictionaries)

Create a new name spell checker.

If no dictionaries passed, NameSpellChecker.defaultDictionaries will be used.

Parameters

  • dictionaries (Array<Dictionary>) — List of dictionary objects. The first must have an aff key, other aff keys are ignored

Returns

New instance of NameSpellChecker.

NameSpellChecker#suggest(str)

Suggest names close to the given string.

Example

nameSpellChecker.suggest("macha"); // => [ 'Mocha' ]
nameSpellChecker.suggest("chai"); // => [ 'Chai' ]

Parameters

  • str (string) — string to suggest names for

Returns

Array<string> — List with zero or more suggestions.

NameSpellChecker#correct(str)

Check if the given string is correct name.

Example

nameSpellChecker.correct("jquery"); // => false
nameSpellChecker.correct("jQuery"); // => true

Parameters

  • str (string) — string to check for correct spelling

Returns

boolean — Whether str is correct name.

NameSpellChecker#add(name)

Add the given name to known names.

Example

nameSpellChecker.correct("name-spell-checker"); // => false
nameSpellChecker.suggest("name-spell-checker"); // => []

nameSpellChecker.add("name-spell-checker");

nameSpellChecker.correct("name-spell-checker"); // => true
nameSpellChecker.suggest("NameSpellCheck"); // => [ 'name-spell-checker' ]

Parameters

  • name (string) — name to add

Returns

NameSpellChecker — Operated on instance.

NameSpellChecker#remove(word)

NSpell#remove(name)

Remove the given name from known words.

Example

nameSpellChecker.correct("Vue.js"); // => true

nameSpellChecker.remove("Vue.js");

nameSpellChecker.correct("Vue.js"); // => false

Parameters

  • name (string) — name to remove

Returns

NameSpellChecker — Operated on instance.

NameSpellChecker#dictionary(dic)

Add an extra dictionary to the NameSpellChecker.

Example

nameSpellChecker.dictionary(
  [
    "5",
    "name-spell-checker",
    "my-lib-foo",
    "jQuery.bar.js",
    "a.js",
    "b.lib.js",
  ].join("\n")
);

Parameters

  • dic (string) — Dictionary document to use

Returns

NameSpellChecker — Operated on instance.

NameSpellChecker#personal(dic)

Add a personal dictionary.

Example

nameSpellChecker.personal(["foo", "*baz"].join("\n"));

Parameters

  • dic (string) — Personal dictionary document to use

Note

Lines starting with a * mark a word as forbidden, which results in them being seen as incorrect, and prevents them from showing up in suggestions.

Returns

NameSpellChecker — Operated on instance.

NameSpellChecker.defaultDictionaries

An object of default dictionaries.

Dictionaries:

  • frontEnd

Dictionaries

name-spell-checker only supports small parts of Hunspell-style dictionaries. Essentially, the concept of a dictionary consists of one “affix” document, and one or more “dictionary” documents.

See hunspell(5) for more information.

Affix documents

Affix documents define the language, keyboard, flags, and much more. The default affix document, only have one line, looks as follows:

SET UTF-8

Not every option is supported in name-spell-checker. We just pass it to nspell.

Dictionary documents

name-spell-checker does not support flags applying to those words. Because it rarely used for check name.

Dictionary documents contain words. For example:

3
foo
bar
baz

The above document contains three words, as the count on the first line shows. Further lines each start with a word.

Personal dictionary documents

name-spell-checker does not support flags applying to those words. Because it rarely used for check name.

Personal dictionaries are not intertwined with affix document. They define new words and words to forbid. For example:

foo
*qux

In the above example, foo is added as a known word and qux is marked as a forbidden word.

Release Notes

[TODO]

[Unreleased]

v0.0.3

  • Fix bug add declaration file #1

Readme

Keywords

none

Package Sidebar

Install

npm i name-spell-checker

Weekly Downloads

1

Version

0.0.4

License

MIT

Unpacked Size

74.8 kB

Total Files

47

Last publish

Collaborators

  • zjffun