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

typo-js-ts

v2.0.4

Published

Typo.js is a JavaScript spellchecker that uses Hunspell-style dictionaries.

Downloads

3,531

Readme

Type.js

Typo.js is a JavaScript spellchecker that uses Hunspell-style dictionaries.

Typo.js is written in Typescript.

Node install

npm install --save typo-js-ts

Usage

Type implements a Ready pattern that returns a Promise.

var Typo = require('typo-js-ts').Typo;

var dict = new Typo("en_US");
dict.ready.then(()=>{
  // Promise that dictionary is loaded
  // do work
  let spellSuggest = dict.suggest("speling");
  console.log(spellSuggest);
  // output [ "spelling", "spieling", "spewing", "peeling", "selling" ]

  spellSuggest = dict.suggest("speling", 1);
  console.log(spellSuggest);
  // output: ["spelling"]
})
.catch((error) => {
  // dictionary was not loaded
  console.error(error);
});

or

var Typo = require('typo-js-ts').Typo;

new Typo("en_US")
  .ready.then(dictionary => {
    // Promise that dictionary is loaded
    // do worl
    // test if mispelled is the corect spelling for en_US
    console.log(dictionary.check("mispelled"));
  })
  .catch((error) => {
    // dictionary was not loaded
    console.error(error);
  });

or using callback

var Typo = require('typo-js-ts').Typo;

new Typo("en_US", null, null, {
  loadedCallback: function (err, dict) { 
    if (err) {
      console.error(err);
      return;
    }
    let spellSuggest = dict.suggest("spitting");
    console.log(spellSuggest);
    // Correctly spelled words receive no suggestions.
    // output [ ]

    spellSuggest = dict.suggest("speling", 1);
    console.log(dict.check("Alex")); // true
    console.log(dict.check("alex")); // false
  }
});

To use Typo.js in a Chrome extension, simply include the typo.js file in your extension's background page, and then initialize the dictionary like so:

var Typo = require('typo-js-ts').Typo;

var dictionary = await new Typo("en_US").ready;

By default Typo.js looks for dictionaries to be in typo/dictionaries path.

The dictionary path for us_US would contain the following:

  • en_US/en_US.aff
  • en_US/en_US.dic

The default paths for us_US would be as follows:

  • typo/dictionaries/en_US/en_US.aff
  • typo/dictionaries/en_US/en_US.dic

if your dictionaries are stored in a different path then this can be pass to Typo.js by way of the settings.

var Typo = require('typo-js-ts').Typo;

var dict = new Typo("en_US", null, null, {
  dictionaryPath: "hunspell/dictionaries"
});
dict.ready.then(() => {
  // Promise that dictionary is loaded
  // do work
  console.log(dict.check("1st")); // true
  console.log(dict.check("1th")); // false
});

If using in node.js, load it like so:

var Typo = require('typo-js-ts').Typo;

var dictionary = new Typo([...]);

Node as ES Module

import { Typo } from "typo-js-ts";

var dictionary = new Typo([...]);

To check if a word is spelled correctly, do this:

var is_spelled_correctly = dictionary.check("mispelled");

To get suggested corrections for a misspelled word, do this:

var array_of_suggestions = dictionary.suggest("mispeling");

// array_of_suggestions == ["misspelling", "dispelling", "misdealing", "misfiling", "misruling"]

Typo.js has full support for the following Hunspell affix flags:

  • PFX
  • SFX
  • REP
  • FLAG
  • COMPOUNDMIN
  • COMPOUNDRULE
  • ONLYINCOMPOUND
  • KEEPCASE
  • NOSUGGEST
  • NEEDAFFIX

Demo

Check out live demo of Typo.js.

Also try on RunKit + NPM

JS Directory

The JS Directory contains compiled JavaScript of this project. This files can be used directly in your web page to load Typo.js
See Js Readme for more information.

Compiling Source

Run grunt help in terminal to get a list of commands that are used to build this project.

Licensing

Typo.js is free software, licensed under the Modified BSD License.