UNPKG

@cobuildlab/validation-utils

Version:

This is package to deal with common scenarios working with Javascript validations

103 lines (102 loc) 3.87 kB
export * from './error'; /** * Validate if a value is `null` or `undefined`. * * @param value - The Value to test. * @returns If a value is `null` or `undefined`. */ export declare const isNullOrUndefined: (value?: any) => boolean; /** * Validate if a value is a valid string or not. * * @param value - The value to validate. * @param allowEmpty - [allowEmpty=false] If a empty string should be valid * or not. * @param size - [size=undefined] The maximum size of the string. * @returns If the string is valid or not. */ export declare const isValidString: (value?: any, allowEmpty?: boolean, size?: number | undefined) => boolean; /** * Validate if the provided string is a valid email address. * * @param email - String to validate as email. * @returns Wether an email is valid or not. */ export declare const isValidEmail: (email: string) => boolean; /** * Validate if a string is a valid number. * * @param stringToTest - The string to validate as a number. * @param allowZero - [allowZero=false] If the string should accept 0 as a valid number. * @param allowNegative - [allowNegative=false] If the string should negative values. * * @returns If the string is valid number or not. */ export declare const isValidNumber: (stringToTest: string, allowZero?: boolean, allowNegative?: boolean) => boolean; /** * Validate if a number is a valid integer. * * @param numberToTest - The number to validate as integer. * @param allowZero - [allowZero=false] If the number should accept 0 as a valid number. * @param allowNegative - [allowNegative=false] If the number should negative values. * * @returns If the number is a valid integer. */ export declare const isValidInteger: (numberToTest: number, allowZero?: boolean, allowNegative?: boolean) => boolean; /** * Validate if the provided string is a valid Date. * * @param date - String date. * @param format - The format with wich the date is going to be * processed. * * @returns Is valid date. */ export declare const isValidDate: (date: string, format?: string | undefined) => boolean; declare type FileValue = { id?: string; fileId: string; filename: string; mimetype?: string; download_Url?: string; }; /** * Validate if a file has a valid type/extension based on a array of valid * types. * * @param file - The file to validate. * @param validTypes - Array of valid types. * @returns If the file is valid or not. */ export declare const isValidFileType: (file: FileValue, validTypes: string[]) => boolean; /** * Validate if the provided string is a valid phone number. * * @param {string} number - Phone number to validate. * @returns {boolean} Is valid or not. */ export declare const isValidPhoneNumber: (number: string) => boolean; /** * Validates that the string provided is not larger that the max value. * * @example ("someString", 3) => Error // 3 was provided, so this function will throw an error. * @example ("someOtherString", 20) => true // 20 was provided, the function will return true. * * @param {string} string - String to limit. * @param {number} max - Maximum boundary. * @returns {boolean} If the string length is lower that max. */ export declare const validateStringLength: (string: string, max: number) => boolean; /** * Validates a standardized name string. * * @example ("Gabriel", 0, 7) => true // This is a valid name with length 7. * @example ("John", 2, 3) => Error // John is 4 characters long. * @example ("童阮", 1, 5) => Error // Contains non-standardized characters. * * @param {string} name - Name to check. * @param {number} minLength - Minimum boundary. * @param {number} maxLength - Maximum boundary. * @returns {boolean} If the name is valid and matches given criteria. */ export declare const isValidName: (name: string, minLength: number, maxLength: number) => boolean;