API reference › @evolu/common › Type › uuidVersion
function uuidVersion<Version extends UuidVersion>(
version: ValidateBrandFactoryNumber<Version>,
): BrandFactory<
`UuidV${Version}`,
string & Brand<"Uuid">,
UuidVersionError<Version>
>;
Defined in: packages/common/src/Type.ts:10663
Uuid Brand requiring one RFC 9562 version.
Accepts a UUID whose version digit is the given version and whose variant is the one RFC 9562 defines, so the Nil and Max UUIDs fail every version. The version must be one concrete numeric literal so different versions have distinct brands.
Use UuidV4 for random UUIDs and UuidV7 for time-ordered UUIDs.
Example
import {
assertErr,
assertOk,
assertType,
Uuid,
uuidVersion,
type Brand,
} from "@evolu/common";
const UuidV1 = uuidVersion(1)(Uuid);
const value = UuidV1.fromUnknown("c232ab00-9414-11ec-b3c8-9f6bdeced846");
assertOk(value, "c232ab00-9414-11ec-b3c8-9f6bdeced846");
assertType<typeof value.value, string & Brand<"Uuid"> & Brand<"UuidV1">>();
assertErr(UuidV1.fromUnknown("0190a6f4-8c3e-7b2a-9d41-5e6f7a8b9c0d"));