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

Schemas
Literal

Literal schema

A function which ensures that a given input matches an exact value.

Arguments

  1. value - An exact value the input should be the same as
  2. message? - A custom object with error messages to be displayed when validation fails or there are type errors

Examples

import { literal } from '@nordic-ui/validathor';
 
const literalRule = literal('Hello');
 
try {
  const parsedValue = literalRule.parse('Hello');
  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 literalRule = literal('Hello');
 
type LiteralSchema = ReturnType<typeof literalRule.parse>; // 'Hello'