Array schema
A function which creates a parsing rule to ensure that a given value is an array.
Arguments
schema
- A single schema or an array of schemasmodifiers?
- A list of modifiersmin
: Learn moremax
: Learn morecustom
: Learn more
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)[]