optimal

Build, validate, and transform values with immutable typed schemas.

MIT 68 个版本
安装
npm install optimal
yarn add optimal
pnpm add optimal
bun add optimal
README

Optimal

Build Status npm version npm deps

Optimal is a system for building and validating any value with typed schemas, and first-class support for defined object structures, like options objects, configuration files, validation fields, and many more. Optimal aims to provide a powerful API, with high performance, the lowest possible filesize, and TypeScript-first support.

// Import schemas to build validators withs
import { array, string, number, optimal } from 'optimal';

// Define and validate values with individual schemas
const maxSizeSchema = number().positive().lte(10000);

maxSizeSchema.validate(1234);

// Or define an explicit shaped blueprint
const schema = optimal({
  name: string().notEmpty(),
  include: array().of(string()),
  exclude: array().of(string()),
  maxSize: maxSizeSchema
});

// Pass a full or partial object to validate
const options = schema.validate({ name: 'Optimal' });

// Which validates, builds, and returns the following object
{
  name: 'Optimal',
  include: [],
  exclude: [],
  maxSize: 10000,
}

Features

  • Zero dependencies, with a tree-shakable API.
  • Powerful inferrence using a TypeScript first design.
  • Runs in both Node.js and the browser.
  • Smallest filesize: 5kB minified and gzipped!
  • Immutable & fluent schema builder pattern.
  • 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.

Requirements

  • Node v12.17 (server)
  • Edge, Chrome, Firefox, Safari (browser)

Installation

yarn add optimal

Documentation

https://optimallib.dev

版本列表
5.1.1 2021-10-16
5.1.0 2021-10-10
5.0.0-alpha.5 2021-10-01
5.0.0-alpha.4 2021-09-21
5.0.0-alpha.3 2021-09-21
5.0.0-alpha.2 2021-09-16
5.0.0-alpha.1 2021-09-08
5.0.0 2021-10-07
4.3.0 2021-02-21
4.2.1 2021-02-12
4.2.0 2020-01-26
4.1.2 2020-01-26
4.1.1 2020-01-25
4.1.0 2020-01-20
4.0.1 2020-01-19
4.0.0-2 2020-01-04
4.0.0-1 2020-01-04
4.0.0-0 2020-01-03
4.0.0 2020-01-08
3.4.0 2019-12-29
3.3.0 2019-12-03
3.2.1 2019-04-23
3.2.0 2019-04-20
3.1.1 2019-04-13
3.1.0-0 2019-04-08
3.1.0 2019-04-08
3.0.0-0 2019-04-04
3.0.0 2019-04-04
2.2.0-1 2019-04-04
2.2.0-0 2019-04-04
2.1.1 2019-02-08
2.1.0 2019-02-07
2.0.0-2 2019-01-31
2.0.0-1 2019-01-31
2.0.0-0 2019-01-30
2.0.0 2019-01-31
1.2.0 2018-12-31
1.1.3 2018-10-16
1.1.2 2018-10-16
1.1.1 2018-09-02
1.1.0 2018-09-02
1.0.0 2018-06-07
0.20.0 2018-06-07
0.19.0 2018-04-11
0.18.0 2018-03-25
0.17.3 2018-03-24
0.17.2 2018-03-24
0.17.1 2018-03-24
0.17.0 2018-03-23
0.16.0 2018-03-23
0.15.0 2018-03-21
0.14.0 2017-07-29
0.13.0 2017-07-15
0.12.0 2017-07-14
0.11.0 2017-07-11
0.10.0 2017-07-11
0.9.0 2017-07-10
0.8.0 2017-07-09
0.7.0 2017-07-08
0.6.0 2017-07-08
0.5.0 2017-07-07
0.4.0 2017-07-07
0.3.1 2017-07-06
0.3.0 2017-07-04
0.2.0 2017-06-24
0.1.0 2013-02-01
0.0.3 2012-07-03
0.0.2 2012-07-01