⚠️ 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. schema - A single schema or an array of schemas
  2. modifiers? - A list of modifiers
  3. message? - A custom object with error messages to be displayed when validation fails or there are type errors

Examples

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

TypeScript

To get the type of a schema, you can do the following:

const arrayRule = array([string(), number()]);
 
type ArraySchema = ReturnType<typeof arrayRule.parse>; // (string | number)[]