ExCuid2 (ex_cuid2 v0.10.1)

A robust, thread-safe, and testable CUID2 (Collision-Resistant Unique Identifiers) generator for Elixir.

This implementation follows the CUID2 standard and generates safe, horizontally scalable IDs, ideal for use as primary keys in databases.

Features:

  • Prefix with a random letter.
  • Timestamp in milliseconds.
  • Local Atomic counter to prevent collisions in the same millisecond.
  • Cryptographically secure entropy.
  • Process fingerprint to ensure uniqueness across nodes.

Summary

Functions

Generates a CUID2 with the default length and counter.

Generates a CUID2 with a specific length, using the default counter. Raises FunctionClauseError if length is not an integer.

Validates whether a string matches the CUID2 format. Returns false for any non-binary input, will not raise an error.

Functions

generate()

Generates a CUID2 with the default length and counter.

generate(length)

Generates a CUID2 with a specific length, using the default counter. Raises FunctionClauseError if length is not an integer.

is_valid?(cuid)

Validates whether a string matches the CUID2 format. Returns false for any non-binary input, will not raise an error.