Tosijs-schema is a super lightweight schema-first LLM-native JSON schema library (www.npmjs.com)

🤖 AI Summary
Tosijs-schema is a new ultra‑lightweight, schema‑first TypeScript/JavaScript library that builds a single, standards‑compliant JSON Schema as the source of truth, infers TypeScript types automatically, and validates data with dramatic performance gains. It exposes a compact, property‑based API (e.g., s.string, s.email, s.array(...)), supports enums, unions, tuples, records, metadata for OpenAPI/Swagger, and a diff tool to spot breaking schema changes. Benchmarks claim raw validation is ~2x–3x faster than Zod and, when using its optimized "cheating" mode, yields orders‑of‑magnitude speedups (hundreds to 1,000x in some optimized comparisons) on very large arrays/dictionaries. The core technical innovation is "prime‑jump" sampling: for large arrays/dictionaries the validator checks a fixed sample (roughly 1%) so validation becomes O(1) regardless of size, returning a boolean by default and failing fast on the first error. For 100% guarantees, a fullScan option forces exhaustive checks; onError callbacks provide detailed diagnostics. Tosijs-schema is "LLM‑native"—objects are strict by default (required keys and additionalProperties:false) and the .schema property yields token‑efficient JSON Schema compatible with OpenAI/Anthropic structured outputs without adapters. Tradeoffs: some JSON Schema features (uniqueItems, dependencies) and recursive type inference are omitted, and maxProperties is only emitted for documentation (not enforced) to avoid O(N) costs. The package is tiny (~3KB minified) and MIT‑licensed.
Loading comments...
loading comments...