Production-grade TypeScript-first validation framework with class-validator style decorators
π GitHub: https://github.com/TQTuyen/Valora
π¦ npm: https://www.npmjs.com/package/@tqtos/valora
A modern, tree-shakeable validation framework for JavaScript/TypeScript with dual APIs: elegant class decorators and chainable fluent validators.
- π¨ Class-Validator Style Decorators - Familiar, elegant validation syntax with 63+ decorators
- π Fluent Chainable API -
v.string().email().minLength(5)for schema-based validation - π³ Tree-Shakeable - Import only what you need, zero unused code
- ποΈ SOLID Architecture - Built with 6 GoF design patterns for maintainability
- π i18n Support - English & Vietnamese built-in, easily extensible
- π Type-Safe - Full TypeScript inference with
Infer<T> - π― Framework Agnostic - Core works everywhere
- π¨ Framework Adapters - React, Vue, Svelte, Solid, Vanilla JS
- β‘ Production-Ready - Comprehensive test coverage
# Using bun (recommended)
bun add @tqtos/valora
# Using npm
npm install @tqtos/valora
# Using yarn
yarn add @tqtos/valora
# Using pnpm
pnpm add @tqtos/valoraPerfect for validating class instances, DTOs, and domain models.
import { Validate, IsString, IsEmail, MinLength, Min, IsNumber } from '@tqtos/valora/decorators';
@Validate()
class CreateUserDto {
@IsString()
@MinLength(2, { message: 'Name must be at least 2 characters' })
name: string;
@IsEmail()
email: string;
@IsNumber()
@Min(18)
age: number;
}
// Auto-validates on construction!
try {
const user = new CreateUserDto({
name: 'John Doe',
email: 'john@example.com',
age: 25,
});
console.log('Valid user:', user);
} catch (error) {
console.error('Validation error:', error.message);
}Perfect for validating data, API requests, and configuration.
import { v, Infer } from '@tqtos/valora';
// Define schema
const createUserSchema = v.object({
name: v.string().minLength(2),
email: v.string().email(),
age: v.number().min(18).optional(),
});
// Infer TypeScript type
type CreateUserDto = Infer<typeof createUserSchema>;
// Validate data
const result = createUserSchema.validate({
name: 'John Doe',
email: 'john@example.com',
age: 25,
});
if (result.success) {
console.log('Valid data:', result.data); // Fully typed!
} else {
console.error('Validation errors:', result.errors);
}Complete guides for learning and reference:
- Getting Started - Installation, first steps, and basic patterns
- Decorators Guide - Complete reference for all 63 decorators
- Validators Guide - Fluent API reference and schema validation
- Nested Validation - Working with nested objects and arrays
- Advanced Usage - Custom validators, i18n, async validation, and more
- Examples - Real-world use cases and patterns
- API Reference - Complete API documentation
- Migration Guide - Upgrading from legacy decorators
@IsOptional() @IsRequired()
@IsString() @IsEmail() @IsUrl() @IsUuid() @MinLength() @MaxLength() @Length() @Matches() @StartsWith() @EndsWith() @Contains() @IsAlpha() @IsAlphanumeric() @IsNumeric() @IsLowercase() @IsUppercase() @NotEmpty()
@IsNumber() @IsInt() @IsFinite() @IsSafeInt() @Min() @Max() @Range() @IsPositive() @IsNegative() @IsMultipleOf()
@IsBoolean() @IsTrue() @IsFalse()
@IsDate() @MinDate() @MaxDate() @IsPast() @IsFuture() @IsToday() @IsBefore() @IsAfter() @IsWeekday() @IsWeekend() @MinAge() @MaxAge()
@IsArray() @ArrayMinSize() @ArrayMaxSize() @ArrayLength() @ArrayNotEmpty() @ArrayUnique() @ArrayContains()
@IsObject() @ValidateNested()
- String -
email(),url(),uuid(),minLength(),maxLength(),matches(), etc. - Number -
min(),max(),range(),positive(),integer(),finite(), etc. - Date -
past(),future(),minAge(),maxAge(),weekday(),weekend(), etc. - Array -
of(),min(),max(),unique(),contains(),every(),some(), etc. - Object -
shape(),partial(),pick(),omit(),strict(),passthrough(), etc. - Boolean -
true(),false(),required() - File -
maxSize(),mimeType(),extension(),dimensions() - Business -
creditCard(),phone(),iban(),ssn(),slug() - Async -
async(),debounce(),timeout(),retry() - Logic -
and(),or(),not(),union(),intersection(),ifThenElse()
Built-in support for English and Vietnamese, easily extensible:
import { globalI18n } from '@tqtos/valora/plugins';
// Switch to Vietnamese
globalI18n.setLocale('vi');
// Add custom locale
globalI18n.loadLocale('fr', {
string: {
required: 'Ce champ est obligatoire',
email: 'Adresse email invalide',
},
});import { useValora } from '@tqtos/valora/adapters/react';
export function LoginForm() {
const { validate, errors } = useValora();
return (
<form>
<input placeholder="Email" onBlur={(e) => validate('email', e.target.value)} />
{errors.email && <span>{errors.email}</span>}
</form>
);
}<script setup>
import { useValora } from '@tqtos/valora/adapters/vue';
const { validate, errors } = useValora();
</script>
<template>
<input placeholder="Email" @blur="validate('email', $event.target.value)" />
<span v-if="errors.email">{{ errors.email }}</span>
</template>valora/
βββ src/
β βββ core/ # Validation engine & design patterns
β βββ decorators/ # Class-validator style decorators
β βββ validators/ # Fluent validators (string, number, date, etc.)
β βββ adapters/ # Framework integrations (React, Vue, Svelte, etc.)
β βββ plugins/ # i18n, logger, cache, transform, devtools
β βββ schema/ # Schema builder & coercion
β βββ notification/ # Event notification system
β βββ utils/ # Utility functions
β βββ types/ # TypeScript type definitions
βββ tests/ # Test files (unit, integration, e2e)
βββ examples/ # Framework-specific examples
βββ docs/ # Comprehensive documentation
βββ dist/ # Build output (generated)
# Development
bun run dev # Watch mode build
bun run build # Production build with type checking
bun run typecheck # Type check only
# Testing
bun run test # Run tests in watch mode
bun run test:run # Run tests once
bun run test:coverage # Run tests with coverage report
bun run test:ui # Run tests with UI
# Code Quality
bun run lint # Lint source code
bun run lint:fix # Lint and auto-fix issues
bun run format # Format code with Prettier
bun run format:check # Check formatting without changes
# Maintenance
bun run clean # Remove dist/ directoryValora is built with SOLID principles and implements 6 Gang of Four design patterns:
- Strategy Pattern - Pluggable validation strategies
- Chain of Responsibility - Validation pipeline
- Observer Pattern - Event notifications
- Factory Pattern - Validator creation
- Decorator Pattern - Validator composition
- Composite Pattern - Nested validation
Full TypeScript support with:
- Strict mode enabled
- Explicit return types
- Type inference with
Infer<T> - Path aliases support (
@/,@validators/, etc.)
import { v, Infer } from '@tqtos/valora';
const userSchema = v.object({
name: v.string(),
age: v.number().optional(),
});
type User = Infer<typeof userSchema>;
// type User = { name: string; age?: number }Tests use Vitest with:
- 70% minimum coverage threshold
- v8 coverage provider
- Type checking enabled
- Both unit and integration tests
- Create a feature branch:
git checkout -b feat/my-feature - Make your changes following the code conventions
- Run tests:
bun run test - Run linter:
bun run lint:fix - Format code:
bun run format - Commit:
git commit -m "feat: add my feature"
- Variables/Functions:
camelCase - Classes/Interfaces/Types:
PascalCase - Constants:
UPPER_SNAKE_CASE - Files:
kebab-case.tsfor modules
- Prefer
interfacefor object shapes - Use
typefor unions and utility types - Import types with
import type {} - No
anytypes without justification - Explicit return types on public functions
- Install Bun (https://bun.sh)
- Clone the repository
- Run
bun install - Run
bun run devto start watch mode - Check
.claude/CLAUDE.mdfor project guidelines
MIT Β© Valora Team
Built with TypeScript, Vite, and Vitest