miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.UUID

Description

Overview

Miso.UUID provides a UUID type, as defined in RFC 4122, backed by a MisoString. Its API mirrors Data.UUID from the uuid package.

New v4 UUIDs are generated with the browser's crypto.randomUUID(). Parsing accepts the canonical 8-4-4-4-12 hexadecimal form, in either case, and normalizes it to lowercase.

Quick start

import Miso.UUID (tUUID)
import qualified Miso.UUID as UUID

-- Generate a fresh identifier
freshId :: IO UUID
freshId = UUID.nextRandom

-- Parse one
parsed :: Maybe UUID
parsed = UUID.fromString "550e8400-e29b-41d4-a716-446655440000"

-- Check for the nil UUID
isUnset :: UUID -> Bool
isUnset = UUID.null

Instances

UUID can be converted to and from MisoString, JSON, JSVal, and used as a route capture with Miso.Router. Its Show and Read instances use the unquoted 8-4-4-4-12 form, like Data.UUID.

Synopsis

Types

data UUID Source #

A universally unique identifier, as defined in RFC 4122.

Instances

Instances details
Eq UUID Source # 
Instance details

Defined in Miso.UUID

Methods

(==) :: UUID -> UUID -> Bool #

(/=) :: UUID -> UUID -> Bool #

Ord UUID Source # 
Instance details

Defined in Miso.UUID

Methods

compare :: UUID -> UUID -> Ordering #

(<) :: UUID -> UUID -> Bool #

(<=) :: UUID -> UUID -> Bool #

(>) :: UUID -> UUID -> Bool #

(>=) :: UUID -> UUID -> Bool #

max :: UUID -> UUID -> UUID #

min :: UUID -> UUID -> UUID #

Read UUID Source # 
Instance details

Defined in Miso.UUID

Show UUID Source # 
Instance details

Defined in Miso.UUID

Methods

showsPrec :: Int -> UUID -> ShowS #

show :: UUID -> String #

showList :: [UUID] -> ShowS #

FromJSVal UUID Source # 
Instance details

Defined in Miso.UUID

ToJSVal UUID Source # 
Instance details

Defined in Miso.UUID

Methods

toJSVal :: UUID -> IO JSVal Source #

FromJSON UUID Source # 
Instance details

Defined in Miso.UUID

ToJSON UUID Source # 
Instance details

Defined in Miso.UUID

Router UUID Source # 
Instance details

Defined in Miso.UUID

FromMisoString UUID Source # 
Instance details

Defined in Miso.UUID

ToMisoString UUID Source # 
Instance details

Defined in Miso.UUID

String conversion

toString :: UUID -> String Source #

Convert a UUID to its 8-4-4-4-12 string form, in lowercase.

fromString :: String -> Maybe UUID Source #

Parse a UUID from its 8-4-4-4-12 string form.

toText :: UUID -> Text Source #

Like toString, but to Text.

fromText :: Text -> Maybe UUID Source #

Like fromString, but from Text.

toASCIIBytes :: UUID -> ByteString Source #

Like toString, but to an ASCII-encoded strict ByteString.

fromASCIIBytes :: ByteString -> Maybe UUID Source #

Like fromString, but from an ASCII-encoded strict ByteString.

toLazyASCIIBytes :: UUID -> ByteString Source #

Like toString, but to an ASCII-encoded lazy ByteString.

fromLazyASCIIBytes :: ByteString -> Maybe UUID Source #

Like fromString, but from an ASCII-encoded lazy ByteString.

Binary conversion

toByteString :: UUID -> ByteString Source #

Encode a UUID as 16 bytes, in network byte order.

fromByteString :: ByteString -> Maybe UUID Source #

Decode a UUID from 16 bytes, in network byte order. Returns Nothing if the input is not exactly 16 bytes long.

toWords :: UUID -> (Word32, Word32, Word32, Word32) Source #

Convert a UUID to four 32-bit words, most significant first.

fromWords :: Word32 -> Word32 -> Word32 -> Word32 -> UUID Source #

Build a UUID from four 32-bit words, most significant first.

toWords64 :: UUID -> (Word64, Word64) Source #

Convert a UUID to two 64-bit words, most significant first.

fromWords64 :: Word64 -> Word64 -> UUID Source #

Build a UUID from two 64-bit words, most significant first.

Nil

null :: UUID -> Bool Source #

Returns True if the passed-in UUID is the nil UUID.

nil :: UUID Source #

The nil UUID, as defined in RFC 4122. It is a UUID of all zeros.

Generation

nextRandom :: IO UUID Source #

Generate a v4 UUID using a cryptographically secure random number generator.