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
MongoDB Atlas runs apps anywhere Icon
MongoDB Atlas runs apps anywhere

Deploy in 115+ regions with the modern database for every enterprise.

MongoDB Atlas gives you the freedom to build and run modern applications anywhere—across AWS, Azure, and Google Cloud. With global availability in over 115 regions, Atlas lets you deploy close to your users, meet compliance needs, and scale with confidence across any geography.
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