class Builder
A class that represents a validation builder for an input value.
class Builder<T = any>;
Notes
- Returned by Schema.build methods, e.g.
f.string(). - Provides a fluent interface for adding default values, validation checks, transformations, and error messages.
Examples
f.string()
.optional() // Allow undefined
.nullable() // Allow null
.default("fallback") // Provide default value
.check(s => s.length > 0) // Custom validation
.error("Cannot be empty") // Custom error message
.transform(s => s.trim()) // Transform the value
.required("Required") // Require non-empty value
Instance members
- [
The Standard Schema v1 compliance property. values
The accepted literal values, for a literal value validator only.shape
The accepted object properties, for an object validator only.default()
Sets a default value.optional()
Marks the value as optional, allowing undefined values.nullable()
Marks the value as nullable, allowing null values but not undefined.required()
Adds a required check (not null, undefined, NaN, or empty string).check()
Adds a validation check using the provided function.error()
Sets the error message for the previously failed check(s).refine()
Adds a refinement check; shorthand for check followed by error.transform()
Transforms the value using the provided callback function.preprocess()
Replaces the input value using the provided callback function.
Related
class Schema
A class that represents a validation schema for input values, objects, and arrays.
