news.volyx.in

Sqids – Generate short unique IDs from numbers (sqids.org)

565 points by vyrotek · 1001 days ago · 232 comments on HN

Article summary

Sqids is an open-source library that generates short unique identifiers from numbers, which are URL-safe and do not contain common profanity words. The library can encode several numbers and is suitable for use cases such as encoding primary keys, saving database lookups, and generating temporary login tokens. Sqids has implementations in multiple languages and provides features like easy encoding and decoding, auto-generated IDs, and support for custom IDs. The library is not intended for sensitive data or encryption.

Main themes

  • unique ID generation
  • profanity exclusion
  • library design
  • encoding algorithms
  • use cases
  • compatibility issues

What commenters say

  • The library's approach to excluding profanity is flawed and may not be effective in all languages or contexts.
  • Using a dictionary approach to exclude profanity may be a better solution than hardcoding a list of bad words.
  • The library's design decision to overwrite the default blocklist when a custom blocklist is provided is problematic and may cause compatibility issues.
  • Base64 or base58 encoding may be a simpler and more effective solution for generating unique IDs.
  • The library's lack of uniqueness guarantee is a concern and may not be suitable for all use cases.
  • The ability to pass in an array of numbers is useful for certain use cases, such as encoding shard numbers, primary IDs, and timestamps.
  • The library's implementation is surprisingly complicated and may be over-engineered for its intended purpose.
  • The use of a semicolon-free style in the library's code is appreciated, but may not be a significant advantage in practice.