@@ -98,32 +98,29 @@ internals.String = class extends Any {
98
98
const patternObject = {
99
99
pattern : new RegExp ( pattern . source , pattern . ignoreCase ? 'i' : undefined ) // Future version should break this and forbid unsupported regex flags
100
100
} ;
101
- let patternIsInverted = false ;
102
101
103
102
if ( typeof patternOptions === 'string' ) {
104
103
patternObject . name = patternOptions ;
105
104
}
106
105
else if ( typeof patternOptions === 'object' ) {
107
- patternIsInverted = ! ! patternOptions . invert ;
108
- patternObject . invert = patternIsInverted ;
106
+ patternObject . invert = ! ! patternOptions . invert ;
109
107
110
108
if ( patternOptions . name ) {
111
109
patternObject . name = patternOptions . name ;
112
110
}
113
111
}
114
112
115
- const baseRegex = patternIsInverted ? 'string.regex.inverted' : 'string.regex.base' ;
116
- const nameRegex = patternIsInverted ? 'string.regex.invertedName' : 'string.regex.name' ;
113
+ const errorCode = [ 'string.regex' , patternObject . invert ? '.invert' : '' , patternObject . name ? '.name' : '.base' ] . join ( '' ) ;
117
114
118
115
return this . _test ( 'regex' , patternObject , function ( value , state , options ) {
119
116
120
117
const patternMatch = patternObject . pattern . test ( value ) ;
121
118
122
- if ( patternMatch ^ patternIsInverted ) {
119
+ if ( patternMatch ^ patternObject . invert ) {
123
120
return value ;
124
121
}
125
122
126
- return this . createError ( ( patternObject . name ? nameRegex : baseRegex ) , { name : patternObject . name , pattern, value } , state , options ) ;
123
+ return this . createError ( errorCode , { name : patternObject . name , pattern : patternObject . pattern , value } , state , options ) ;
127
124
} ) ;
128
125
}
129
126
0 commit comments