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

Schemas
Object

Object schema

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

Arguments

  1. schema - A record of schemas
  2. message? - A custom object with error messages to be displayed when validation fails or there are type errors

Examples

import { object, string } from '@nordic-ui/validathor';
 
const objectRule = object({ name: string() });
 
try {
  const parsedValue = objectRule.parse({ name: 'John Doe' });
  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 objectRule = object({ name: string() });
 
type ObjectSchema = ReturnType<typeof objectRule.parse>; // { name: string }