{"library":"optimal","title":"Optimal Schema Validator","description":"Optimal is a JavaScript and TypeScript library designed for robust and type-safe schema definition, validation, and transformation of values. Currently at version 5.1.1, it provides a fluent, immutable API for constructing schemas that define object structures, configuration files, and validation fields. The library maintains a strong focus on performance and minimal footprint, boasting zero runtime dependencies and a small bundle size of just 5kB minified and gzipped. Its release cadence involves periodic major updates preceded by alpha versions, with minor patches addressing fixes. A key differentiator is its TypeScript-first approach, offering powerful inference and ensuring compile-time safety. It operates seamlessly in both Node.js environments (v12.17+) and modern browsers, providing features like recursive validation, automatic defaulting of missing fields, optional strictness for unknown fields, and support for complex logical operators (AND, OR, XOR) to combine schemas. This makes `optimal` suitable for defining and enforcing data contracts across various applications.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install optimal"],"cli":null},"imports":["import { optimal } from 'optimal';","import { string } from 'optimal';","import { SchemaError } from 'optimal';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"// Import schemas to build validators with\nimport { array, string, number, optimal } from 'optimal';\n\n// Define and validate values with individual schemas\nconst maxSizeSchema = number().positive().lte(10000);\n\n// Or define an explicit shaped blueprint\nconst schema = optimal({\n  name: string().notEmpty().default('Default Name'),\n  include: array().of(string()).default([]),\n  exclude: array().of(string()).default([]),\n  maxSize: maxSizeSchema.default(5000)\n});\n\n// Pass a full or partial object to validate\ntry {\n  const options = schema.validate({ name: 'Optimal Project', maxSize: 8000 });\n  console.log('Validated options:', options);\n  // Expected output: { name: 'Optimal Project', include: [], exclude: [], maxSize: 8000 }\n\n  const defaultOptions = schema.validate({});\n  console.log('Default options:', defaultOptions);\n  // Expected output: { name: 'Default Name', include: [], exclude: [], maxSize: 5000 }\n} catch (error) {\n  console.error('Validation failed:', error);\n}","lang":"typescript","description":"This quickstart demonstrates how to define a complex object schema using `optimal`, including primitive types, arrays, default values, and custom validation predicates, then validates input data.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}