example param value param state const formatToRG = ( value , state ? ) : string => ( state !== 'RJ' && state !== 'SP' ) ? value : ( value . toUpperCase ( ) . replace ( /[^\d|A|B|X]/g , '' ) . replace ( /(\d{2})(\d)/ , '$1.$2' ) . replace ( /(\d{3})(\d)/ , '$1.$2' ) . replace ( /(\d{3})([\d|A|B|X]{1})$/ , '$1-$2' ) ) ; export default formatToRG ;