-
Notifications
You must be signed in to change notification settings - Fork 0
sanitize
awekrx edited this page May 29, 2026
·
1 revision
import { sanitize } from '@dev-suite/decorators/sanitize'
parameter
Sanitize unsafe text input before business handling.
- Inline regex sanitation blocks
- Scattered content-cleanup utilities
class CommentService {
post(text: string) {
const sanitized = text.replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, '');
return this.repo.save(sanitized);
}
}import { sanitize } from '@dev-suite/decorators/sanitize';
class CommentService {
post(@sanitize() text: string) {
return this.repo.save(text);
}
}- Centralizes cross-cutting behavior.
- Method/class/property code stays focused on domain logic.
class ProfileService {
setBio(bio: string) {
const clean = bio.replace(/[<>]/g, '');
return this.repo.setBio(clean);
}
}import { sanitize } from '@dev-suite/decorators/sanitize';
class ProfileService {
setBio(@sanitize({ replacement: '' }) bio: string) {
return this.repo.setBio(bio);
}
}- Second scenario reuses same policy without duplication.
- Behavior is more consistent and easier to audit.