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

Schemas
Array

Array schema

A function which creates a parsing rule to ensure that a given value is an array.

Arguments

  1. A schema
  2. (Optional): A list of modifiers
  3. (Optional): A custom object with error messages to be displayed when validation fails or there are type errors.

Example

import { array, string } from '@nordic-ui/validathor';
 
const arrayRule = array(string(), undefined, 'Value must be an array');
 
try {
  const parsedValue = arrayRule.parse(['Hello', 'world']);
  console.log('Parsed value:', parsedValue);
} catch (error) {
  console.error('Parsing failed:', error.message);
}