name-spell-checker v0.0.4
name-spell-checker
✓ name-spell-checker
✗ NameSpellChecker
✗ name-spell-checker.js
Installation
npm
# Install with peerDependencies nspell
npm install name-spell-checker nspellUsage
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")); // => trueCJS:
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")); // => trueCDN:
<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 ofdictionaryobjects. The first must have anaffkey, otheraffkeys 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"); // => trueParameters
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"); // => falseParameters
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-8Not 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
bazThe 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
*quxIn 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