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

typosquatting

v1.0.12

Published

Catch those pesky typosquatting libraries, before they catch you!

Downloads

32

Readme

Anti-Typosquatting

npm version License

A powerful npm package to prevent typosquatting attacks by catching npm install <package_name> typos.

Example

Features

  • 🕵️‍♀️ Detects potential typosquatting attempts in package names.
  • 🧪 Provides suggestions for correct package names.
  • ⚙️ Integrates seamlessly with your existing npm workflows.
  • ⚡️ Lightweight and fast, averaging 10ms per package check.

How to use

npi <package_name> # instals the package if it is safe, otherwise provides suggestions for the correct package name
npi --refresh # refreshes the list of top 10000 packages (useful if you want to force-update the list)
npi --distance <distance> # sets the tolerated distance for typosquatting detection (default is 2) # alternatively, you can set your env variable TYPOSQUATTING_TOLERATED_DISTANCE to the desired value

Every time you run npi <package_name>, anti-typosquatting will check if the package name is a potential typosquatting attempt. If it is, it will provide suggestions for the correct package name. If the package name is safe, the installation will proceed as normal.

How it Works

Anti-typosquatting uses the Levenshtein distance algorithm to calculate the similarity between the package that the user wants to install against the top 10000 npm packages (retrieved from LeoDog896's latest npm-rank release).

The Levenshtein distance between two strings is calculated by finding the minimum number of operations required to transform one string into the other (operations being insertions, deletions, or substitutions). This is a perfect way to detect typosquatting attempts, as it can detect small differences between two strings that are caused by typos or misspellings.

Levenshtein distance algorithm's dynamic programming implementation has a time complexity of O(m*n), where m and n are the lengths of the two strings being compared, so the algorithm is very fast and efficient. On average, the algorithm takes around 10ms to calculate the similarity between the package name and the top 10000 packages, making it a great choice for typosquatting detection.

Installation

To install the package, run the following command:

npm install anti-typosquatting -g

Congrats! Running npi <package_name> will now check if the package name is a potential typosquatting attempt before installing the package.

Note: The packages typosquatting, typosquating, and safe-install are all owned by me too so you can install those as well :)

(OPTIONAL) If you'd like to use npm install instead of the npi command, you can set up an alias.

To set up the alias, use the alias-setup.sh script (make sure to double check your bash config file path):

./src/alias-setup.sh

(You can still use the npm install without going through the checking if you use npm oldinstall <package_name> after using the alias-setup.sh script)

You can edit how aggressive the typosquatting detection is by adding an env variable called TYPOSQUATTING_TOLERATED_DISTANCE. The threshold is the maximum Levenshtein distance between the package name and the top 10000 packages that is considered safe. By default, the threshold is set to 2, but you can change it to any value you like. Higher, the value, the more aggressive the detection will be.

Contributing

Contributions are welcome! Feel free to submit issues or pull requests to improve the library.

License

anti-typosquatting is MIT licensed.