Skip to content

RuleDef ​

A rule, as defineRule takes it.

Generics ​

Definition ​

  • RuleDef
    • kinds readonly ValueKind[]: the kinds of field it fits
    • stage RuleStage: optional, 'normalize' or 'validate', the default
    • params TParams | ((kind: ValueKind) => TParams): optional, the params it takes
    • meta RuleMeta: optional
    • create (params, message?: string) => AnyAction: the Valibot action for its params and message

Explanation ​

See custom rules.

RuleMeta ​

  • RuleMeta
    • label string
    • description string: optional
    • category RuleCategory

RuleCategory ​

ts
type RuleCategory =
  | 'length'
  | 'text'
  | 'content'
  | 'format'
  | 'date'
  | 'comparison'
  | 'number'
  | 'file'
  | 'normalize'
  | (string & {})

RuleStage ​

ts
type RuleStage = 'normalize' | 'validate'

normalize rules run before the required check, so ' ' with trim counts as empty. validate rules run after it.

Functions ​