first commit
This commit is contained in:
37
backend/src/lib/utils.ts
Normal file
37
backend/src/lib/utils.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
export function generateId(): string {
|
||||
return nanoid(21);
|
||||
}
|
||||
|
||||
export function generateTicketCode(): string {
|
||||
return `TKT-${nanoid(8).toUpperCase()}`;
|
||||
}
|
||||
|
||||
export function getNow(): string {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
export function formatCurrency(amount: number, currency: string = 'PYG'): string {
|
||||
return new Intl.NumberFormat('es-PY', {
|
||||
style: 'currency',
|
||||
currency,
|
||||
}).format(amount);
|
||||
}
|
||||
|
||||
export function calculateAvailableSeats(capacity: number, bookedCount: number): number {
|
||||
return Math.max(0, capacity - bookedCount);
|
||||
}
|
||||
|
||||
export function isEventSoldOut(capacity: number, bookedCount: number): boolean {
|
||||
return bookedCount >= capacity;
|
||||
}
|
||||
|
||||
export function sanitizeHtml(str: string): string {
|
||||
return str
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
Reference in New Issue
Block a user