ids/uuid

A module for generating UUIDs (Universally Unique Identifiers).

The module currently supports UUID versions:

Functions

pub fn decode_v7(
  uuid_v7: String,
) -> Result(#(Int, Int, BitArray, Int, BitArray), String)

Decodes a version 7 UUID to #(timestamp, version, random_a, rfc_variant, random_b).

pub fn generate_v4() -> Result(String, String)

Generates a version 4 (random) UUID. The version 4 UUID produced by this function is generated using a cryptographically secure random number generator.

Usage

import ids/uuid

let assert Ok(id) = uuid.generate_v4()
pub fn generate_v7() -> Result(String, String)

Generates a version 7 UUID. The version 7 UUID produced by this function is generated using a cryptographically secure random number generator and includes a unix timestamp.

Usage

import ids/uuid

let assert Ok(id) = uuid.generate_v7()
pub fn generate_v7_from_timestamp(
  timestamp: Int,
) -> Result(String, String)

Generates a version 7 UUID from a given unix timestamp in milliseconds.

Search Document