tjs - A JSON Schema validator library with TypeScript type inference.
npm test- Run all tests (type tests)npm run test:types- Run type tests onlynpm run build- Build the project
src/- Source codeindex.ts- Main entry point, exportsschema()functioninfer.ts- TypeScript type inference from JSON Schematypes.ts- Core type definitions
tests/types/- Type-level tests (.test-d.tsfiles)dist/- Built output
- Type tests use the
Expect<Equal<...>>pattern for compile-time assertions - The
schema()function returns aValidator<T>where T is inferred from the schema - Run
npm testto verify type inference is working correctly - When creating debug test files, use
/private/tmp/debug.jsinstead of files in the project directory - Use Write tool to create files instead of cat/heredoc in Bash
When making API changes, always update README.md to reflect the current API:
schema(definition, options?)- Creates a validator from JSON Schemastruct(properties, options?)- Ergonomic helper for object schemasschemaAsync(definition, options?)- Async version that fetches remote $refs
validator.validate(data)- Returns{ value: T, error: undefined }on success,{ value: undefined, error: ValidationError[] }on failurevalidator.assert(data)- Returns typed valueTon success, throws on failurevalidator.type- Phantom property for type inference (typeof validator.type)validator.schema- The JSON Schema definition, can be used for schema composition
- There is NO
.parse()method - use.assert()for throwing validation or.validate()for result-based .validate()returns an object{ value, error }, NOT a boolean- ALWAYS use src/claude-debug.js for any scratch work. do not use heredocs or shell scripts or cat commands.
When testing performance:
- Full benchmark:
npm run bench:tjsandnpm run bench:schemasafe - Micro benchmark with filter:
npm run bench -- draft7 --filter pattern -v tjs(use this for testing specific groups) - Comparison report:
npx tsx benchmarks/generate-report.ts schemasafe - Filter regex examples:
--filter "pattern|format",--filter "oneOf"
Always use the official benchmark tool with --filter for micro benchmarks, not custom scripts.