$ show open-circle/valibot
Valibot is a modular, type-safe schema validation library for TypeScript with zero external dependencies. It provides a comprehensive set of schemas (string, number, object, array, union, etc.), validation actions (email, minLength, regex, etc.), transformation actions (toNumber, toUpperCase, parseJson, etc.), and composition methods (pipe, fallback, forward, cache). The library is tree-shakeable, supports both sync and async validation, and achieves 100% test coverage. Its architecture follows a consistent action/schema object pattern with a `~run` method for runtime validation and extensive TypeScript generics for type inference (InferInput, InferOutput, InferIssue). The repository is a monorepo containing the core library, a documentation website built with Qwik, a codemod for migrating from Zod to Valibot, a JSON Schema conversion package, and an i18n package for localized error messages. The primary entry point is `library/src/index.ts`, which re-exports all schemas, actions, methods, and utilities. Data flows involve defining schemas, optionally piping actions, and then calling `parse` or `safeParse` to validate input against the schema. The library implements the Standard Schema specification for interoperability.
The LLM identified 4 files worth highlighting for reuse:
A self-contained LRU cache implementation with configurable maxSize and maxAge. Uses a WeakMap for reference-based keying and a doubly-linked list for eviction ordering. Demonstrates a clean, reusable caching pattern that can be extracted into any TypeScript project requiring memoization with bounded memory.
A single-pass, char-code-based word splitter for converting strings between camelCase, PascalCase, snake_case, kebab-case, etc. Handles Unicode surrogate pairs correctly without regex. This is a high-performance, dependency-free utility that can be reused in any project needing case transformation.
The main entry point for a jscodeshift-based codemod that automatically migrates Zod schema definitions to Valibot. It handles imports, schema constructors, validation methods, and type inference. This is a standalone package demonstrating a reusable pattern for library migration tools, with clear separation of concerns (imports, schemas, methods, validators).
Converts Valibot schemas to JSON Schema (draft-07) using a recursive conversion context with reference caching. Supports input/output schemas and handles most Valibot types. This is a self-contained package that demonstrates a reusable schema-to-JSON-Schema conversion pattern, applicable to any validation library with a similar schema interface.