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

Other Useful Business Software
Ship AI Apps Faster with Vertex AI Icon
Ship AI Apps Faster with Vertex AI

Go from idea to deployed AI app without managing infrastructure. Vertex AI offers one platform for the entire AI development lifecycle.

Ship AI apps and features faster with Vertex AI—your end-to-end AI platform. Access Gemini 3 and 200+ foundation models, fine-tune for your needs, and deploy with enterprise-grade MLOps. Build chatbots, agents, or custom models. New customers get $300 in free credit.
Try Vertex AI 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