Hashids is a small open-source library that generates short, unique, non-sequential ids from numbers. It converts numbers like 347 into strings like “yr8”, or array of numbers like [27, 986] into “3kTMd”. You can also decode those ids back. This is useful in bundling several parameters into one or simply using them as short UIDs. Hashids works similarly to the way integers are converted to hex, but with a few exceptions. The alphabet is not base16, but base base62 by default. The alphabet is also shuffled based on salt. We need ids to be nice and friendly especially if they end up being in the URL. Therefore, the algorithm tries to avoid generating most common English curse words by never placing the following letters (and their uppercase equivalents) next to each other. There are no collisions because the method is based on integer to hex conversion. As long as you don't change constructor arguments midway, the generated output will stay unique to your salt.

Features

  • Generate short unique IDs from integers
  • Available in JavaScript, Ruby, Python, Java, Scala, PHP, etc.
  • Create short unique ids from numbers (positive numbers & zero)
  • Allow custom alphabet as well as salt, so ids are unique only to you
  • Incremental input is mangled to stay unguessable
  • Code is tiny (~350 lines), fast and does not depend on external libraries

Project Samples

Project Activity

See All Activity >

Categories

Libraries

License

MIT License

Follow Hashids

Hashids Web Site

You Might Also Like
Gen AI apps are built with MongoDB Atlas Icon
Gen AI apps are built with MongoDB Atlas

The database for AI-powered applications.

MongoDB Atlas is the developer-friendly database used to build, scale, and run gen AI and LLM-powered apps—without needing a separate vector database. Atlas offers built-in vector search, global availability across 115+ regions, and flexible document modeling. Start building AI apps faster, all in one place.
Start Free
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of Hashids!

Additional Project Details

Programming Language

PHP

Related Categories

PHP Libraries

Registered

2021-12-08