Initial source, tests, migrations, and local Docker setup for the Hope Food Pantry volunteer scheduler.
22 lines
598 B
TypeScript
22 lines
598 B
TypeScript
export class EmailAddressError extends Error {
|
|
constructor(message: string) {
|
|
super(message);
|
|
this.name = 'EmailAddressError';
|
|
}
|
|
}
|
|
|
|
/** Trim, Unicode normalize, and lowercase. Dots and plus-tags are kept. */
|
|
export function normalizeEmail(input: string): string {
|
|
const normalized = input.normalize('NFC').trim().toLowerCase();
|
|
if (
|
|
normalized.length === 0 ||
|
|
/\s/.test(normalized) ||
|
|
!normalized.includes('@') ||
|
|
normalized.startsWith('@') ||
|
|
normalized.endsWith('@')
|
|
) {
|
|
throw new EmailAddressError('Enter an email address.');
|
|
}
|
|
return normalized;
|
|
}
|