Optimal
A system for building and validating defined object structures, like argument options, configuration
files, data bags, validation fields, and more! Runs checks in development and strips checks in
production using dead code elimination (should not be used on user input!).
- Recursively builds and validates nested structures.
- Supports common data types.
- Autofills missing fields with default values.
- Allows or restricts unknown fields.
- Mark fields as nullable or required.
- Handles logical operators AND, OR, and XOR.
import optimal, { array, string, number } from 'optimal';
optimal(
{ name: 'Optimal' },
{
name: string().notEmpty(),
include: array().of(string()),
exclude: array().of(string()),
maxSize: number(10000).gte(0),
},
);
{
name: 'Optimal',
include: [],
exclude: [],
maxSize: 10000,
}
Requirements
- Node 12.17+
- Edge / Modern browsers
Installation
yarn add optimal
Documentation
https://milesj.gitbook.io/optimal