import { CommonValidatorBuilderImpl , StringValidationOptionsBuilder , StringValidatorBuilder , ValidationOptionsBuilder } from "./" ; import { ValidationRule , WhenNotEmptyCondition } from "../validation" ; import { AlphaLocale , AlphanumericLocale , CurrencyOptions , EmailOptions , FqdnOptions , MobilePhoneLocale , PostalCodeLocale , UrlOptions , UuidVersion } from "../shared" ; import { PropertyValidator } from "../validators/PropertyValidator" ; import { ContainsValidator , HasLengthValidator , IsAlphanumericValidator , IsAlphaValidator , IsAsciiValidator , IsBase64Validator , IsBooleanStringValidator , IsCurrencyValidator , IsDecimalStringValidator , IsEmailValidator , IsFqdnValidator , IsHexadecimalValidator , IsIso8601Validator , IsJsonValidator , IsLowercaseValidator , IsMobilePhoneValidator , IsNumericStringValidator , IsPostalCodeValidator , IsUppercaseValidator , IsUrlValidator , IsUuidValidator , RegExValidator } from "../validators/string-based" ; import { IsLatLongValidator } from "../validators/string-based/IsLatLongValidator" ; export class StringValidatorBuilderImpl < T > extends CommonValidatorBuilderImpl < T , string > implements StringValidatorBuilder < T > , StringValidationOptionsBuilder < T > { constructor ( validationRule ) { super ( validationRule ) ; } private buildRuleWith ( validator ) { this . validationRule . addValidator ( validator ) ; return this ; } whenNotEmpty ( ) { this . validationRule . addCondition ( new WhenNotEmptyCondition ( this . validationRule . lambdaExpression ) ) ; return this ; } isBooleanString ( ) { return this . buildRuleWith ( new IsBooleanStringValidator ( ) ) ; } isNumericString ( ) { return this . buildRuleWith ( new IsNumericStringValidator ( ) ) ; } isAlpha ( locale ? ) { return this . buildRuleWith ( new IsAlphaValidator ( locale ) ) ; } isAlphanumeric ( locale ? ) { return this . buildRuleWith ( new IsAlphanumericValidator ( locale ) ) ; } contains ( seed ) { return this . buildRuleWith ( new ContainsValidator ( seed ) ) ; } isAscii ( ) { return this . buildRuleWith ( new IsAsciiValidator ( ) ) ; } isBase64 ( ) { return this . buildRuleWith ( new IsBase64Validator ( ) ) ; } isCurrency ( options ? ) { return this . buildRuleWith ( new IsCurrencyValidator ( options ) ) ; } isDecimalString ( ) { return this . buildRuleWith ( new IsDecimalStringValidator ( ) ) ; } isEmail ( options ? ) { return this . buildRuleWith ( new IsEmailValidator ( options ) ) ; } isFqdn ( options ? ) { return this . buildRuleWith ( new IsFqdnValidator ( options ) ) ; } isHexadecimal ( ) { return this . buildRuleWith ( new IsHexadecimalValidator ( ) ) ; } isIso8601 ( ) { return this . buildRuleWith ( new IsIso8601Validator ( ) ) ; } isJson ( ) { return this . buildRuleWith ( new IsJsonValidator ( ) ) ; } isPostalCode ( locale ) { return this . buildRuleWith ( new IsPostalCodeValidator ( locale ) ) ; } hasLength ( length ) { return this . buildRuleWith ( new HasLengthValidator ( { min : length , max : length } ) ) ; } hasLengthBetween ( min , max ) { return this . buildRuleWith ( new HasLengthValidator ( { min : min , max : max } ) ) ; } hasMinLength ( min ) { return this . buildRuleWith ( new HasLengthValidator ( { min : min } ) ) ; } hasMaxLength ( max ) { return this . buildRuleWith ( new HasLengthValidator ( { max : max } ) ) ; } isLatLong ( ) { return this . buildRuleWith ( new IsLatLongValidator ( ) ) ; } isLowercase ( ) { return this . buildRuleWith ( new IsLowercaseValidator ( ) ) ; } isMobilePhoneNo ( locale ) { return this . buildRuleWith ( new IsMobilePhoneValidator ( locale ) ) ; } isUppercase ( ) { return this . buildRuleWith ( new IsUppercaseValidator ( ) ) ; } isUrl ( options ? ) { return this . buildRuleWith ( new IsUrlValidator ( options ) ) ; } isUuid ( version ? ) { return this . buildRuleWith ( new IsUuidValidator ( version ) ) ; } matches ( pattern , modifiers ? ) { return this . buildRuleWith ( new RegExValidator ( pattern , modifiers ) ) ; } }