ts-valid8
Version:
A next-generation TypeScript validation library with advanced features
35 lines • 1.33 kB
TypeScript
/**
* Error Utilities for Valid8
*
* Functions for working with and formatting validation errors
*/
import { ValidationError } from '../core/types';
/**
* Format validation errors into a nested object structure
* This is useful for displaying errors in forms
*/
export declare function formatErrors(errors: ValidationError[]): Record<string, any>;
/**
* Format errors as a flat map (easier for simple UIs)
* Result is a map from 'path.to.field' to error message
*/
export declare function formatErrorsFlat(errors: ValidationError[]): Record<string, string>;
/**
* Group errors by error code
* Useful for categorizing errors by type
*/
export declare function groupErrorsByCode(errors: ValidationError[]): Record<string, ValidationError[]>;
/**
* Get the first error message for each path
* Useful for displaying just the first error per field
*/
export declare function getFirstErrors(errors: ValidationError[]): Record<string, string>;
/**
* Create a custom error with a specific format
*/
export declare function createValidationError(code: string, message: string, path?: string[], params?: Record<string, any>): ValidationError;
/**
* Extract all error messages into a flat array
*/
export declare function extractErrorMessages(errors: ValidationError[]): string[];
//# sourceMappingURL=errors.d.ts.map