UNPKG

multiform-validator

Version:

Javascript library made to validate, several form fields, such as: email, images, phone, password, cpf etc.

34 lines (33 loc) 1.19 kB
import type { ValidateFunctions } from "./types"; interface OptionsParams { minLength?: number; maxLength?: number; cbValidate?: (username: string) => ValidateFunctions; errorMsg?: (string | null)[]; } /** * @param username * @param minLength optional * @param maxLength optional * @param cbValidate optional * @param errorMsg optional * @default minLength number: 1 * @default maxLength number: Infinity * @default cbValidate function: undefined * @info minLength cannot be greater than maxLength * @description This function returns 3 errors in the following order, * * If you want to use a default parameter, use null. * * Default: * [ "Username cannot be empty", "Username must be between ${maxLenthUsername} and ${maxLenthUsername} characters", "Username must be between ${maxLenthUsername} and ${maxLenthUsername} characters", ]; * * Create a list of errors separated by commas in strings * @returns An object with "isValid" (boolean) and "errorMsg" (string) properties. */ declare function validateUsername(username: string, { minLength, maxLength, cbValidate, errorMsg, }?: OptionsParams): ValidateFunctions; export default validateUsername;