@prismicio/types-internal
Version:
Prismic types for Custom Types and Prismic Data
20 lines (15 loc) • 415 B
text/typescript
import * as t from "io-ts"
import { validate as validateUUID } from "uuid"
import { withCustomError } from "../validators/function"
export interface UUIDBrand {
readonly UUID: unique symbol
}
export const UUID = withCustomError(
t.brand(
t.string,
(s): s is t.Branded<string, UUIDBrand> => validateUUID(s),
"UUID",
),
() => "The value must be a valid UUID",
)
export type UUID = t.TypeOf<typeof UUID>