UNPKG

@tldraw/tlschema

Version:

A tiny little drawing app (schema).

15 lines (13 loc) 400 B
import type { RecordId, UnknownRecord } from '@tldraw/store' import { T } from '@tldraw/validate' /** @public */ export function idValidator<Id extends RecordId<UnknownRecord>>( prefix: Id['__type__']['typeName'] ): T.Validator<Id> { return T.string.refine((id) => { if (!id.startsWith(`${prefix}:`)) { throw new Error(`${prefix} ID must start with "${prefix}:"`) } return id as Id }) }