import { build as buildError } from "../errorBuilder" ; import { errorStatusCode } from "../errorStatusCode" ; export const validDnsRegex = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/ ; param segment export const containsValidCharacters = ( segment ) : boolean => { return ! ! segment . match ( /^[0-9a-z-.]+$/ ) ; } ; param dns export const isValid = ( dns ) : boolean => { return ! ! dns . match ( validDnsRegex ) ; } ; param dns export const replaceIllegalCharacters = ( dns ) : string => { return dns . toLowerCase ( ) . replace ( /[^0-9a-z-.]/g , "-" ) ; } ; throws params params export function assertIsValid ( fieldName , dns ) { if ( ! isValid ( dns ) ) { throw buildError ( errorStatusCode . VALIDATION_ERR , { errorKey : "validation-err-rfc1123-compliant" , values : [ fieldName , dns , validDnsRegex . toString ( ) ] , } ) ; } }