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
Run Any Workload on Compute Engine VMs Icon
Run Any Workload on Compute Engine VMs

From dev environments to AI training, choose preset or custom VMs with 1–96 vCPUs and industry-leading 99.95% uptime SLA.

Compute Engine delivers high-performance virtual machines for web apps, databases, containers, and AI workloads. Choose from general-purpose, compute-optimized, or GPU/TPU-accelerated machine types—or build custom VMs to match your exact specs. With live migration and automatic failover, your workloads stay online. New customers get $300 in free credits.
Try Compute Engine
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