⚠️ This project is still in early alpha. Please report bugs on GitHub.

Modifiers
Custom

Custom modifier

A modifier which creates a validation rule to ensure that a a custom assertion is true.

If you have specific needs that are not met by existing modifiers, the custom modifier could be something to reach for. It works with all of the primary schema types, except object.

Schemas

Arguments

  • assertions: A tuple consisting of an assertion and the related error.

Example

import { custom, string, ValidationError } from '@nordic-ui/validathor';
 
const customRule = string([custom((value) =>
  [[value.toLowerCase() === value, new ValidationError('Lowercase only')]]
)]);
 
try {
  const parsedValue = customRule.parse('only_lowercase_chars');
  console.log('Parsed value:', parsedValue);
} catch (error) {
  console.error('Parsing failed:', error.message);
}