Skip to content

text

const text: TextPrimitive

Text primitive with optional chainable length and pattern constraints.

Text is always escaped when serialized to JSON, so it is safe for untrusted input and can contain arbitrary Unicode characters including newlines. In contrast, the string primitive is intended for short single-line strings without special characters (e.g. names, titles) and is not escaped when serialized, so it will throw an error on the consumer side if the input contains special characters that would break JSON syntax.

Example:

text // any text
text.min(3).max(50) // length range
text.pattern(/^\S+@\S+\..+$/) // regex constraint

Throws:

When the raw value fails this primitive’s validation.

Learn: Primitives and builders

Last updated: