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

spelling-variations

v1.0.6

Published

gives you a word's spelling variations with detection whether it's a UK (English, british) or US (American) variations, also gives you the preferred variation.

Downloads

265

Readme

Spelling Variations

A library to give you spelling variations for a specific word with detection whether it's a UK variation or US variations. Also can be used to change word's UK spelling variation to the US one.

Getting started

You can either download the minified version (from the dist directory) and use it in your browser, or you can install the library via NPM:

npm install --save spelling-variations

Now you can use the library as you wish:


// for node environments:
const spellingVariations = require("spelling-variations");

var uk_version = new spellingVariations("theater").toUK;
console.log(uk_version);
// > "theatre"

var full = new spellingVariations("Anglify").analyze(); // or .analyse() for obvious reasons
console.log(full);

// will produce something like this:
{
	word: 'cenobitic', 	// original word without any modification just lowercased
	// scoring how common this variation is along other variations
	// 1: the correct one to use / the most common
	// 0.87: frequent usually, the same for US/UK
	// 0.75: infrequent
	// 0.5: uncommon
	// 0.25: very uncommon, might be present only in old texts
	// 0: this variation is rejected
	// -1: the word you passed isn't present in the database (might be not having a spelling variations)
	scoreUK: 0.75,
	scoreUS: 1,
	// whether or not the word has variations
	hasVariations: true,
	// the preferred variation for the UK
	UKPreferred: 'coenobitic',
	// the preferred variation for the US
	USPreferred: 'cenobitic',
	// if there's a common variation between the US & UK
	commonVariation: '',
	// all UK variations of the word ordered by commonness
	UKVariations: [ 'coenobitic', 'coenobitical', 'cenobitical' ],
	// all US variations of the word ordered by commonness
	USVariations: [ 'coenobitic', 'cenobitical', 'coenobitical' ],
	// all variations (not ordered by any means)
	variations: [ 'coenobitic', 'coenobitical', 'cenobitical' ],
}

API

Method | Example | Returns | Description --- | --- | --- | --- analyze | new spellingVariations("Anglify").analyze(); | {Object} | @returns: The object described above (in getting started) analyse | new spellingVariations("Anglify").analyse(); | {Object} | @returns: An alias of the same function above (made for obvious reasons) scoreUK | new spellingVariations("Anglify").scoreUK(); | {Number} | @returns: A score of how common this variation in the UK's texts (1-0) scoreUS | new spellingVariations("Anglify").scoreUS(); | {Number} | @returns: A score of how common this variation in the US's texts (1-0) hasVariations | new spellingVariations("Anglify").hasVariations(); | {Boolean} | @returns: Does this word have other variations? USVariations | new spellingVariations("Anglify").USVariations(); | {Array} | @returns: US variations of the word UKVariations | new spellingVariations("Anglify").UKVariations(); | {Array} | @returns: UK variations of the word variations | new spellingVariations("Anglify").variations(); | {Array} | @returns: All of the word's variations UKPreferred | new spellingVariations("Anglify").UKPreferred(); | {String} | @returns: UK's preferred variation USPreferred | new spellingVariations("Anglify").USPreferred(); | {String} | @returns: US's preferred variation commonVariation | new spellingVariations("Anglify").commonVariation(); | {String} | @returns: A variation that is common for the US and the UK toUK | new spellingVariations("Anglify").toUK(); | {String} | @returns: UK variant of the word toUS | new spellingVariations("Anglify").toUS(); | {String} | @returns: US variant of the word

Frequency Scores

One might think that the word theatre is present solely in British English text and the word theater is in American English text, however that's not the case. If you tracked the word theatre in Google's N-Gram viewer (screenshot below), you'll see that it has been used in American English text as well as the the word theater, yet the word theater has been raising in popularity in American English text more than theatre. Same case applies for many word spelling variations out there.

http://puu.sh/t54v6/fd05234a0a.png

http://puu.sh/t54ze/765341b8af.png

For this reason, this library will rather tell you the frequency score (which is calculated by comparison with other spelling variations) rather than whether this spelling variation is British or American.

And these are the possible scores:

  • 1: the correct one to use / the most common
  • 0.87: frequent, the same for US/UK
  • 0.75: infrequent
  • 0.5: uncommon
  • 0.25: very uncommon, might be present only in old texts
  • 0: this variation is rejected in the (UK/US).
  • -1: the word you passed isn't present in the database.

The score -1 does not mean that this word isn't a dictionary word, absolutely not! it only means that this word doesn't have a spelling variations.

For example, the words anything, everything, only will have a score of -1 since those don't really have a spelling variation and they are the same for American and British spelling.

Contributing

  • clone this repository to your machine
  • cd spelling-variations && npm install
  • install mocha globally (for running the tests): mocha test/test
  • ..
  • ..
  • build node build/build
  • test node test/test

License: The MIT License.