Files
hope-food-pantry-app/src/email.ts
T
blake f1a46e2ba7 feat: add volunteer shift signup app
Initial source, tests, migrations, and local Docker setup for the Hope Food Pantry volunteer scheduler.
2026-10-16 09:33:39 -05:00

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;
}