Uuid
Core
Universally Unique Identifiers without a database transaction.
Prefer this module for cookies, request IDs, and other non-DB work. Inside a Transaction, keep using Database.Uuid.generate.
Universally Unique Identifiers
UUID v4 values are randomly generated 128-bit values. It is extremely unlikely that a given 16-byte Uuid will ever be generated by anyone else ever again.
import Task
import Uuid exposing (Uuid)
type SessionSecret = SessionSecret Uuid
Task.perform GotSecret (Uuid.generateAs SessionSecret)String Conversions
Types
Uuid
type Uuid = UuidUniversally Unique Identifiers (UUID v4) are randomly generated 128-bit values.
Values
generate
generate : Task x UuidGenerate a random UUID v4 as a Task.
Examples
Task.perform GotId Uuid.generategenerateAs
generateAs : (Uuid -> a) -> Task x aGenerate a UUID and wrap it with a constructor.
Examples
type ArticleID = ArticleID Uuid
Task.perform GotArticle (generateAs ArticleID)toBase64
toBase64 : Uuid -> StringConvert the 16 bytes directly into Base64 encoding, producing 22 ASCII characters that are sensible to use for cookie values.
Examples
toBase64 uuid1 == "AAAAAAAAAAAAAAAAAAAAAA"fromBase64
fromBase64 : String -> Maybe UuidTry to convert a Base64 encoded String into a Uuid.
Examples
fromBase64 "AAAAAAAAAAAAAAAAAAAAAA" == Just uuid1
fromBase64 "kel7A1aURfClkxOtERvA" == Nothing