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 = Uuid

Universally Unique Identifiers (UUID v4) are randomly generated 128-bit values.

Values

generate

generate : Task x Uuid

Generate a random UUID v4 as a Task.

Examples

Task.perform GotId Uuid.generate

generateAs

generateAs : (Uuid -> a) -> Task x a

Generate a UUID and wrap it with a constructor.

Examples

type ArticleID = ArticleID Uuid

Task.perform GotArticle (generateAs ArticleID)

toBase64

toBase64 : Uuid -> String

Convert 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 Uuid

Try to convert a Base64 encoded String into a Uuid.

Examples

fromBase64 "AAAAAAAAAAAAAAAAAAAAAA" == Just uuid1
fromBase64 "kel7A1aURfClkxOtERvA" == Nothing