Kinds

What each field builder takes and what it reads. Also what an absent value reads as, and which declarations throw where they are built.

On this page

Text

ts
field.string({ minLength: 2, maxLength: 20, pattern: '[a-z0-9-]+' });
field.email({ maxLength: 254 });
field.url();
field.tel();
field.password({ minLength: 8 });

string, email, url, tel and password read a string. email is checked by HTML’s email address pattern, and url by URL.canParse.

minLength and maxLength count UTF-16 code units, as the attributes do, and an empty value is never tooShort. pattern matches the whole value with the v flag.

password reads as string does. It is the kind a form makes a type="password" control from.

Numbers

ts
field.number({ min: 0, max: 1, step: 0.1 });
field.integer({ min: 1, default: 1 });

number and integer read a number, or a string in the spelling an HTML number input submits. 0x10, ' 2' and Infinity are badInput.

integer refuses a fraction as stepMismatch. step counts from min, or from 0 without one.

Booleans and choices

ts
field.boolean();
field.enum(['new', 'price'], { default: 'new' });

boolean reads true and false, and the strings 'true' and 'false'. Anything else is typeMismatch.

enum reads one of the values it lists. They are literal types without as const, and a default that is not one of them is a type error.

Dates and times

ts
field.date({ min: '2026-01-01' });
field.time({ max: '18:00' });
field.datetime();

date reads a YYYY-MM-DD string, time an HH:MM one and datetime a YYYY-MM-DDTHH:MM one, as they are. That is what the HTML inputs submit, and what JSON keeps.

A date that does not exist, such as 2026-02-30, is badInput. min and max are strings of the same form, compared with the seconds filled in.

Files

ts
field.file({ accept: 'image/*' });

file reads a File. One with no name and no bytes is absent. accept becomes the control’s attribute and is not checked on reading.

Lists and objects

ts
field.list(field.enum(['sale', 'new']), { max: 2 });
field.object({
  name: field.string(),
  quantity: field.integer({ min: 1, default: 1 }),
});

list reads each item of an array as item. An absent item is skipped, and a refused one is dropped from the value with its issue. min and max count the items it kept.

object reads its declared keys only. It takes no options.

Required and messages

ts
field.string({
  required: true,
  minLength: 8,
  messages: { tooShort: 'At least 8 characters' },
});

required: true refuses an absent value as valueMissing, and a false boolean too, as required does on a checkbox.

messages holds the words a form shows, per refusal. Each is a string, or a function that returns one. A function is called where it is shown, so an @k8ordo/i18n message() follows the current locale.

Every kind but list and object takes both. list takes messages only.

An absent value

ts
field.integer(); // number | undefined
field.integer({ default: 1 }); // number
field.integer({ required: true }); // number
field.string(); // string

undefined, null and an empty File are absent. So is '', for every kind but text.

An absent value reads as the default. Without one, text reads '', a boolean false, a list [], and any other kind undefined.

The value type says the same: a default or required: true drops undefined from it.

Declarations that throw

ts
field.integer({ min: 2, max: 1 });
// field.integer: min 2 is above max 1

field.integer({ min: 1, default: 0 });
// field.integer: default 0 is refused by its own constraints (rangeUnderflow)

A declaration that contradicts itself throws where it is built, with an error that starts field.<kind>:: min above max, an enum with no values or a value listed twice, a pattern the v flag rejects, and a default its own constraints refuse.

An option the kind does not take is a type error, and throws where it is built in a file nobody type-checks.

k8ordo

React libraries that use Baseline features without holding back.