Skip to content
Automatic typo correction in the browser, based on the next message.
JavaScript HTML
Branch: master
Clone or download
Decagon
Latest commit d9c3a9f Dec 30, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.clang-format Use Google clang format Jul 22, 2016
.gitignore Add node .gitignore Jul 22, 2016
.travis.yml
CHANGELOG.md Release v1.0.7 Jul 19, 2016
LICENSE Create LICENSE again, after it disappeared Jul 19, 2016
README.md Fix markdown syntax error Dec 30, 2017
index.html Fixed example code Jul 6, 2016
package.json Add chai test package Jul 22, 2016
star.js Add a few more mispressed keys for 'p' Dec 31, 2016
ubuntu_irc_starjs_corrections.csv Create ubuntu_irc_starjs_corrections.csv Jan 6, 2017

README.md

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'

gif of star js

(See Sozercan's slack-typobot on GitHub, powered by Star.js: https://github.com/sozercan/slack-typobot)

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.

Getting Started

If you're using Ubuntu/Debian, install node: apt-get install node

Create a new dir: mkdir my-project && cd my-project

Run npm init, then npm install star-correct, and just include star-correct via var starjs = require('star-correct'); in the first line of your javascript file, and you're good to go!

See the examples section to get started.

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.

Test cases 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' (pronoun recognition)

starjs.correct(['Sarah wanted to go to the movies', 'Jane*']);
// 'Jane wanted to go to the movies' (name detection)

starjs.correct(['She wet to the store', 'whent* went*']);
// 'She went to the store' (overwriting a correction)

starjs.correct(['Their owners\' were talking loudly', 'my* speaking*']);
// 'My owner was speaking loudly' (this test case may be too complex)

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' (duplicate corrections + time)

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

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 (direction)

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

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

starjs.correct(['He ygusy today is a day where', 'hey guys*']);
// 'Hey guys today is a day where' (accidental space)

starjs.correct(['And the study[1] shows that, in this case...', '[2]*']);
// 'And the study[2] shows that, in this case...' (replacing references)

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

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
You can’t perform that action at this time.