uuidnamespacenamespace uuidUUIDs (RFC 9562): the branded Uuid, its text form read and written, the name-based version 5 (SHA-1 of a namespace and a name) and the namespaces RFC 9562 defines (Appendix A.4: DNS, URL, OID, X.500). A version 5 UUID is the same for the same namespace and name on every runtime, so the standard formats name what they describe by it and the same input gives the same document (commons 0007-grc FR-017, FR-018). SHA-1 is Web Crypto's (crypto.subtle.digest), so uuidV5 is asynchronous; it is used here as RFC 9562 uses it, to name, not to protect.
import { NAMESPACE_DNS, uuidV5 } from "./uuid.ts";
await uuidV5(NAMESPACE_DNS, "www.example.com"); // "2ed6657d-e927-568b-95e1-2665a8aea6a2"uuidnamespacenamespace uuiduuid.Uuidtypeno test imports ittype Uuid = Brand<string, "Uuid">;A UUID in RFC 9562's text form, lower-case: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx; made only by uuidOf, uuidFromBytes and uuidV5.
uuid.uuidOffunctionno test imports itfunction uuidOf(text: string): Uuid | undefinedText as a Uuid (any case, with or without a urn:uuid: prefix), lower-cased; undefined where it is not one.
uuid.uuidFromBytesfunctionno test imports itfunction uuidFromBytes(bytes: Uint8Array<ArrayBufferLike>): Uuid | undefinedSixteen bytes as a Uuid, or undefined where there are not sixteen.
uuid.uuidBytesfunctionno test imports itfunction uuidBytes(u: Uuid): Uint8Array<ArrayBufferLike>A UUID's sixteen bytes.
uuid.uuidVersionfunctionno test imports itfunction uuidVersion(u: Uuid): numberA UUID's version, the high four bits of its seventh byte (5 for a name-based UUID with SHA-1).
uuid.uuidUrnfunctionno test imports itfunction uuidUrn(u: Uuid): `urn:uuid:${string}`A UUID as a URN, urn:uuid:... (RFC 9562 Section 4).
uuid.NIL_UUIDconstno test imports itconst NIL_UUID: UuidThe Nil UUID, all zeros (RFC 9562 Section 5.9).
uuid.NAMESPACE_DNSconstno test imports itconst NAMESPACE_DNS: UuidThe namespace of fully qualified domain names (RFC 9562 Section 6.6).
uuid.NAMESPACE_URLconstno test imports itconst NAMESPACE_URL: UuidThe namespace of URLs (RFC 9562 Section 6.6).
uuid.NAMESPACE_OIDconstno test imports itconst NAMESPACE_OID: UuidThe namespace of ISO object identifiers (RFC 9562 Section 6.6).
uuid.NAMESPACE_X500constno test imports itconst NAMESPACE_X500: UuidThe namespace of X.500 distinguished names, in DER or text (RFC 9562 Section 6.6).
uuid.uuidV5functionno test imports itfunction uuidV5(namespace: Uuid, name: string | Uint8Array<ArrayBufferLike>): Promise<Uuid>The version 5 UUID of a name in a namespace (RFC 9562 Section 5.5): the first sixteen bytes of SHA-1 over the namespace's bytes and then the name's (a string is taken as UTF-8), with the version (5) and the variant (10) set.
uuid.nameOffunctionno test imports itfunction nameOf(parts: readonly string[]): stringA stable name made of parts, for uuidV5: the parts as a JSON array, so that no two lists of parts give the same name (["a/b"] and ["a", "b"] stay apart).
uuid.uuidV5Offunctionno test imports itfunction uuidV5Of(namespace: Uuid, parts: readonly string[]): Promise<Uuid>The version 5 UUID of a name made of parts (nameOf) in a namespace.
uuid.uuidDecoderconstno test imports itconst uuidDecoder: Decoder<Uuid>The decoder of a UUID in text (any case, or a urn:uuid: URN).
Uuidtypetype Uuid = Brand<string, "Uuid">;A UUID in RFC 9562's text form, lower-case: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx; made only by uuidOf, uuidFromBytes and uuidV5.
uuidOffunctionfunction uuidOf(text: string): Uuid | undefinedText as a Uuid (any case, with or without a urn:uuid: prefix), lower-cased; undefined where it is not one.
uuidFromBytesfunctionfunction uuidFromBytes(bytes: Uint8Array<ArrayBufferLike>): Uuid | undefinedSixteen bytes as a Uuid, or undefined where there are not sixteen.
uuidBytesfunctionfunction uuidBytes(u: Uuid): Uint8Array<ArrayBufferLike>A UUID's sixteen bytes.
uuidVersionfunctionfunction uuidVersion(u: Uuid): numberA UUID's version, the high four bits of its seventh byte (5 for a name-based UUID with SHA-1).
uuidUrnfunctionfunction uuidUrn(u: Uuid): `urn:uuid:${string}`A UUID as a URN, urn:uuid:... (RFC 9562 Section 4).
NIL_UUIDconstconst NIL_UUID: UuidThe Nil UUID, all zeros (RFC 9562 Section 5.9).
NAMESPACE_DNSconstconst NAMESPACE_DNS: UuidThe namespace of fully qualified domain names (RFC 9562 Section 6.6).
NAMESPACE_URLconstconst NAMESPACE_URL: UuidThe namespace of URLs (RFC 9562 Section 6.6).
NAMESPACE_OIDconstconst NAMESPACE_OID: UuidThe namespace of ISO object identifiers (RFC 9562 Section 6.6).
NAMESPACE_X500constconst NAMESPACE_X500: UuidThe namespace of X.500 distinguished names, in DER or text (RFC 9562 Section 6.6).
uuidV5functionfunction uuidV5(namespace: Uuid, name: string | Uint8Array<ArrayBufferLike>): Promise<Uuid>The version 5 UUID of a name in a namespace (RFC 9562 Section 5.5): the first sixteen bytes of SHA-1 over the namespace's bytes and then the name's (a string is taken as UTF-8), with the version (5) and the variant (10) set.
nameOffunctionfunction nameOf(parts: readonly string[]): stringA stable name made of parts, for uuidV5: the parts as a JSON array, so that no two lists of parts give the same name (["a/b"] and ["a", "b"] stay apart).
uuidV5Offunctionfunction uuidV5Of(namespace: Uuid, parts: readonly string[]): Promise<Uuid>The version 5 UUID of a name made of parts (nameOf) in a namespace.
uuidDecoderconstconst uuidDecoder: Decoder<Uuid>The decoder of a UUID in text (any case, or a urn:uuid: URN).