- Convert ApiResponse to discriminated union for type-safe error handling - Add HealthStatus type with HealthState literal union - Make BaseEntity fields readonly for immutability - Add GlobalExceptionFilter with structured logging - Add port validation with clear error messages in main.ts - Improve parseDate to log warnings for invalid dates - Add comprehensive Button tests (variants, onClick, disabled) - Add slugify edge case tests (empty, special chars, numbers) - Create ESLint configs for all packages - Remove compiled JS files from src directories - Convert .prettierrc.js to .prettierrc.json Refs #1 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
/**
|
|
* Safely parse a date string or return undefined.
|
|
* Logs a warning if an invalid date string is passed.
|
|
*/
|
|
export function parseDate(value: string | Date | undefined | null): Date | undefined {
|
|
if (!value) return undefined;
|
|
if (value instanceof Date) return value;
|
|
const parsed = new Date(value);
|
|
if (isNaN(parsed.getTime())) {
|
|
console.warn(`parseDate: Invalid date string received: "${value}"`);
|
|
return undefined;
|
|
}
|
|
return parsed;
|
|
}
|
|
|
|
/**
|
|
* Generate a simple slug from a string
|
|
*/
|
|
export function slugify(text: string): string {
|
|
return text
|
|
.toLowerCase()
|
|
.trim()
|
|
.replace(/[^\w\s-]/g, "")
|
|
.replace(/[\s_-]+/g, "-")
|
|
.replace(/^-+|-+$/g, "");
|
|
}
|
|
|
|
/**
|
|
* Sleep for a given number of milliseconds
|
|
*/
|
|
export function sleep(ms: number): Promise<void> {
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
}
|
|
|
|
/**
|
|
* Check if a value is defined (not null or undefined)
|
|
*/
|
|
export function isDefined<T>(value: T | null | undefined): value is T {
|
|
return value !== null && value !== undefined;
|
|
}
|