MVP Build
This commit is contained in:
31
backend/src/shared-minimal/utils/formatters.ts
Normal file
31
backend/src/shared-minimal/utils/formatters.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @ai-summary Generic formatting utilities (no business logic)
|
||||
* @ai-context Pure functions only, no feature-specific logic
|
||||
*/
|
||||
|
||||
export function formatDate(date: Date): string {
|
||||
return date.toISOString().split('T')[0];
|
||||
}
|
||||
|
||||
export function formatDateTime(date: Date): string {
|
||||
return date.toISOString();
|
||||
}
|
||||
|
||||
export function formatCurrency(amount: number, currency = 'USD'): string {
|
||||
return new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency,
|
||||
}).format(amount);
|
||||
}
|
||||
|
||||
export function formatDistance(meters: number): string {
|
||||
if (meters < 1000) {
|
||||
return `${Math.round(meters)}m`;
|
||||
}
|
||||
return `${(meters / 1000).toFixed(1)}km`;
|
||||
}
|
||||
|
||||
export function formatMPG(miles: number, gallons: number): string {
|
||||
if (gallons === 0) return '0 MPG';
|
||||
return `${(miles / gallons).toFixed(1)} MPG`;
|
||||
}
|
||||
30
backend/src/shared-minimal/utils/validators.ts
Normal file
30
backend/src/shared-minimal/utils/validators.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @ai-summary Generic validation utilities (no business logic)
|
||||
* @ai-context Pure functions only, no feature-specific logic
|
||||
*/
|
||||
|
||||
export function isValidEmail(email: string): boolean {
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return emailRegex.test(email);
|
||||
}
|
||||
|
||||
export function isValidPhone(phone: string): boolean {
|
||||
const phoneRegex = /^\+?[\d\s\-()]+$/;
|
||||
return phoneRegex.test(phone) && phone.replace(/\D/g, '').length >= 10;
|
||||
}
|
||||
|
||||
export function isValidUUID(uuid: string): boolean {
|
||||
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
return uuidRegex.test(uuid);
|
||||
}
|
||||
|
||||
export function isValidVIN(vin: string): boolean {
|
||||
// VIN must be exactly 17 characters
|
||||
if (vin.length !== 17) return false;
|
||||
|
||||
// VIN cannot contain I, O, or Q
|
||||
if (/[IOQ]/i.test(vin)) return false;
|
||||
|
||||
// Must be alphanumeric
|
||||
return /^[A-HJ-NPR-Z0-9]{17}$/i.test(vin);
|
||||
}
|
||||
Reference in New Issue
Block a user