Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 35x 283x 289x 289x 6x 283x 283x | import { InvalidEmailError } from './errors/invalid-email.error';
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
export class Email {
private constructor(private readonly value: string) {}
static create(raw: string): Email {
const normalized = raw.trim().toLowerCase();
if (!EMAIL_REGEX.test(normalized)) {
throw new InvalidEmailError(raw);
}
return new Email(normalized);
}
toString(): string {
return this.value;
}
}
|