✓ name-spell-checker
✗ NameSpellChecker
✗ name-spell-checker.js
npm
# Install with peerDependencies nspell
npm install name-spell-checker nspell
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.6/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>
Create a new name spell checker.
If no dictionaries passed, NameSpellChecker.defaultDictionaries
will be used.
dictionaries
(Array<Dictionary>
) — List ofdictionary
objects. The first must have anaff
key, otheraff
keys are ignored
New instance of NameSpellChecker
.
Suggest names close to the given string.
nameSpellChecker.suggest("macha"); // => [ 'Mocha' ]
nameSpellChecker.suggest("chai"); // => [ 'Chai' ]
str
(string
) — string to suggest names for
Array<string>
— List with zero or more suggestions.
Check if the given string is correct name.
nameSpellChecker.correct("jquery"); // => false
nameSpellChecker.correct("jQuery"); // => true
str
(string
) — string to check for correct spelling
boolean
— Whether str
is correct name.
Add the given name to known names.
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' ]
name
(string
) — name to add
NameSpellChecker
— Operated on instance.
Remove the given name from known words.
nameSpellChecker.correct("Vue.js"); // => true
nameSpellChecker.remove("Vue.js");
nameSpellChecker.correct("Vue.js"); // => false
name
(string
) — name to remove
NameSpellChecker
— Operated on instance.
Add an extra dictionary to the NameSpellChecker.
nameSpellChecker.dictionary(
[
"5",
"name-spell-checker",
"my-lib-foo",
"jQuery.bar.js",
"a.js",
"b.lib.js",
].join("\n")
);
dic
(string
) — Dictionary document to use
NameSpellChecker
— Operated on instance.
Add a personal dictionary.
nameSpellChecker.personal(["foo", "*baz"].join("\n"));
dic
(string
) — Personal dictionary document to use
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.
NameSpellChecker
— Operated on instance.
An object of default dictionaries.
Dictionaries:
- frontEnd
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 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.
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.
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.
- Fix bug add declaration file #1