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

star-correct

v1.0.7

Published

A small javascript library to automatically correct typos in messages based on the next message.

Downloads

14

Readme

npm version travis cli downloads Join the chat at https://gitter.im/Decagon/star.js

star.js

star-correct does automatic typo correction in the browser, based on the next message.

starjs.correct(['Fixing typos awsf never asier', 'easier* was*'])
// 'Fixing typos was never easier'

A small javascript npm library to automatically correct typos in messages based on the next message, and it works out of the box--no dependencies.

Examples

var starjs = require('star-correct');

starjs.correct(['I would like to to that today sometime', 'to do']);
// 'I would like to do that today sometime'

Not all messages are corrections. Star.js knows when something isn't a correction, even though it is passed in as a correction.

var starjs = require('star-correct');

starjs.correct(['I like apples', 'I like oranges, pecans, and strawberries, too.']);
// false (no correction needed)

Star.js is meant to replace manual spell checkers, or drop down menus that let you choose a different word. Spell checkers are very good if you have the time, but if you only have one correction to make, they're a bit overkill, especially when you have to use the mouse. All of these examples follow the same syntax as the previous boilerplate example.

Examples for Star.js 2.0 (in development)

starjs.correct(['I like apples', 'I like oranges, pecans, and strawberries, too.']);
// false (no correction needed)

starjs.correct(['She wanted to go to the movies', 'he*']);
// 'He wanted to go to the movies'

starjs.correct(['He went to the concert yesterday', 'a few days ago* was going to go*']);
// 'He was going to go to the concert a few days ago'

starjs.correct(['He go to store tomorrow', 'will*']);
// 'He will go to the store tomorrow'

starjs.correct(['Turn left on Main Street, then take a right on 123 Sesame Street', 'turn right*']);
// 'Turn right on Main Street, then take a right on 123 Sesame Street

starjs.correct(['I have 10 apples and one bananas', '2*']);
// 'I have 10 apples and two bananas'

starjs.correct(['The ayoxk bepwn dpx kimped ovwe the laxy soh', 'quick**']);
// 'The quick bepwn dpx kimped ovwe the laxy soh'

Why Star.js is a bit different than a spell checker

Star doesn't try to correct every single word; it knows the correct spelling of the word that you meant to type, and compares it against the words that you did type. Here's a comparison of a general spell checker against Star:

Super-bad-misspelled-sentence: The ayoxk bepwn dpx kimped ovwe the laxy soh

Correction I want to make: quick*

Star.js: ayoxk -> quick (correctly identifies misspelled word)

Conventional spell checker suggestions: aux, askoa, Axons, ataxic... (and no suggestion for "quick"!)

This is because spell checkers put heavy emphasis on the first letter of the word being correct, which is not always the case. They also use prouncination cues to determine whether a word is spelled correctly.

Star.js doesn't use prouncination, and it doesn't focus tonnes on the first letter: it looks at keys that are close to the letter that you may be trying to type--and a few other things--to determine whether the correction should correct that word. Each misspelled word is given a ranking on how likely it could have been created by looking at the keys which are closer to each letter on the keyboard, along with calculating a modified version of the levenshtein distance, and the highest ranking word is automatically corrected, if it is not a perfect match.

Demo

A demo is available at https://decagon.github.io/star.js/ (thanks to @njt1982 for getting the demo working nicely)

Issues

  • punctuation is not preserved if there is more than one punctuation symbol after the word that needs to be replaced
  • capitalization is only preserved for the first letter, the rest is ignored
  • whitespace is not preserved, but just added (and never subtracted)
  • there are, of course a few false positives where star.js can make the new message non-sensical

Configuring

Just install node with apt-get install node, create a new project with npm init and just include star.js via var starjs = require('star-correct'); and you're good to go! See the examples section to see how to get started.

Browser

I have only tested Star.js in Google Chrome, but it should work with all modern browsers, except possibly IE, since it uses a string function which is not built-in to IE.

Thanks

  • @adamisntdead, for helping publish Star.js to NPM, and making the readme file more readable and attractive
  • Stack Overflow (credit in comments) for the levenshtein distance algorthim