npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

name-spell-checker

v0.0.4

Published

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

Downloads

6

Readme

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/[email protected]/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/nspell.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/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