Search for a command to run...
Last updated June 9, 2026
Ctrovalidate is built with TypeScript from the ground up. This page documents the core types that are shared across all packages.
ValidationSchemaMaps field names to their validation rules.
type ValidationSchema = Record<string, SchemaRule>;SchemaRuleA single field's rule definition. Can be a string or an array of strings and/or RuleDefinition objects.
type SchemaRule = string | (string | RuleDefinition)[];RuleDefinitionThe normalized representation of a parsed rule.
interface RuleDefinition {
name: string;
params: unknown[];
}DependencyDefinitionDefines a cross-field dependency for conditional validation (used by the browser adapter).
interface DependencyDefinition {
controllerName: string;
type: 'checked' | 'value' | 'present' | string;
value?: unknown;
}ValidationResultReturned after executing a validation rule or full schema.
interface ValidationResult {
isValid: boolean;
error: string | null;
rule: string | null;
}ValidationOptionsConfiguration passed to validation functions.
interface ValidationOptions {
customRules?: Record<string, RuleLogic | AsyncRuleLogic>;
aliases?: Record<string, SchemaRule>;
messages?: Record<string, string>;
locale?: string;
signal?: AbortSignal;
}RuleLogic<Context>Signature for synchronous validation rules.
type RuleLogic<Context = unknown> = (
value: unknown,
params?: unknown[],
context?: Context | null
) => boolean;Context parameter defaults to unknown. In ctrovalidate-browser, this is HTMLElement.true for valid, false for invalid.AsyncRuleLogic<Context>Signature for asynchronous validation rules.
type AsyncRuleLogic<Context = unknown> = (
value: unknown,
params?: unknown[],
context?: Context | null,
signal?: AbortSignal
) => Promise<boolean>;RuleLogic but returns Promise<boolean> and accepts an optional AbortSignal.CtrovalidateOptionsConfiguration for the browser Ctrovalidate constructor.
interface CtrovalidateOptions {
logLevel?: number;
errorClass?: string;
errorMessageClass?: string;
pendingClass?: string;
realTime?: boolean;
schema?: ValidationSchema;
aliases?: Record<string, SchemaRule>;
}| Option | Type | Default |
|---|---|---|
logLevel | number | LogLevel.NONE (0) |
errorClass | string | 'is-invalid' |
errorMessageClass | string | 'error-message' |
pendingClass | string | 'ctrovalidate-pending' |
realTime | boolean | true |
schema | ValidationSchema | {} |
aliases | Record<string, SchemaRule> | {} |
FieldStateInternal state tracked per field in the browser controller.
interface FieldState {
isDirty: boolean;
abortController: AbortController | null;
lastError: string | null;
}FieldObjectFull internal representation of a tracked field.
interface FieldObject {
element: HTMLElement;
rules: RuleDefinition[];
state: FieldState;
dependency: DependencyDefinition | null;
customMessages?: Record<string, string>;
listeners?: {
onBlur: (e: Event) => void;
onInput: (e: Event) => void;
onControllerInput: ((e: Event) => void) | null;
controllerElement: HTMLElement | null;
};
}interface UseCtrovalidateOptions<T extends object> {
schema: ValidationSchema;
initialValues?: T;
validateOnBlur?: boolean;
customRules?: Record<string, RuleLogic | AsyncRuleLogic>;
aliases?: Record<string, SchemaRule>;
messages?: Record<string, string>;
locale?: string;
}
interface UseCtrovalidateReturn<T extends object> {
values: T;
errors: Partial<Record<keyof T, string>>;
isDirty: Partial<Record<keyof T, boolean>>;
isValidating: Partial<Record<keyof T, boolean>>;
handleChange: (name: keyof T, value: T[keyof T]) => void;
handleBlur: (name: keyof T) => void;
validateField: (name: keyof T, value?: T[keyof T]) => Promise<boolean>;
validateForm: () => Promise<boolean>;
reset: (newValues?: Partial<T>) => void;
}interface UseCtrovalidateOptions<T extends object> {
schema: ValidationSchema;
initialValues?: T;
validateOnBlur?: boolean;
validateOnChange?: boolean;
customRules?: Record<string, RuleLogic | AsyncRuleLogic>;
aliases?: Record<string, SchemaRule>;
messages?: Record<string, string>;
locale?: string;
}
interface UseCtrovalidateReturn<T extends object> {
values: T; // reactive
errors: Record<keyof T, string | undefined>; // reactive
isDirty: Record<keyof T, boolean>; // reactive
isValidating: Record<keyof T, boolean>; // reactive
isValid: boolean; // ref
validateField: (name: keyof T) => Promise<boolean>;
validateForm: () => Promise<boolean>;
reset: (newValues?: Partial<T>) => void;
handleChange: (name: keyof T, value: T[keyof T]) => void;
handleBlur: (name: keyof T) => void;
}// Return stores:
values: Writable<T>
errors: Writable<Partial<Record<keyof T, string>>>
isDirty: Writable<Partial<Record<keyof T, boolean>>>
isValidating: Writable<Partial<Record<keyof T, boolean>>>
isValid: Readable<boolean> // derived storekeyof T when defining schemas for specific data interfaces.ctrovalidate-core and are re-exported by adapter packages.ctrovalidate-browser, the Context generic is HTMLElement, giving rules access to the DOM element.