export interface ICustomValidatorResponse { valid : boolean ; value ? : string | number | Record < any , any > | boolean | Array < any > ; error ? : CustomValidatorReponseTypes ; } export interface ICustomValidatorInput { input : string | number | Record < any , any > | boolean | Array < any > ; validationObject ? : ICustomValidatorInputObject ; } export interface ICustomValidatorInputObject { nullemptyundefined ? : boolean ; null ? : boolean ; undefined ? : boolean ; empty ? : boolean ; minlength ? : number ; maxlength ? : number ; tuemail ? : boolean ; } export enum CustomValidatorReponseTypes { NULLEMPTYUNDEFINED , NULL , UNDEFINED , EMPTY , MINLENGTH , MAXLENGTH } export const customValidator = ( input ) : ICustomValidatorResponse => { if ( typeof input . input !== "undefined" ) { const inputString = input . input . toString ( ) ; if ( input . validationObject === undefined ) { input . validationObject = { nullemptyundefined : true } ; } if ( input . validationObject . nullemptyundefined === undefined ) { input . validationObject . nullemptyundefined = true ; } if ( input . validationObject . nullemptyundefined && ( input . input === null || input . input === undefined || input . input === "" ) ) { return { valid : false , error : CustomValidatorReponseTypes . NULLEMPTYUNDEFINED , value : input . input } ; } else if ( input . validationObject . null && input . input === null ) { return { valid : false , error : CustomValidatorReponseTypes . NULL , value : input . input } ; } else if ( input . validationObject . undefined && input . input === undefined ) { return { valid : false , error : CustomValidatorReponseTypes . UNDEFINED , value : input . input } ; } else if ( input . validationObject . empty && input . input === "" ) { return { valid : false , error : CustomValidatorReponseTypes . EMPTY , value : input . input } ; } else if ( input . validationObject . minlength && input . validationObject . minlength > 0 && inputString . length < input . validationObject . minlength ) { return { valid : false , error : CustomValidatorReponseTypes . MINLENGTH , value : input . input } ; } else if ( input . validationObject . maxlength && input . validationObject . maxlength > 0 && inputString . length > input . validationObject . maxlength ) { return { valid : false , error : CustomValidatorReponseTypes . MAXLENGTH , value : input . input } ; } else { return { valid : true } ; } } else { return { valid : false , error : CustomValidatorReponseTypes . NULL , value : input . input } ; } } ; export const validateMultipleInputs = ( ... inputs ) : ICustomValidatorResponse => { for ( const input of inputs ) { const validationResult = customValidator ( input ) ; if ( ! validationResult . valid ) { return { valid : false , error : validationResult . error , value : validationResult . value } ; } } return { valid : true } ; } ;