codetrix
Version:
A lightweight lodash-style utility library
35 lines (34 loc) • 1.49 kB
TypeScript
/**
* Maps common built-in validation errors to readable messages.
* Use this for client-side form validation feedback.
*
* @param errors - A dictionary of validation error keys and values.
* @param label - The field label for dynamic messages.
* @returns A human-readable error message or null.
*/
export declare function getBuiltInErrorMessage(errors: Record<string, any>, label?: string): string | null;
/**
* Maps custom validation errors to human-readable messages.
* Customize based on your business rules or regex checks.
*
* @param errors - A dictionary of validation error keys and values.
* @param label - The field label for dynamic messages.
* @returns A custom validation error message or null.
*/
export declare function getCustomErrorMessage(errors: Record<string, any>, label?: string): string | null;
/**
* Returns the first applicable error message from built-in or custom error maps.
*
* @param errors - Object containing validation errors.
* @param label - Label to use in error messages.
* @returns The first matched error message or null.
*/
export declare function getFirstErrorMessage(errors: Record<string, any>, label?: string): string | null;
/**
* Extracts all human-readable messages from the errors object.
*
* @param errors - The validation errors object.
* @param label - Optional field label.
* @returns An array of error messages.
*/
export declare function getAllErrorMessages(errors: Record<string, any>, label?: string): string[];