UNPKG

@dbs-portal/core-api

Version:

HTTP client and API utilities for DBS Portal

129 lines 3.09 kB
/** * Validation utilities for mock handlers */ /** * Validation result */ export interface ValidationResult { isValid: boolean; errors: string[]; } /** * Field validation rules */ export interface ValidationRule { field: string; rules: Array<{ type: 'required' | 'email' | 'minLength' | 'maxLength' | 'pattern' | 'custom'; value?: any; message?: string; validator?: (value: any) => boolean; }>; } /** * Validate required field */ export declare function validateRequired(value: any, fieldName: string): string | null; /** * Validate email format */ export declare function validateEmail(value: string, fieldName?: string): string | null; /** * Validate minimum length */ export declare function validateMinLength(value: string, minLength: number, fieldName: string): string | null; /** * Validate maximum length */ export declare function validateMaxLength(value: string, maxLength: number, fieldName: string): string | null; /** * Validate pattern */ export declare function validatePattern(value: string, pattern: RegExp, fieldName: string, message?: string): string | null; /** * Validate object against rules */ export declare function validateObject(data: Record<string, any>, rules: ValidationRule[]): ValidationResult; /** * Common validation rule sets */ export declare const commonValidationRules: { /** * User registration validation */ userRegistration: ({ field: string; rules: ({ type: "required"; } | { type: "email"; })[]; } | { field: string; rules: ({ type: "required"; value?: never; message?: never; } | { type: "minLength"; value: number; message: string; })[]; } | { field: string; rules: ({ type: "required"; value?: never; } | { type: "maxLength"; value: number; })[]; })[]; /** * Login validation */ login: { field: string; rules: ({ type: "required"; } | { type: "email"; })[]; }[]; /** * Profile update validation */ profileUpdate: ({ field: string; rules: { type: "maxLength"; value: number; }[]; } | { field: string; rules: { type: "email"; }[]; })[]; }; /** * Create a validator function from rules */ export declare function createValidator(rules: ValidationRule[]): (data: Record<string, any>) => string[]; /** * Validate file upload */ export declare function validateFileUpload(file: { name: string; size: number; type: string; }, options?: { maxSize?: number; allowedTypes?: string[]; allowedExtensions?: string[]; }): ValidationResult; /** * Sanitize input data */ export declare function sanitizeInput(data: Record<string, any>): Record<string, any>; //# sourceMappingURL=validation.d.ts.map