@@ -160,13 +160,18 @@ function isLikelyInvalidName(name) {
160160
161161 const vowels = name . match ( / [ a e i o u ] / gi) || [ ] ;
162162 const vowelRatio = vowels . length / name . replace ( / \s / g, '' ) . length ;
163- if ( vowelRatio < 0.15 || vowelRatio > 0.6 ) score += 2 ;
163+ if ( vowelRatio < 0.15 || vowelRatio > 0.7 ) score += 2 ;
164164
165165 if ( / a s d f | q w e r | z x c v | h j k l / i. test ( name ) ) score += 3 ;
166166
167167 if ( / [ ^ a e i o u \s ] { 6 , } / i. test ( name ) ) score += 2 ;
168168
169- if ( / [ ^ a - z \s ' - ] / i. test ( name ) ) score += 2 ;
169+ if (
170+ / [ ^ a - z à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ ā ă ą ć č ď đ ē ė ę ě ğ ģ ī į ķ ĺ ļ ľ ł ń ņ ň ő œ ŕ ř ś ş š ţ ť ũ ū ů ű ų ź ż ž ș ț ə \s ' - ] / i. test (
171+ name
172+ )
173+ )
174+ score += 3 ;
170175
171176 const capsScore = checkCapitalization ( name ) ;
172177 score += capsScore ;
@@ -179,34 +184,37 @@ function checkCapitalization(name) {
179184
180185 let suspiciousPatterns = 0 ;
181186
182- const allLowercase = ! / [ A - Z ] / . test ( name ) ;
183-
184187 for ( const word of words ) {
185188 if ( word . length === 0 ) continue ;
186189
187- const capitals = ( word . match ( / [ A - Z ] / g) || [ ] ) . length ;
188-
189- if ( word . length > 2 && capitals === word . length ) {
190- suspiciousPatterns += 1 ;
190+ if ( / [ A - Z ] { 3 , } / . test ( word ) ) {
191+ suspiciousPatterns += 2 ;
191192 }
192193
193194 if ( word . length > 2 ) {
194- const randomCaps = / ^ [ a - z ] + [ A - Z ] [ a - z ] * [ A - Z ] | ^ [ A - Z ] [ a - z ] + [ A - Z ] [ a - z ] + [ A - Z ] / ;
195- const isException = / ^ ( M a ? c | O ' | D ' | D e | V a n | V o n | L a | L e | D i | D a ) [ A - Z ] / i . test ( word ) ;
196-
197- if ( randomCaps . test ( word ) && ! isException ) {
198- suspiciousPatterns += 1 ;
195+ const isException = / ^ ( m a ? c | o ' | d ' | d e | v a n | v o n | l a | l e | d i | d a ) [ A - Z ] / i . test (
196+ word
197+ ) ;
198+ if ( isException ) {
199+ return suspiciousPatterns ;
199200 }
200- }
201- }
202201
203- if ( ! allLowercase && words . length > 1 ) {
204- const hasLowercaseWord = words . some ( ( w ) => w . length > 2 && / ^ [ a - z ] + $ / . test ( w ) ) ;
205- const hasUppercaseWord = words . some ( ( w ) => w . length > 2 && / ^ [ A - Z ] + $ / . test ( w ) ) ;
206- const hasProperCaseWord = words . some ( ( w ) => / ^ [ A - Z ] [ a - z ] + $ / . test ( w ) ) ;
202+ const startsWithLowerCase = / ^ [ a - z ] / . test ( word ) ;
207203
208- if ( ( hasUppercaseWord && hasLowercaseWord ) || ( hasProperCaseWord && hasLowercaseWord ) ) {
209- suspiciousPatterns += 1 ;
204+ let transitions = 0 ;
205+ for ( let i = 1 ; i < word . length ; i ++ ) {
206+ const prevIsUpper = / [ A - Z ] / . test ( word [ i - 1 ] ) ;
207+ const currIsUpper = / [ A - Z ] / . test ( word [ i ] ) ;
208+ if ( prevIsUpper !== currIsUpper ) {
209+ transitions ++ ;
210+ }
211+ }
212+
213+ if ( startsWithLowerCase && transitions > 0 ) {
214+ suspiciousPatterns += 3 ;
215+ } else if ( ! startsWithLowerCase && transitions > 2 ) {
216+ suspiciousPatterns += 3 ;
217+ }
210218 }
211219 }
212220
0 commit comments