Files
blackheart-website/src/lib/validation.ts
diana.dolgolyova b1adbbfe3d fix: MEDIUM priority — shared validation, content caching, Schedule useReducer, stable keys
- Extract shared sanitization to src/lib/validation.ts, apply to all 3 registration routes (#2)
- Replace key={index} with stable keys in About and News (#4)
- Add 5-min in-memory content cache in content.ts, invalidate on admin section save (#6)
- Refactor Schedule from 8 useState calls to useReducer — single dispatch, fewer re-renders (#8)
- Remove Hero scroll indicator, add auto-scroll to next section on wheel/swipe

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 14:17:24 +03:00

28 lines
918 B
TypeScript

/**
* Shared input sanitization for public registration endpoints.
*/
export function sanitizeName(name: unknown): string | null {
if (!name || typeof name !== "string") return null;
const clean = name.trim().slice(0, 100);
return clean || null;
}
export function sanitizePhone(phone: unknown): string | null {
if (!phone || typeof phone !== "string") return null;
const clean = phone.replace(/\D/g, "").slice(0, 15);
return clean.length >= 9 ? clean : null;
}
export function sanitizeHandle(value: unknown): string | undefined {
if (!value || typeof value !== "string") return undefined;
const clean = value.trim().slice(0, 100);
return clean || undefined;
}
export function sanitizeText(value: unknown, maxLength: number = 200): string | undefined {
if (!value || typeof value !== "string") return undefined;
const clean = value.trim().slice(0, maxLength);
return clean || undefined;
}