-
Notifications
You must be signed in to change notification settings - Fork 0
email param
awekrx edited this page May 29, 2026
·
1 revision
import { emailParam } from '@dev-suite/decorators/email-param'
parameter
Validate and normalize email argument before use.
- Regex validation inside each method
- Manual trim/lowercase boilerplate
class InviteService {
send(email: string) {
const normalized = email.trim().toLowerCase();
if (!/^[^@]+@[^@]+\.[^@]+$/.test(normalized)) throw new Error('Invalid email');
return this.mailer.send(normalized);
}
}import { emailParam } from '@dev-suite/decorators/email-param';
class InviteService {
send(@emailParam({ normalize: true }) email: string) {
return this.mailer.send(email);
}
}- Centralizes cross-cutting behavior.
- Method/class/property code stays focused on domain logic.
class AuthService {
resetPassword(email: string) {
if (!email.includes('@')) throw new Error('Bad email');
return this.tokens.issue(email.toLowerCase());
}
}import { emailParam } from '@dev-suite/decorators/email-param';
class AuthService {
resetPassword(@emailParam() email: string) {
return this.tokens.issue(email);
}
}- Second scenario reuses same policy without duplication.
- Behavior is more consistent and easier to audit.