@hunterstack/typebox-helpers
v0.0.5
Published
Tree shakable typebox helper utilities
Downloads
976
Maintainers
Readme
TypeBox Helpers
A collection of tree-shakable TypeBox helper utilities to make working with TypeBox even easier.
Installation
npm install @hunterstack/typebox-helpersFeatures
- Tree-shakable utilities
- Type-safe helpers
- Zero dependencies (except TypeBox)
Usage
UnionOf
Create TypeBox union types from any literal values (strings, numbers, booleans) with full type safety:
import { UnionOf } from '@hunterstack/typebox-helpers'
const Status = UnionOf(['active', 'inactive', 'pending'])
// TUnion<[TLiteral<"active">, TLiteral<"inactive">, TLiteral<"pending">]>
const Numbers = UnionOf([1, 2, 3, 4, 5])
// TUnion<[TLiteral<1>, TLiteral<2>, TLiteral<3>, TLiteral<4>, TLiteral<5>]>
const Mixed = UnionOf([1, 'red', true])
// TUnion<[TLiteral<1>, TLiteral<"red">, TLiteral<true>]>Testing
This package is thoroughly tested with a comprehensive approach:
Runtime Tests
- Vitest for runtime validation testing
- Tests ensure schemas correctly validate expected values and reject invalid ones
- Integration tests with frameworks like Elysia
- Covers all literal types: strings, numbers, booleans, and mixed unions
Type Tests
- @ark/attest for type inference checking performance
- Ensures TypeScript types are correctly inferred
- Validates that generated schemas match expected TypeBox types
- Prevents type regressions and ensures full type safety
Benchmarks
- Performance benchmarks using @ark/attest
- Monitors schema creation and validation performance
- Automated performance regression detection
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run benchmarks
npm run benchDevelopment
# Install dependencies
npm install
# Run tests
npm test
# Run benchmarks
npm run bench
# Build
npm run buildLicense
MIT
