/** * A field's purpose: what its value means (`email`, `date-signed`, a name an * app made up). The engine keeps it with the field and reads nothing into * it; what a purpose does is its reader's to decide. */ import { checkedFieldText, FIELD_TEXT_MAX_LENGTH, isFieldText } from './fieldText'; /** The most characters a purpose has. */ export const FIELD_PURPOSE_MAX_LENGTH = FIELD_TEXT_MAX_LENGTH; /** * Whether `purpose` is one a field takes: 1 to 256 characters, with no white * space at its start or its end and no NUL character (`\u0000`) in it. The * runtime takes a string up to its first NUL, so a purpose with one would be * stored cut short. */ export function isFieldPurpose(purpose: unknown): purpose is string { return isFieldText(purpose); } /** * The purpose a write names: `null` for none, which a draft also says by * leaving it out. One that isn't a purpose ({@link isFieldPurpose}) is * refused with `InvalidArg`, not trimmed. */ export function checkedPurpose(purpose: unknown): string | null { return checkedFieldText(purpose, 'purpose'); }