validation
Validation module - Data validation with error accumulation.
The Validation type is similar to Result but optimized for error accumulation. While Result short-circuits on the first error (fail-fast), Validation accumulates all errors (fail-slow), making it ideal for form validation and multi-field data validation.
Example
import { valid, invalid, validate, schema } from 'receta/validation'
// Single field validation with multiple rules
const validatePassword = (password: string) =>
validate(password, [
fromPredicate(s => s.length >= 8, 'At least 8 characters'),
fromPredicate(s => /[A-Z]/.test(s), 'At least one uppercase'),
fromPredicate(s => /[0-9]/.test(s), 'At least one number')
])
// Multi-field validation (accumulates all errors)
const userSchema = schema({
name: pipe(required, minLength(3)),
email: pipe(required, email),
age: pipe(required, min(18))
})
// Returns all field errors at once, not just the first one
validateForm(formData) // => Invalid([...all errors...])
References
alphanumeric
Re-exports alphanumeric
between
Re-exports between
collectErrors
Re-exports collectErrors
defined
Re-exports defined
email
Re-exports email
equals
Re-exports equals
FieldError
Re-exports FieldError
finite
Re-exports finite
flatMap
Re-exports flatMap
flatten
Re-exports flatten
fromPredicate
Re-exports fromPredicate
fromPredicateWithError
Re-exports fromPredicateWithError
fromResult
Re-exports fromResult
integer
Re-exports integer
invalid
Re-exports invalid
Invalid
Re-exports Invalid
isInvalid
Re-exports isInvalid
isValid
Re-exports isValid
lengthBetween
Re-exports lengthBetween
map
Re-exports map
mapInvalid
Re-exports mapInvalid
match
Re-exports match
matches
Re-exports matches
max
Re-exports max
maxItems
Re-exports maxItems
maxLength
Re-exports maxLength
min
Re-exports min
minItems
Re-exports minItems
minLength
Re-exports minLength
negative
Re-exports negative
nonEmpty
Re-exports nonEmpty
notNaN
Re-exports notNaN
oneOf
Re-exports oneOf
partial
Re-exports partial
positive
Re-exports positive
required
Re-exports required
schema
Re-exports schema
tap
Re-exports tap
tapInvalid
Re-exports tapInvalid
toResult
Re-exports toResult
toResultWith
Re-exports toResultWith
tryCatch
Re-exports tryCatch
tryCatchAsync
Re-exports tryCatchAsync
unwrap
Re-exports unwrap
unwrapOr
Re-exports unwrapOr
unwrapOrElse
Re-exports unwrapOrElse
url
Re-exports url
valid
Re-exports valid
Valid
Re-exports Valid
validate
Re-exports validate
validateAll
Re-exports validateAll
Validation
Re-exports Validation
ValidationMatcher
Re-exports ValidationMatcher
ValidationSchema
Re-exports ValidationSchema
Validator
Re-exports Validator