ConstValidates that a string is not empty.
The string to validate
Name of the field for error messages
Success with trimmed string or Failure
Validates string length.
The string to validate
Validation options (min, max, fieldName)
Success with trimmed string or Failure
Validates number range.
The number to validate
Validation options (min, max, fieldName)
Success with number or Failure
Validates against a regex pattern.
The string to validate
The regular expression pattern
Custom error message
Success with string or Failure
Validates email format.
The email string to validate
Success with email or Failure
Validates URL format.
The URL string to validate
Success with URL or Failure
Composes multiple validators into a single validator. Validators are executed in order, stopping at first failure.
Array of validator functions
A composed validator function
// Compose validators for a ProductName value object
static create(value: string): Result<ProductName, DomainError> {
return Validators.compose(
(v) => Validators.notEmpty(v, 'Product name'),
(v) => Validators.length(v, { min: 3, max: 100 })
)(value).map(validated => new ProductName(validated));
}
Common validators for value objects and domain entities.
These validators are reusable, composable, and return Results for type-safe error handling.