refactor: replace ignored numeric literals with constants
This commit is contained in:
@@ -7,6 +7,9 @@ import {
|
||||
ValidatorConstraint,
|
||||
} from 'class-validator';
|
||||
|
||||
const EMAIL_PART_COUNT = 2;
|
||||
const FIRST_CHARACTER_INDEX = 0;
|
||||
|
||||
const MAX_EMAIL_LENGTH = 254;
|
||||
const ASCII_SPACE = 32;
|
||||
const ASCII_DELETE = 127;
|
||||
@@ -19,14 +22,14 @@ class EmailConstraint {
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
value.length <= MAX_EMAIL_LENGTH &&
|
||||
value.split('@').length === 2 &&
|
||||
value.split('@').length === EMAIL_PART_COUNT &&
|
||||
!value
|
||||
.split('')
|
||||
.some(
|
||||
(character) =>
|
||||
/\s/.test(character) ||
|
||||
character.charCodeAt(0) < ASCII_SPACE ||
|
||||
character.charCodeAt(0) === ASCII_DELETE,
|
||||
character.charCodeAt(FIRST_CHARACTER_INDEX) < ASCII_SPACE ||
|
||||
character.charCodeAt(FIRST_CHARACTER_INDEX) === ASCII_DELETE,
|
||||
) &&
|
||||
value.split('@').every(Boolean)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user