Function names already communicate intent. Comments that restate the function name add noise without explaining why. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
23 lines
754 B
TypeScript
23 lines
754 B
TypeScript
import { formatDate } from '$lib/shared/utils/date';
|
|
|
|
type AuthorSummary = { firstName?: string; lastName?: string; email: string };
|
|
type AuthorView = { displayName: string };
|
|
|
|
export function formatAuthorName(author: AuthorSummary | null | undefined): string {
|
|
if (!author) return '';
|
|
const full = [author.firstName, author.lastName].filter(Boolean).join(' ').trim();
|
|
return full || author.email || '';
|
|
}
|
|
|
|
export function formatAuthorDisplayName(author: AuthorView | null | undefined): string {
|
|
return author?.displayName ?? '';
|
|
}
|
|
|
|
export function formatPublishedAt(
|
|
publishedAt: string | null | undefined,
|
|
style: 'short' | 'long' = 'short'
|
|
): string | null {
|
|
if (!publishedAt) return null;
|
|
return formatDate(publishedAt.slice(0, 10), style);
|
|
}
|