• Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Automatic typo correction in the browser, based on the next message.

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

More Repositories

1

Pedant

Find and fix bothersome punctuation and formatting errors in English texts.
JavaScript
79
star
2

hofs-churn

A small bash script to approximate code churn for a Git repo as described by Brikman's article https://www.ybrikman.com/writing/2018/08/12/the-10-to-1-rule-of-writing-and-programming/
Shell
75
star
3

youtube-subscriptions-exporter

Export your YouTube channel subscriptions with links and channel URLs
JavaScript
29
star
4

wick

Browse and interact with the internet like your filesystem
Python
25
star
5

ssd-protect

Get notified when an app writes an excessive amount of data to your SSD
Python
21
star
6

archiveorg_link_restorer

Change all links on blog posts and news articles links' to their archive.org snapshot on the date of publication
JavaScript
12
star
7

butter-fingers

A python library to generate highly realistic typos (fuzz-testing)
Python
11
star
8

Rabbit

Rabbit is a C# library that intelligently uses the right PlayerIO authentication for your users
C#
8
star
9

can-you-hear-me

An app to "predict" hearing loss by measuring the normalized output sound volume everyday
Shell
7
star
10

asciinema-tools

An application to trim, annotate, and edit asciinemi casts after recording
Python
7
star
11

youtube-backup

Brutally simple YouTube channel cloud backup
Shell
6
star
12

installed-to-chocolatey

Convert your locally installed software into Chocolatey packages
Python
6
star
13

TrialMinder

Automatically detects when you sign up for a free trial; get reminded before you are billed
JavaScript
6
star
14

clapperboard

Automatically fix audio sync for your videos; no clapperboard required
Python
5
star
15

banana-for-scale

Places a correctly-sized reference image against a product on Amazon or eBay to show the relative size
JavaScript
5
star
16

populated-ports

Warns if two applications are using the same port (e.g. Docker and Visual Studio Code)
C#
3
star
17

bashreqs

pipreqs but for bash scripts. Not affiliated with pipreqs.
Python
3
star
18

auto-sun-brightness

Get a normalized numeric representation of how bright the sun is at any point in the day, anywhere
Python
3
star
19

docker-non-forwarded-ports

Alerts you if you map a port on your Docker container to a service which is not running inside of your container
C#
3
star
20

brightspace2excel

Downloads your Brightspace grades to an Excel spreadsheet
JavaScript
3
star
21

fb-export-to-slack

Export your Facebook Messenger data, and import the messages into Slack
Python
2
star
22

hn-sonar

Automatically be notified if someone replies to your comment on Hacker News. Self-hosted. No email required.
Python
2
star
23

muto

Convert Google Slides and PowerPoint presentations into GIFs
Python
2
star
24

Penguin

Penguin, send Everybody Edits commands in plain English
C#
2
star
25

wave

Set your desktop picture to a new unsplash.com photo everyday. No dependencies.
Python
2
star
26

CamelCamelCamelToExcel

Convert camelcamelcamel historical prices to an Excel spreadsheet
C#
1
star
27

all-npm-package-names

Easily download all npm's package names.
1
star
28

chars

Generate a random string that is N characters long
Shell
1
star
29

alexyorke.github.io

My blog
HTML
1
star
30

oss_rss

An RSS feed of OSS torrent and magnet links for seeding
HTML
1
star
31

BencodeSharp

A tap-water flavored non-recursive Bencode reader and writer written in C#
C#
1
star
32

depcheck-safe

Like depcheck but only removes unused dependencies if they don't break the build and tests
Batchfile
1
star
33

Spider

An EE bot that records information about players and rooms.
C#
1
star
34

Squirrel

C# app to convert Everybody Edits minimaps to png files, under 1ms.
C#
1
star
35

dal-to-cal

Generate an iCal-compatible file (events with alarms) for your Dalhousie classes automatically. Not affiliated with Dalhousie.
Python
1
star